|
3 | 3 |
|
4 | 4 | const crypto = require('crypto')
|
5 | 5 | const expect = require('chai').expect
|
| 6 | +const FormData = require('form-data') |
| 7 | +const streamToPromise = require('stream-to-promise') |
| 8 | +const multibase = require('multibase') |
6 | 9 |
|
7 | 10 | module.exports = (http) => {
|
8 | 11 | describe('/files', () => {
|
@@ -37,6 +40,46 @@ module.exports = (http) => {
|
37 | 40 | done()
|
38 | 41 | })
|
39 | 42 | })
|
| 43 | + |
| 44 | + // TODO: unskip when we can retrieve data from the repo with a different |
| 45 | + // version CID then it was added with. |
| 46 | + it.skip('should add data and return a base64 encoded CID', (done) => { |
| 47 | + const form = new FormData() |
| 48 | + form.append('data', Buffer.from('TEST' + Date.now())) |
| 49 | + const headers = form.getHeaders() |
| 50 | + |
| 51 | + streamToPromise(form).then((payload) => { |
| 52 | + api.inject({ |
| 53 | + method: 'POST', |
| 54 | + url: '/api/v0/add?cid-base=base64', |
| 55 | + headers: headers, |
| 56 | + payload: payload |
| 57 | + }, (res) => { |
| 58 | + expect(res.statusCode).to.equal(200) |
| 59 | + expect(multibase.isEncoded(JSON.parse(res.result).Hash)).to.deep.equal('base64') |
| 60 | + done() |
| 61 | + }) |
| 62 | + }).catch(err => console.error(err)) |
| 63 | + }) |
| 64 | + |
| 65 | + it('should add data without pinning and return a base64 encoded CID', (done) => { |
| 66 | + const form = new FormData() |
| 67 | + form.append('data', Buffer.from('TEST' + Date.now())) |
| 68 | + const headers = form.getHeaders() |
| 69 | + |
| 70 | + streamToPromise(form).then((payload) => { |
| 71 | + api.inject({ |
| 72 | + method: 'POST', |
| 73 | + url: '/api/v0/add?cid-base=base64&pin=false', |
| 74 | + headers: headers, |
| 75 | + payload: payload |
| 76 | + }, (res) => { |
| 77 | + expect(res.statusCode).to.equal(200) |
| 78 | + expect(multibase.isEncoded(JSON.parse(res.result).Hash)).to.deep.equal('base64') |
| 79 | + done() |
| 80 | + }) |
| 81 | + }).catch(err => console.error(err)) |
| 82 | + }) |
40 | 83 | })
|
41 | 84 |
|
42 | 85 | describe('/cat', () => {
|
|
0 commit comments