This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathcancel.js
65 lines (51 loc) · 1.88 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
/* eslint-env mocha */
import all from 'it-all'
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../utils/mocha.js'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testCancel (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.name.pubsub.cancel', () => {
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
/** @type {string} */
let nodeId
before(async () => {
ipfs = (await factory.spawn()).api
const peerInfo = await ipfs.id()
nodeId = peerInfo.id.toString()
})
after(() => factory.clean())
it('should return false when the name that is intended to cancel is not subscribed', async function () {
this.timeout(60 * 1000)
const res = await ipfs.name.pubsub.cancel(nodeId)
expect(res).to.exist()
expect(res).to.have.property('canceled')
expect(res.canceled).to.be.false()
})
it('should cancel a subscription correctly returning true', async function () {
this.timeout(300 * 1000)
const peerId = await createEd25519PeerId()
const id = peerId.toString()
const ipnsPath = `/ipns/${id}`
const subs = await ipfs.name.pubsub.subs()
expect(subs).to.be.an('array').that.does.not.include(ipnsPath)
await expect(all(ipfs.name.resolve(id))).to.eventually.be.rejected()
const subs1 = await ipfs.name.pubsub.subs()
const cancel = await ipfs.name.pubsub.cancel(ipnsPath)
const subs2 = await ipfs.name.pubsub.subs()
expect(subs1).to.be.an('array').that.includes(ipnsPath)
expect(cancel).to.have.property('canceled')
expect(cancel.canceled).to.be.true()
expect(subs2).to.be.an('array').that.does.not.include(ipnsPath)
})
})
}