22/* eslint-env mocha */
33'use strict'
44
5- const series = require ( 'async/series ' )
6- const loadFixture = require ( 'aegir/fixtures ' )
5+ const auto = require ( 'async/auto ' )
6+ const PeerId = require ( 'peer-id ' )
77
88const { spawnNodeWithId } = require ( '../utils/spawn' )
99const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
1010
11- const fixture = Object . freeze ( {
12- data : loadFixture ( 'js/test/fixtures/testfile.txt' , 'interface-ipfs-core' )
13- } )
14-
1511module . exports = ( createCommon , options ) => {
1612 const describe = getDescribe ( options )
1713 const it = getIt ( options )
@@ -20,7 +16,6 @@ module.exports = (createCommon, options) => {
2016 describe ( '.name.pubsub.cancel' , function ( ) {
2117 let ipfs
2218 let nodeId
23- let value
2419
2520 before ( function ( done ) {
2621 // CI takes longer to instantiate the daemon, so we need to increase the
@@ -36,12 +31,7 @@ module.exports = (createCommon, options) => {
3631 ipfs = node
3732 nodeId = node . peerId . id
3833
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 ( )
4535 } )
4636 } )
4737 } )
@@ -63,24 +53,35 @@ module.exports = (createCommon, options) => {
6353
6454 it ( 'should cancel a subscription correctly returning true' , function ( done ) {
6555 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 ) => {
7658 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 )
8259
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+ } )
8485 } )
8586 } )
8687 } )
0 commit comments