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

Commit 3e619e1

Browse files
committed
fix: ipns over pubsub tests
1 parent 0d7b447 commit 3e619e1

File tree

2 files changed

+37
-55
lines changed

2 files changed

+37
-55
lines changed

js/src/name-pubsub/cancel.js

+23-28
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33
'use strict'
44

55
const series = require('async/series')
6-
const loadFixture = require('aegir/fixtures')
76

87
const { spawnNodeWithId } = require('../utils/spawn')
98
const { getDescribe, getIt, expect } = require('../utils/mocha')
109

11-
const fixture = Object.freeze({
12-
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
13-
})
14-
1510
module.exports = (createCommon, options) => {
1611
const describe = getDescribe(options)
1712
const it = getIt(options)
@@ -20,7 +15,6 @@ module.exports = (createCommon, options) => {
2015
describe('.name.pubsub.cancel', function () {
2116
let ipfs
2217
let nodeId
23-
let value
2418

2519
before(function (done) {
2620
// CI takes longer to instantiate the daemon, so we need to increase the
@@ -36,12 +30,7 @@ module.exports = (createCommon, options) => {
3630
ipfs = node
3731
nodeId = node.peerId.id
3832

39-
ipfs.add(fixture.data, { pin: false }, (err, res) => {
40-
expect(err).to.not.exist()
41-
42-
value = res[0].path
43-
done()
44-
})
33+
done()
4534
})
4635
})
4736
})
@@ -63,24 +52,30 @@ module.exports = (createCommon, options) => {
6352

6453
it('should cancel a subscription correctly returning true', function (done) {
6554
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) => {
55+
const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA'
56+
const ipnsPath = `/ipns/${id}`
57+
58+
ipfs.name.pubsub.subs((err, res) => {
7659
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)
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)
8275

83-
done()
76+
done()
77+
})
78+
})
8479
})
8580
})
8681
})

js/src/name-pubsub/subs.js

+14-27
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
/* eslint-env mocha */
33
'use strict'
44

5-
const series = require('async/series')
6-
const loadFixture = require('aegir/fixtures')
7-
85
const { spawnNodeWithId } = require('../utils/spawn')
96
const { getDescribe, getIt, expect } = require('../utils/mocha')
107

11-
const fixture = Object.freeze({
12-
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
13-
})
14-
158
module.exports = (createCommon, options) => {
169
const describe = getDescribe(options)
1710
const it = getIt(options)
1811
const common = createCommon()
1912

2013
describe('.name.pubsub.subs', function () {
2114
let ipfs
22-
let nodeId
23-
let value
2415

2516
before(function (done) {
2617
// CI takes longer to instantiate the daemon, so we need to increase the
@@ -34,14 +25,7 @@ module.exports = (createCommon, options) => {
3425
expect(err).to.not.exist()
3526

3627
ipfs = node
37-
nodeId = node.peerId.id
38-
39-
ipfs.add(fixture.data, { pin: false }, (err, res) => {
40-
expect(err).to.not.exist()
41-
42-
value = res[0].path
43-
done()
44-
})
28+
done()
4529
})
4630
})
4731
})
@@ -62,19 +46,22 @@ module.exports = (createCommon, options) => {
6246

6347
it('should get the list of subscriptions updated after a resolve', function (done) {
6448
this.timeout(300 * 1000)
49+
const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA'
6550

66-
series([
67-
(cb) => ipfs.name.pubsub.subs(cb),
68-
(cb) => ipfs.name.publish(value, { resolve: false }, cb),
69-
(cb) => ipfs.name.resolve(nodeId, cb),
70-
(cb) => ipfs.name.pubsub.subs(cb)
71-
], (err, res) => {
51+
ipfs.name.pubsub.subs((err, res) => {
7252
expect(err).to.not.exist()
73-
expect(res).to.exist()
74-
expect(res[0]).to.eql([]) // initally empty
75-
expect(res[3]).to.be.an('array').that.does.include(`/ipns/${nodeId}`)
53+
expect(res).to.eql([]) // initally empty
7654

77-
done()
55+
ipfs.name.resolve(id, (err) => {
56+
expect(err).to.exist()
57+
58+
ipfs.name.pubsub.subs((err, res) => {
59+
expect(err).to.not.exist()
60+
expect(res).to.be.an('array').that.does.include(`/ipns/${id}`)
61+
62+
done()
63+
})
64+
})
7865
})
7966
})
8067
})

0 commit comments

Comments
 (0)