|
| 1 | +/* eslint max-nested-callbacks: ["error", 5] */ |
| 2 | +/* eslint-env mocha */ |
| 3 | +'use strict' |
| 4 | + |
| 5 | +const loadFixture = require('aegir/fixtures') |
| 6 | + |
| 7 | +const { spawnNodeWithId } = require('../utils/spawn') |
| 8 | +const { getDescribe, getIt, expect } = require('../utils/mocha') |
| 9 | + |
| 10 | +const fixture = Object.freeze({ |
| 11 | + data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core'), |
| 12 | + cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' |
| 13 | +}) |
| 14 | + |
| 15 | +module.exports = (createCommon, options) => { |
| 16 | + const describe = getDescribe(options) |
| 17 | + const it = getIt(options) |
| 18 | + const common = createCommon() |
| 19 | + |
| 20 | + describe('.name.pubsub.cancel', function () { |
| 21 | + let ipfs |
| 22 | + let nodeId |
| 23 | + |
| 24 | + before(function (done) { |
| 25 | + // CI takes longer to instantiate the daemon, so we need to increase the |
| 26 | + // timeout for the before step |
| 27 | + this.timeout(60 * 1000) |
| 28 | + |
| 29 | + common.setup((err, factory) => { |
| 30 | + expect(err).to.not.exist() |
| 31 | + |
| 32 | + spawnNodeWithId(factory, (err, node) => { |
| 33 | + expect(err).to.not.exist() |
| 34 | + |
| 35 | + ipfs = node |
| 36 | + nodeId = node.peerId.id |
| 37 | + |
| 38 | + ipfs.files.add(fixture.data, { pin: false }, done) |
| 39 | + }) |
| 40 | + }) |
| 41 | + }) |
| 42 | + |
| 43 | + after((done) => common.teardown(done)) |
| 44 | + |
| 45 | + it('should return false when the name that is intended to cancel is not subscribed', function (done) { |
| 46 | + this.timeout(60 * 1000) |
| 47 | + |
| 48 | + ipfs.name.pubsub.cancel(nodeId, (err, res) => { |
| 49 | + expect(err).to.not.exist() |
| 50 | + expect(res).to.exist() |
| 51 | + expect(res).to.have.property('canceled') |
| 52 | + expect(res.canceled).to.eql(false) |
| 53 | + |
| 54 | + done() |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + it('should cancel a subscription correctly returning true', function (done) { |
| 59 | + this.timeout(140 * 1000) |
| 60 | + const value = fixture.cid |
| 61 | + |
| 62 | + ipfs.name.publish(value, { resolve: false }, (err, res) => { |
| 63 | + expect(err).to.not.exist() |
| 64 | + |
| 65 | + ipfs.name.resolve(nodeId, (err) => { |
| 66 | + expect(err).to.not.exist() |
| 67 | + |
| 68 | + ipfs.name.pubsub.cancel(nodeId, (err, res) => { |
| 69 | + expect(err).to.not.exist() |
| 70 | + expect(res).to.exist() |
| 71 | + expect(res).to.have.property('canceled') |
| 72 | + expect(res.canceled).to.eql(true) |
| 73 | + |
| 74 | + done() |
| 75 | + }) |
| 76 | + }) |
| 77 | + }) |
| 78 | + }) |
| 79 | + }) |
| 80 | +} |
0 commit comments