Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 9b3d0a0

Browse files
author
Alan Shaw
committed
test: add HTTP API test for add with cid-base option
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 9a43cc8 commit 9b3d0a0

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

test/http-api/inject/block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const streamToPromise = require('stream-to-promise')
99
const multibase = require('multibase')
1010

1111
module.exports = (http) => {
12-
describe.only('/block', () => {
12+
describe('/block', () => {
1313
let api
1414

1515
before(() => {

test/http-api/inject/files.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
const crypto = require('crypto')
55
const expect = require('chai').expect
6+
const FormData = require('form-data')
7+
const streamToPromise = require('stream-to-promise')
8+
const multibase = require('multibase')
69

710
module.exports = (http) => {
811
describe('/files', () => {
@@ -37,6 +40,46 @@ module.exports = (http) => {
3740
done()
3841
})
3942
})
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+
})
4083
})
4184

4285
describe('/cat', () => {

0 commit comments

Comments
 (0)