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

Commit 3ed9da5

Browse files
author
Alan Shaw
committed
test: add HTTP API tests for object.new/get/put with cid-base
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent f857c37 commit 3ed9da5

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/http-api/inject/object.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ chai.use(dirtyChai)
1010
const fs = require('fs')
1111
const FormData = require('form-data')
1212
const streamToPromise = require('stream-to-promise')
13+
const multibase = require('multibase')
1314

1415
module.exports = (http) => {
1516
describe('/object', () => {
@@ -32,6 +33,17 @@ module.exports = (http) => {
3233
done()
3334
})
3435
})
36+
37+
it('should create a new object and return a base64 encoded CID', (done) => {
38+
api.inject({
39+
method: 'POST',
40+
url: '/api/v0/object/new?cid-base=base64'
41+
}, (res) => {
42+
expect(res.statusCode).to.equal(200)
43+
expect(multibase.isEncoded(res.result.Hash)).to.deep.equal('base64')
44+
done()
45+
})
46+
})
3547
})
3648

3749
describe('/get', () => {
@@ -69,6 +81,24 @@ module.exports = (http) => {
6981
done()
7082
})
7183
})
84+
85+
it('should get object and return a base64 encoded CID', (done) => {
86+
api.inject({
87+
method: 'POST',
88+
url: '/api/v0/object/new'
89+
}, (res) => {
90+
expect(res.statusCode).to.equal(200)
91+
92+
api.inject({
93+
method: 'POST',
94+
url: '/api/v0/object/get?cid-base=base64&arg=' + res.result.Hash
95+
}, (res) => {
96+
expect(res.statusCode).to.equal(200)
97+
expect(multibase.isEncoded(res.result.Hash)).to.deep.equal('base64')
98+
done()
99+
})
100+
})
101+
})
72102
})
73103

74104
describe('/put', () => {
@@ -138,6 +168,25 @@ module.exports = (http) => {
138168
})
139169
})
140170
})
171+
172+
it('should put data and return a base64 encoded CID', (done) => {
173+
const form = new FormData()
174+
form.append('file', JSON.stringify({ Data: 'TEST' + Date.now(), Links: [] }), { filename: 'node.json' })
175+
const headers = form.getHeaders()
176+
177+
streamToPromise(form).then((payload) => {
178+
api.inject({
179+
method: 'POST',
180+
url: '/api/v0/object/put?cid-base=base64',
181+
headers: headers,
182+
payload: payload
183+
}, (res) => {
184+
expect(res.statusCode).to.equal(200)
185+
expect(multibase.isEncoded(res.result.Hash)).to.deep.equal('base64')
186+
done()
187+
})
188+
})
189+
})
141190
})
142191

143192
describe('/stat', () => {

0 commit comments

Comments
 (0)