From 7fcde729905ef01268342b0b03b1c37b83176a73 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 17 Oct 2018 17:20:44 +0100 Subject: [PATCH] fix: code review --- README.md | 2 +- src/name/pubsub/cancel.js | 2 +- src/name/pubsub/subs.js | 4 +- test/interface.spec.js | 4 +- test/name-pubsub.spec.js | 87 --------------------------------------- 5 files changed, 5 insertions(+), 94 deletions(-) delete mode 100644 test/name-pubsub.spec.js diff --git a/README.md b/README.md index cb448e079..7bf46d5fe 100644 --- a/README.md +++ b/README.md @@ -277,10 +277,10 @@ const ipfs = IpfsApi({ - [name](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md) - [`ipfs.name.publish(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepublish) - - [`ipfs.name.resolve(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#nameresolve) - [`ipfs.name.pubsub.cancel(arg, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubcancel) - [`ipfs.name.pubsub.state([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubstate) - [`ipfs.name.pubsub.subs([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubsubs) + - [`ipfs.name.resolve(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#nameresolve) #### Node Management diff --git a/src/name/pubsub/cancel.js b/src/name/pubsub/cancel.js index 941969b71..32dbbb3af 100644 --- a/src/name/pubsub/cancel.js +++ b/src/name/pubsub/cancel.js @@ -4,7 +4,7 @@ const promisify = require('promisify-es6') const transform = function (res, callback) { callback(null, { - canceled: res.Canceled + canceled: res.Canceled === undefined || res.Canceled === true }) } diff --git a/src/name/pubsub/subs.js b/src/name/pubsub/subs.js index eda39bb17..3a3a54c2a 100644 --- a/src/name/pubsub/subs.js +++ b/src/name/pubsub/subs.js @@ -3,9 +3,7 @@ const promisify = require('promisify-es6') const transform = function (res, callback) { - callback(null, { - strings: res.Strings - }) + callback(null, res.Strings || []) } module.exports = (send) => { diff --git a/test/interface.spec.js b/test/interface.spec.js index 5c16d01c6..9c6f91f98 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -190,12 +190,12 @@ describe('interface-ipfs-core tests', () => { // name.pubsub.cancel { name: 'should cancel a subscription correctly returning true', - reasone: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode' + reason: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode' }, // name.pubsub.subs { name: 'should get the list of subscriptions updated after a resolve', - reasone: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode' + reason: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode' } ] }) diff --git a/test/name-pubsub.spec.js b/test/name-pubsub.spec.js deleted file mode 100644 index b4b2d9a73..000000000 --- a/test/name-pubsub.spec.js +++ /dev/null @@ -1,87 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -const dirtyChai = require('dirty-chai') -const expect = chai.expect -chai.use(dirtyChai) - -const parallel = require('async/parallel') -const series = require('async/series') - -const IPFSApi = require('../src') -const f = require('./utils/factory') - -describe('.name-pubsub', () => { - let ipfs - let ipfsd - let otherd - - before(function (done) { - this.timeout(30 * 1000) - - series([ - (cb) => { - f.spawn({ - initOptions: { bits: 1024 }, - args: ['--enable-namesys-pubsub'] - }, (err, _ipfsd) => { - expect(err).to.not.exist() - ipfsd = _ipfsd - ipfs = IPFSApi(_ipfsd.apiAddr) - cb() - }) - }, - (cb) => { - f.spawn({ initOptions: { bits: 1024 } }, (err, node) => { - expect(err).to.not.exist() - otherd = node - cb() - }) - } - ], done) - }) - - after(function (done) { - this.timeout(10 * 1000) - - parallel([ - (cb) => { - if (!ipfsd) return cb() - ipfsd.stop(cb) - }, - (cb) => { - if (!otherd) return cb() - otherd.stop(cb) - } - ], done) - }) - - it('.name.pubsub.state', (done) => { - ipfs.name.pubsub.state((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.property('enabled') - expect(res.enabled).to.be.eql(true) - done() - }) - }) - - it('.name.pubsub.subs', (done) => { - ipfs.name.pubsub.subs((err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.property('strings') - done() - }) - }) - - it('.name.pubsub.cancel', (done) => { - ipfs.name.pubsub.cancel('QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC', (err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.property('canceled') - done() - }) - }) -})