|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const chai = require('chai') |
| 5 | +const dirtyChai = require('dirty-chai') |
| 6 | +const expect = chai.expect |
| 7 | +chai.use(dirtyChai) |
| 8 | + |
| 9 | +const parallel = require('async/parallel') |
| 10 | +const series = require('async/series') |
| 11 | + |
| 12 | +const IPFSApi = require('../src') |
| 13 | +const f = require('./utils/factory') |
| 14 | + |
| 15 | +describe('.name-pubsub', () => { |
| 16 | + let ipfs |
| 17 | + let ipfsd |
| 18 | + let otherd |
| 19 | + |
| 20 | + before(function (done) { |
| 21 | + this.timeout(30 * 1000) |
| 22 | + |
| 23 | + series([ |
| 24 | + (cb) => { |
| 25 | + f.spawn({ |
| 26 | + initOptions: { bits: 1024 }, |
| 27 | + args: ['--enable-namesys-pubsub'] |
| 28 | + }, (err, _ipfsd) => { |
| 29 | + expect(err).to.not.exist() |
| 30 | + ipfsd = _ipfsd |
| 31 | + ipfs = IPFSApi(_ipfsd.apiAddr) |
| 32 | + cb() |
| 33 | + }) |
| 34 | + }, |
| 35 | + (cb) => { |
| 36 | + f.spawn({ initOptions: { bits: 1024 } }, (err, node) => { |
| 37 | + expect(err).to.not.exist() |
| 38 | + otherd = node |
| 39 | + cb() |
| 40 | + }) |
| 41 | + } |
| 42 | + ], done) |
| 43 | + }) |
| 44 | + |
| 45 | + after(function (done) { |
| 46 | + this.timeout(10 * 1000) |
| 47 | + |
| 48 | + parallel([ |
| 49 | + (cb) => { |
| 50 | + if (!ipfsd) return cb() |
| 51 | + ipfsd.stop(cb) |
| 52 | + }, |
| 53 | + (cb) => { |
| 54 | + if (!otherd) return cb() |
| 55 | + otherd.stop(cb) |
| 56 | + } |
| 57 | + ], done) |
| 58 | + }) |
| 59 | + |
| 60 | + it('.name.pubsub.state', (done) => { |
| 61 | + ipfs.name.pubsub.state((err, res) => { |
| 62 | + expect(err).to.not.exist() |
| 63 | + expect(res).to.exist() |
| 64 | + expect(res).to.have.property('enabled') |
| 65 | + expect(res.enabled).to.be.eql(true) |
| 66 | + done() |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + it('.name.pubsub.subs', (done) => { |
| 71 | + ipfs.name.pubsub.subs((err, res) => { |
| 72 | + expect(err).to.not.exist() |
| 73 | + expect(res).to.exist() |
| 74 | + expect(res).to.have.property('strings') |
| 75 | + done() |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + it('.name.pubsub.cancel', (done) => { |
| 80 | + ipfs.name.pubsub.cancel('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC', (err, res) => { |
| 81 | + expect(err).to.not.exist() |
| 82 | + expect(res).to.exist() |
| 83 | + expect(res).to.have.property('canceled') |
| 84 | + done() |
| 85 | + }) |
| 86 | + }) |
| 87 | +}) |
0 commit comments