|
2 | 2 | /* eslint-env mocha */
|
3 | 3 | 'use strict'
|
4 | 4 |
|
5 |
| -const series = require('async/series') |
| 5 | +const auto = require('async/auto') |
| 6 | +const PeerId = require('peer-id') |
6 | 7 |
|
7 | 8 | const { spawnNodeWithId } = require('../utils/spawn')
|
8 | 9 | const { getDescribe, getIt, expect } = require('../utils/mocha')
|
@@ -52,28 +53,33 @@ module.exports = (createCommon, options) => {
|
52 | 53 |
|
53 | 54 | it('should cancel a subscription correctly returning true', function (done) {
|
54 | 55 | this.timeout(300 * 1000)
|
55 |
| - const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA' |
56 |
| - const ipnsPath = `/ipns/${id}` |
57 | 56 |
|
58 |
| - ipfs.name.pubsub.subs((err, res) => { |
| 57 | + PeerId.create({ bits: 512 }, (err, peerId) => { |
59 | 58 | expect(err).to.not.exist()
|
60 |
| - expect(res).to.eql([]) // initally empty |
61 |
| - |
62 |
| - ipfs.name.resolve(id, (err) => { |
63 |
| - expect(err).to.exist() |
64 |
| - series([ |
65 |
| - (cb) => ipfs.name.pubsub.subs(cb), |
66 |
| - (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), |
67 |
| - (cb) => ipfs.name.pubsub.subs(cb) |
68 |
| - ], (err, res) => { |
69 |
| - expect(err).to.not.exist() |
70 |
| - expect(res).to.exist() |
71 |
| - expect(res[0]).to.be.an('array').that.does.include(ipnsPath) |
72 |
| - expect(res[1]).to.have.property('canceled') |
73 |
| - expect(res[1].canceled).to.eql(true) |
74 |
| - expect(res[2]).to.be.an('array').that.does.not.include(ipnsPath) |
75 |
| - |
76 |
| - done() |
| 59 | + |
| 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: (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), |
| 72 | + subs2: (cb) => ipfs.name.pubsub.subs(cb) |
| 73 | + }, 1, (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 | + }) |
77 | 83 | })
|
78 | 84 | })
|
79 | 85 | })
|
|
0 commit comments