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

Commit 1763d0e

Browse files
author
Alan Shaw
committed
test: add HTTP API tests for block.put with cid-base option
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent ec0afe7 commit 1763d0e

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

src/http/api/resources/block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ exports.put = {
126126
}
127127
}
128128

129-
exports.del = {
129+
exports.rm = {
130130
// uses common parseKey method that returns a `key`
131131
parseArgs: exports.parseKey,
132132

src/http/api/routes/block.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = (server) => {
1212
pre: [
1313
{ method: resources.block.get.parseArgs, assign: 'args' }
1414
],
15-
handler: resources.block.get.handler
15+
handler: resources.block.get.handler,
16+
validate: resources.block.get.validate
1617
}
1718
})
1819

@@ -27,18 +28,19 @@ module.exports = (server) => {
2728
pre: [
2829
{ method: resources.block.put.parseArgs, assign: 'args' }
2930
],
30-
handler: resources.block.put.handler
31+
handler: resources.block.put.handler,
32+
validate: resources.block.put.validate
3133
}
3234
})
3335

3436
api.route({
3537
method: '*',
36-
path: '/api/v0/block/del',
38+
path: '/api/v0/block/rm',
3739
config: {
3840
pre: [
39-
{ method: resources.block.del.parseArgs, assign: 'args' }
41+
{ method: resources.block.rm.parseArgs, assign: 'args' }
4042
],
41-
handler: resources.block.del.handler
43+
handler: resources.block.rm.handler
4244
}
4345
})
4446

@@ -49,7 +51,8 @@ module.exports = (server) => {
4951
pre: [
5052
{ method: resources.block.stat.parseArgs, assign: 'args' }
5153
],
52-
handler: resources.block.stat.handler
54+
handler: resources.block.stat.handler,
55+
validate: resources.block.stat.validate
5356
}
5457
})
5558
}

test/http-api/inject/block.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,50 @@ module.exports = (http) => {
5656
})
5757
})
5858
})
59+
60+
it('should put a value and return a base64 encoded CID', (done) => {
61+
const form = new FormData()
62+
const filePath = 'test/fixtures/test-data/hello'
63+
form.append('data', fs.createReadStream(filePath))
64+
const headers = form.getHeaders()
65+
const expectedResult = {
66+
Key: 'mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH',
67+
Size: 12
68+
}
69+
70+
streamToPromise(form).then((payload) => {
71+
api.inject({
72+
method: 'POST',
73+
url: '/api/v0/block/put?cid-base=base64',
74+
headers: headers,
75+
payload: payload
76+
}, (res) => {
77+
expect(res.statusCode).to.equal(200)
78+
expect(res.result).to.deep.equal(expectedResult)
79+
done()
80+
})
81+
})
82+
})
83+
84+
it('should not put a value for invalid cid-base option', (done) => {
85+
const form = new FormData()
86+
const filePath = 'test/fixtures/test-data/hello'
87+
form.append('data', fs.createReadStream(filePath))
88+
const headers = form.getHeaders()
89+
90+
streamToPromise(form).then((payload) => {
91+
api.inject({
92+
method: 'POST',
93+
url: '/api/v0/block/put?cid-base=invalid',
94+
headers: headers,
95+
payload: payload
96+
}, (res) => {
97+
expect(res.statusCode).to.equal(400)
98+
expect(res.result.Message).to.include('child "cid-base" fails')
99+
done()
100+
})
101+
})
102+
})
59103
})
60104

61105
describe('/block/get', () => {

0 commit comments

Comments
 (0)