Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit d268add

Browse files
committed
fix: code review
1 parent 3e619e1 commit d268add

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

js/src/name-pubsub/cancel.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/* eslint-env mocha */
33
'use strict'
44

5-
const series = require('async/series')
5+
const auto = require('async/auto')
6+
const PeerId = require('peer-id')
67

78
const { spawnNodeWithId } = require('../utils/spawn')
89
const { getDescribe, getIt, expect } = require('../utils/mocha')
@@ -52,28 +53,33 @@ module.exports = (createCommon, options) => {
5253

5354
it('should cancel a subscription correctly returning true', function (done) {
5455
this.timeout(300 * 1000)
55-
const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA'
56-
const ipnsPath = `/ipns/${id}`
5756

58-
ipfs.name.pubsub.subs((err, res) => {
57+
PeerId.create({ bits: 512 }, (err, peerId) => {
5958
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+
})
7783
})
7884
})
7985
})

0 commit comments

Comments
 (0)