This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathcancel.js
88 lines (69 loc) · 2.52 KB
/
cancel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* eslint max-nested-callbacks: ["error", 5] */
/* eslint-env mocha */
'use strict'
const auto = require('async/auto')
const PeerId = require('peer-id')
const { spawnNodeWithId } = require('../utils/spawn')
const { getDescribe, getIt, expect } = require('../utils/mocha')
module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()
describe('.name.pubsub.cancel', function () {
let ipfs
let nodeId
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)
common.setup((err, factory) => {
expect(err).to.not.exist()
spawnNodeWithId(factory, (err, node) => {
expect(err).to.not.exist()
ipfs = node
nodeId = node.peerId.id
done()
})
})
})
after((done) => common.teardown(done))
it('should return false when the name that is intended to cancel is not subscribed', function (done) {
this.timeout(60 * 1000)
ipfs.name.pubsub.cancel(nodeId, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res).to.have.property('canceled')
expect(res.canceled).to.eql(false)
done()
})
})
it('should cancel a subscription correctly returning true', function (done) {
this.timeout(300 * 1000)
PeerId.create({ bits: 512 }, (err, peerId) => {
expect(err).to.not.exist()
const id = peerId.toB58String()
const ipnsPath = `/ipns/${id}`
ipfs.name.pubsub.subs((err, res) => {
expect(err).to.not.exist()
expect(res).to.be.an('array').that.does.not.include(ipnsPath)
ipfs.name.resolve(id, (err) => {
expect(err).to.exist()
auto({
subs1: (cb) => ipfs.name.pubsub.subs(cb),
cancel: ['subs1', (_, cb) => ipfs.name.pubsub.cancel(ipnsPath, cb)],
subs2: ['cancel', (_, cb) => ipfs.name.pubsub.subs(cb)]
}, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.subs1).to.be.an('array').that.does.include(ipnsPath)
expect(res.cancel).to.have.property('canceled')
expect(res.cancel.canceled).to.eql(true)
expect(res.subs2).to.be.an('array').that.does.not.include(ipnsPath)
done()
})
})
})
})
})
})
}