1
1
/* eslint-env mocha */
2
2
'use strict'
3
3
4
- const Path = require ( 'path' )
4
+ const path = require ( 'path' )
5
5
const expect = require ( 'chai' ) . expect
6
6
const isIpfs = require ( 'is-ipfs' )
7
7
@@ -14,19 +14,39 @@ describe('resolve', () => runOnAndOff((thing) => {
14
14
ipfs = thing . ipfs
15
15
} )
16
16
17
- it ( 'should resolve an IPFS hash' , ( done ) => {
18
- const path = '/src/init-files/init-docs/readme'
17
+ it ( 'should resolve an IPFS hash' , ( ) => {
18
+ const filePath = path . join ( process . cwd ( ) , '/src/init-files/init-docs/readme' )
19
19
let hash
20
20
21
- return ipfs ( `add ${ Path . join ( process . cwd ( ) , path ) } ` )
21
+ return ipfs ( `add ${ filePath } ` )
22
22
. then ( ( out ) => {
23
23
hash = out . split ( ' ' ) [ 1 ]
24
- console . log ( out )
25
24
expect ( isIpfs . cid ( hash ) ) . to . be . true ( )
26
- return ipfs ( `resolve ${ hash } ` )
25
+ return ipfs ( `resolve /ipfs/ ${ hash } ` )
27
26
} )
28
27
. then ( ( out ) => {
29
28
expect ( out ) . to . contain ( `/ipfs/${ hash } ` )
30
29
} )
31
30
} )
31
+
32
+ it ( 'should resolve an IPFS path link' , ( ) => {
33
+ const filePath = path . join ( process . cwd ( ) , '/src/init-files/init-docs/readme' )
34
+ let fileHash , rootHash
35
+
36
+ return ipfs ( `add ${ filePath } --wrap-with-directory` )
37
+ . then ( ( out ) => {
38
+ const lines = out . split ( '\n' )
39
+
40
+ fileHash = lines [ 0 ] . split ( ' ' ) [ 1 ]
41
+ rootHash = lines [ 1 ] . split ( ' ' ) [ 1 ]
42
+
43
+ expect ( isIpfs . cid ( fileHash ) ) . to . be . true ( )
44
+ expect ( isIpfs . cid ( rootHash ) ) . to . be . true ( )
45
+
46
+ return ipfs ( `resolve /ipfs/${ rootHash } /readme` )
47
+ } )
48
+ . then ( ( out ) => {
49
+ expect ( out ) . to . contain ( `/ipfs/${ fileHash } ` )
50
+ } )
51
+ } )
32
52
} ) )
0 commit comments