diff --git a/js/src/name-pubsub/cancel.js b/js/src/name-pubsub/cancel.js index ba7fd2cc..b46dcb82 100644 --- a/js/src/name-pubsub/cancel.js +++ b/js/src/name-pubsub/cancel.js @@ -2,16 +2,12 @@ /* eslint-env mocha */ 'use strict' -const series = require('async/series') -const loadFixture = require('aegir/fixtures') +const auto = require('async/auto') +const PeerId = require('peer-id') const { spawnNodeWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') -const fixture = Object.freeze({ - data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core') -}) - module.exports = (createCommon, options) => { const describe = getDescribe(options) const it = getIt(options) @@ -20,7 +16,6 @@ module.exports = (createCommon, options) => { describe('.name.pubsub.cancel', function () { let ipfs let nodeId - let value before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the @@ -36,12 +31,7 @@ module.exports = (createCommon, options) => { ipfs = node nodeId = node.peerId.id - ipfs.add(fixture.data, { pin: false }, (err, res) => { - expect(err).to.not.exist() - - value = res[0].path - done() - }) + done() }) }) }) @@ -63,24 +53,35 @@ module.exports = (createCommon, options) => { it('should cancel a subscription correctly returning true', function (done) { this.timeout(300 * 1000) - const ipnsPath = `/ipns/${nodeId}` - - series([ - (cb) => ipfs.name.pubsub.subs(cb), - (cb) => ipfs.name.publish(value, { resolve: false }, cb), - (cb) => ipfs.name.resolve(nodeId, cb), - (cb) => ipfs.name.pubsub.subs(cb), - (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb), - (cb) => ipfs.name.pubsub.subs(cb) - ], (err, res) => { + + PeerId.create({ bits: 512 }, (err, peerId) => { expect(err).to.not.exist() - expect(res).to.exist() - expect(res[0]).to.eql([]) // initally empty - expect(res[4]).to.have.property('canceled') - expect(res[4].canceled).to.eql(true) - expect(res[5]).to.be.an('array').that.does.not.include(ipnsPath) - done() + 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() + }) + }) + }) }) }) }) diff --git a/js/src/name-pubsub/subs.js b/js/src/name-pubsub/subs.js index 44db46ea..d7a52937 100644 --- a/js/src/name-pubsub/subs.js +++ b/js/src/name-pubsub/subs.js @@ -2,16 +2,9 @@ /* eslint-env mocha */ 'use strict' -const series = require('async/series') -const loadFixture = require('aegir/fixtures') - const { spawnNodeWithId } = require('../utils/spawn') const { getDescribe, getIt, expect } = require('../utils/mocha') -const fixture = Object.freeze({ - data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core') -}) - module.exports = (createCommon, options) => { const describe = getDescribe(options) const it = getIt(options) @@ -19,8 +12,6 @@ module.exports = (createCommon, options) => { describe('.name.pubsub.subs', function () { let ipfs - let nodeId - let value before(function (done) { // CI takes longer to instantiate the daemon, so we need to increase the @@ -34,14 +25,7 @@ module.exports = (createCommon, options) => { expect(err).to.not.exist() ipfs = node - nodeId = node.peerId.id - - ipfs.add(fixture.data, { pin: false }, (err, res) => { - expect(err).to.not.exist() - - value = res[0].path - done() - }) + done() }) }) }) @@ -62,19 +46,22 @@ module.exports = (createCommon, options) => { it('should get the list of subscriptions updated after a resolve', function (done) { this.timeout(300 * 1000) + const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA' - series([ - (cb) => ipfs.name.pubsub.subs(cb), - (cb) => ipfs.name.publish(value, { resolve: false }, cb), - (cb) => ipfs.name.resolve(nodeId, cb), - (cb) => ipfs.name.pubsub.subs(cb) - ], (err, res) => { + ipfs.name.pubsub.subs((err, res) => { expect(err).to.not.exist() - expect(res).to.exist() - expect(res[0]).to.eql([]) // initally empty - expect(res[3]).to.be.an('array').that.does.include(`/ipns/${nodeId}`) + expect(res).to.eql([]) // initally empty - done() + ipfs.name.resolve(id, (err) => { + expect(err).to.exist() + + ipfs.name.pubsub.subs((err, res) => { + expect(err).to.not.exist() + expect(res).to.be.an('array').that.does.include(`/ipns/${id}`) + + done() + }) + }) }) }) })