@@ -6,9 +6,10 @@ const expect = require('chai').expect
6
6
const fs = require ( 'fs' )
7
7
const FormData = require ( 'form-data' )
8
8
const streamToPromise = require ( 'stream-to-promise' )
9
+ const multibase = require ( 'multibase' )
9
10
10
11
module . exports = ( http ) => {
11
- describe ( '/block' , ( ) => {
12
+ describe . only ( '/block' , ( ) => {
12
13
let api
13
14
14
15
before ( ( ) => {
@@ -59,13 +60,8 @@ module.exports = (http) => {
59
60
60
61
it ( 'should put a value and return a base64 encoded CID' , ( done ) => {
61
62
const form = new FormData ( )
62
- const filePath = 'test/fixtures/test-data/hello'
63
- form . append ( 'data' , fs . createReadStream ( filePath ) )
63
+ form . append ( 'data' , Buffer . from ( 'TEST' + Date . now ( ) ) )
64
64
const headers = form . getHeaders ( )
65
- const expectedResult = {
66
- Key : 'mAXASIKlIkE8vD0ebj4GXaUswGEsNLtHBzSoewPuF0pmhkqRH' ,
67
- Size : 12
68
- }
69
65
70
66
streamToPromise ( form ) . then ( ( payload ) => {
71
67
api . inject ( {
@@ -75,16 +71,15 @@ module.exports = (http) => {
75
71
payload : payload
76
72
} , ( res ) => {
77
73
expect ( res . statusCode ) . to . equal ( 200 )
78
- expect ( res . result ) . to . deep . equal ( expectedResult )
74
+ expect ( multibase . isEncoded ( res . result . Key ) ) . to . deep . equal ( 'base64' )
79
75
done ( )
80
76
} )
81
77
} )
82
78
} )
83
79
84
80
it ( 'should not put a value for invalid cid-base option' , ( done ) => {
85
81
const form = new FormData ( )
86
- const filePath = 'test/fixtures/test-data/hello'
87
- form . append ( 'data' , fs . createReadStream ( filePath ) )
82
+ form . append ( 'data' , Buffer . from ( 'TEST' + Date . now ( ) ) )
88
83
const headers = form . getHeaders ( )
89
84
90
85
streamToPromise ( form ) . then ( ( payload ) => {
@@ -175,13 +170,51 @@ module.exports = (http) => {
175
170
done ( )
176
171
} )
177
172
} )
173
+
174
+ it ( 'should stat a block and return a base64 encoded CID' , ( done ) => {
175
+ const form = new FormData ( )
176
+ form . append ( 'data' , Buffer . from ( 'TEST' + Date . now ( ) ) )
177
+ const headers = form . getHeaders ( )
178
+
179
+ streamToPromise ( form ) . then ( ( payload ) => {
180
+ api . inject ( {
181
+ method : 'POST' ,
182
+ url : '/api/v0/block/put?cid-base=base64' ,
183
+ headers : headers ,
184
+ payload : payload
185
+ } , ( res ) => {
186
+ expect ( res . statusCode ) . to . equal ( 200 )
187
+ expect ( multibase . isEncoded ( res . result . Key ) ) . to . deep . equal ( 'base64' )
188
+ done ( )
189
+ } )
190
+ } )
191
+ } )
192
+
193
+ it ( 'should not stat a block for invalid cid-base option' , ( done ) => {
194
+ const form = new FormData ( )
195
+ form . append ( 'data' , Buffer . from ( 'TEST' + Date . now ( ) ) )
196
+ const headers = form . getHeaders ( )
197
+
198
+ streamToPromise ( form ) . then ( ( payload ) => {
199
+ api . inject ( {
200
+ method : 'POST' ,
201
+ url : '/api/v0/block/put?cid-base=invalid' ,
202
+ headers : headers ,
203
+ payload : payload
204
+ } , ( res ) => {
205
+ expect ( res . statusCode ) . to . equal ( 400 )
206
+ expect ( res . result . Message ) . to . include ( 'child "cid-base" fails' )
207
+ done ( )
208
+ } )
209
+ } )
210
+ } )
178
211
} )
179
212
180
- describe ( '/block/del ' , ( ) => {
213
+ describe ( '/block/rm ' , ( ) => {
181
214
it ( 'returns 400 for request without argument' , ( done ) => {
182
215
api . inject ( {
183
216
method : 'GET' ,
184
- url : '/api/v0/block/del '
217
+ url : '/api/v0/block/rm '
185
218
} , ( res ) => {
186
219
expect ( res . statusCode ) . to . equal ( 400 )
187
220
expect ( res . result ) . to . be . a ( 'string' )
@@ -192,7 +225,7 @@ module.exports = (http) => {
192
225
it ( 'returns 500 for request with invalid argument' , ( done ) => {
193
226
api . inject ( {
194
227
method : 'GET' ,
195
- url : '/api/v0/block/del ?arg=invalid'
228
+ url : '/api/v0/block/rm ?arg=invalid'
196
229
} , ( res ) => {
197
230
expect ( res . statusCode ) . to . equal ( 500 )
198
231
expect ( res . result . Code ) . to . equal ( 0 )
@@ -204,7 +237,7 @@ module.exports = (http) => {
204
237
it ( 'returns 200' , ( done ) => {
205
238
api . inject ( {
206
239
method : 'GET' ,
207
- url : '/api/v0/block/del ?arg=QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp'
240
+ url : '/api/v0/block/rm ?arg=QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp'
208
241
} , ( res ) => {
209
242
expect ( res . statusCode ) . to . equal ( 200 )
210
243
done ( )
0 commit comments