2
2
/* eslint-env mocha */
3
3
'use strict'
4
4
5
- const series = require ( 'async/series ' )
6
- const loadFixture = require ( 'aegir/fixtures ' )
5
+ const auto = require ( 'async/auto ' )
6
+ const PeerId = require ( 'peer-id ' )
7
7
8
8
const { spawnNodeWithId } = require ( '../utils/spawn' )
9
9
const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
10
10
11
- const fixture = Object . freeze ( {
12
- data : loadFixture ( 'js/test/fixtures/testfile.txt' , 'interface-ipfs-core' )
13
- } )
14
-
15
11
module . exports = ( createCommon , options ) => {
16
12
const describe = getDescribe ( options )
17
13
const it = getIt ( options )
@@ -20,7 +16,6 @@ module.exports = (createCommon, options) => {
20
16
describe ( '.name.pubsub.cancel' , function ( ) {
21
17
let ipfs
22
18
let nodeId
23
- let value
24
19
25
20
before ( function ( done ) {
26
21
// CI takes longer to instantiate the daemon, so we need to increase the
@@ -36,12 +31,7 @@ module.exports = (createCommon, options) => {
36
31
ipfs = node
37
32
nodeId = node . peerId . id
38
33
39
- ipfs . add ( fixture . data , { pin : false } , ( err , res ) => {
40
- expect ( err ) . to . not . exist ( )
41
-
42
- value = res [ 0 ] . path
43
- done ( )
44
- } )
34
+ done ( )
45
35
} )
46
36
} )
47
37
} )
@@ -63,24 +53,35 @@ module.exports = (createCommon, options) => {
63
53
64
54
it ( 'should cancel a subscription correctly returning true' , function ( done ) {
65
55
this . timeout ( 300 * 1000 )
66
- const ipnsPath = `/ipns/${ nodeId } `
67
-
68
- series ( [
69
- ( cb ) => ipfs . name . pubsub . subs ( cb ) ,
70
- ( cb ) => ipfs . name . publish ( value , { resolve : false } , cb ) ,
71
- ( cb ) => ipfs . name . resolve ( nodeId , cb ) ,
72
- ( cb ) => ipfs . name . pubsub . subs ( cb ) ,
73
- ( cb ) => ipfs . name . pubsub . cancel ( ipnsPath , cb ) ,
74
- ( cb ) => ipfs . name . pubsub . subs ( cb )
75
- ] , ( err , res ) => {
56
+
57
+ PeerId . create ( { bits : 512 } , ( err , peerId ) => {
76
58
expect ( err ) . to . not . exist ( )
77
- expect ( res ) . to . exist ( )
78
- expect ( res [ 0 ] ) . to . eql ( [ ] ) // initally empty
79
- expect ( res [ 4 ] ) . to . have . property ( 'canceled' )
80
- expect ( res [ 4 ] . canceled ) . to . eql ( true )
81
- expect ( res [ 5 ] ) . to . be . an ( 'array' ) . that . does . not . include ( ipnsPath )
82
59
83
- done ( )
60
+ const id = peerId . toB58String ( )
61
+ const ipnsPath = `/ipns/${ id } `
62
+
63
+ ipfs . name . pubsub . subs ( ( err , res ) => {
64
+ expect ( err ) . to . not . exist ( )
65
+ expect ( res ) . to . be . an ( 'array' ) . that . does . not . include ( ipnsPath )
66
+
67
+ ipfs . name . resolve ( id , ( err ) => {
68
+ expect ( err ) . to . exist ( )
69
+ auto ( {
70
+ subs1 : ( cb ) => ipfs . name . pubsub . subs ( cb ) ,
71
+ cancel : [ 'subs1' , ( _ , cb ) => ipfs . name . pubsub . cancel ( ipnsPath , cb ) ] ,
72
+ subs2 : [ 'cancel' , ( _ , cb ) => ipfs . name . pubsub . subs ( cb ) ]
73
+ } , ( err , res ) => {
74
+ expect ( err ) . to . not . exist ( )
75
+ expect ( res ) . to . exist ( )
76
+ expect ( res . subs1 ) . to . be . an ( 'array' ) . that . does . include ( ipnsPath )
77
+ expect ( res . cancel ) . to . have . property ( 'canceled' )
78
+ expect ( res . cancel . canceled ) . to . eql ( true )
79
+ expect ( res . subs2 ) . to . be . an ( 'array' ) . that . does . not . include ( ipnsPath )
80
+
81
+ done ( )
82
+ } )
83
+ } )
84
+ } )
84
85
} )
85
86
} )
86
87
} )
0 commit comments