@@ -9,6 +9,7 @@ chai.use(dirtyChai)
9
9
10
10
const fs = require ( 'fs' )
11
11
12
+ const CID = require ( 'cids' )
12
13
const IPFS = require ( '../../src/core' )
13
14
const createTempRepo = require ( '../utils/create-repo-nodejs' )
14
15
const expectTimeout = require ( '../utils/expect-timeout' )
@@ -44,14 +45,22 @@ describe('pin', function () {
44
45
let pin
45
46
let repo
46
47
47
- function expectPinned ( hash , type , pinned = true ) {
48
+ function expectPinned ( hash , type = pinTypes . all , pinned = true ) {
48
49
if ( typeof type === 'boolean' ) {
49
50
pinned = type
50
- type = undefined
51
+ type = pinTypes . all
51
52
}
52
53
53
- return pin . _isPinnedWithType ( hash , type || pinTypes . all )
54
- . then ( result => expect ( result . pinned ) . to . eql ( pinned ) )
54
+ return pin . _isPinnedWithType ( hash , type )
55
+ . then ( result => {
56
+ expect ( result . pinned ) . to . eql ( pinned )
57
+ if ( type === pinTypes . indirect ) {
58
+ // indirect pins return a CID of recursively pinned root instead of 'indirect' string
59
+ expect ( CID . isCID ( result . reason ) ) . to . be . true ( )
60
+ } else if ( type !== pinTypes . all ) {
61
+ expect ( result . reason ) . to . eql ( type )
62
+ }
63
+ } )
55
64
}
56
65
57
66
async function clearPins ( ) {
@@ -159,6 +168,7 @@ describe('pin', function () {
159
168
it ( 'recursive' , function ( ) {
160
169
return pin . add ( pins . root )
161
170
. then ( ( ) => {
171
+ expectPinned ( pins . root , pinTypes . recursive )
162
172
const pinChecks = Object . values ( pins )
163
173
. map ( hash => expectPinned ( hash ) )
164
174
@@ -169,7 +179,7 @@ describe('pin', function () {
169
179
it ( 'direct' , function ( ) {
170
180
return pin . add ( pins . root , { recursive : false } )
171
181
. then ( ( ) => Promise . all ( [
172
- expectPinned ( pins . root ) ,
182
+ expectPinned ( pins . root , pinTypes . direct ) ,
173
183
expectPinned ( pins . solarWiki , false )
174
184
] ) )
175
185
} )
@@ -242,7 +252,7 @@ describe('pin', function () {
242
252
)
243
253
} )
244
254
245
- it ( 'direct' , function ( ) {
255
+ it ( 'all direct' , function ( ) {
246
256
return pin . ls ( { type : 'direct' } )
247
257
. then ( out =>
248
258
expect ( out ) . to . deep . include . members ( [
@@ -252,7 +262,7 @@ describe('pin', function () {
252
262
)
253
263
} )
254
264
255
- it ( 'recursive' , function ( ) {
265
+ it ( 'all recursive' , function ( ) {
256
266
return pin . ls ( { type : 'recursive' } )
257
267
. then ( out =>
258
268
expect ( out ) . to . deep . include . members ( [
@@ -262,7 +272,7 @@ describe('pin', function () {
262
272
)
263
273
} )
264
274
265
- it ( 'indirect' , function ( ) {
275
+ it ( 'all indirect' , function ( ) {
266
276
return pin . ls ( { type : 'indirect' } )
267
277
. then ( out =>
268
278
expect ( out ) . to . deep . include . members ( [
@@ -275,6 +285,78 @@ describe('pin', function () {
275
285
] )
276
286
)
277
287
} )
288
+
289
+ it ( 'direct for CID' , function ( ) {
290
+ return pin . ls ( pins . mercuryDir , { type : 'direct' } )
291
+ . then ( out =>
292
+ expect ( out ) . to . have . deep . members ( [
293
+ { type : 'direct' ,
294
+ hash : pins . mercuryDir }
295
+ ] )
296
+ )
297
+ } )
298
+
299
+ it ( 'direct for path' , function ( ) {
300
+ return pin . ls ( `/ipfs/${ pins . root } /mercury/` , { type : 'direct' } )
301
+ . then ( out =>
302
+ expect ( out ) . to . have . deep . members ( [
303
+ { type : 'direct' ,
304
+ hash : pins . mercuryDir }
305
+ ] )
306
+ )
307
+ } )
308
+
309
+ it ( 'direct for path (no match)' , function ( done ) {
310
+ pin . ls ( `/ipfs/${ pins . root } /mercury/wiki.md` , { type : 'direct' } , ( err , pinset ) => {
311
+ expect ( err ) . to . exist ( )
312
+ expect ( pinset ) . to . not . exist ( )
313
+ done ( )
314
+ } )
315
+ } )
316
+
317
+ it ( 'direct for CID (no match)' , function ( done ) {
318
+ pin . ls ( pins . root , { type : 'direct' } , ( err , pinset ) => {
319
+ expect ( err ) . to . exist ( )
320
+ expect ( pinset ) . to . not . exist ( )
321
+ done ( )
322
+ } )
323
+ } )
324
+
325
+ it ( 'recursive for CID' , function ( ) {
326
+ return pin . ls ( pins . root , { type : 'recursive' } )
327
+ . then ( out =>
328
+ expect ( out ) . to . have . deep . members ( [
329
+ { type : 'recursive' ,
330
+ hash : pins . root }
331
+ ] )
332
+ )
333
+ } )
334
+
335
+ it ( 'recursive for CID (no match)' , function ( done ) {
336
+ return pin . ls ( pins . mercuryDir , { type : 'recursive' } , ( err , pinset ) => {
337
+ expect ( err ) . to . exist ( )
338
+ expect ( pinset ) . to . not . exist ( )
339
+ done ( )
340
+ } )
341
+ } )
342
+
343
+ it ( 'indirect for CID' , function ( ) {
344
+ return pin . ls ( pins . solarWiki , { type : 'indirect' } )
345
+ . then ( out =>
346
+ expect ( out ) . to . have . deep . members ( [
347
+ { type : `indirect through ${ pins . root } ` ,
348
+ hash : pins . solarWiki }
349
+ ] )
350
+ )
351
+ } )
352
+
353
+ it ( 'indirect for CID (no match)' , function ( done ) {
354
+ pin . ls ( pins . root , { type : 'indirect' } , ( err , pinset ) => {
355
+ expect ( err ) . to . exist ( )
356
+ expect ( pinset ) . to . not . exist ( )
357
+ done ( )
358
+ } )
359
+ } )
278
360
} )
279
361
} )
280
362
0 commit comments