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

Commit

Permalink
Remove one level of callback nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
victorb committed Nov 8, 2016
1 parent 0feb397 commit 143333b
Showing 1 changed file with 27 additions and 37 deletions.
64 changes: 27 additions & 37 deletions src/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,33 @@ module.exports = (common) => {
})

describe('callback API', () => {
describe('.get', (done) => {
it('errors when getting a non-existent key from the DHT', (done) => {
ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => {
expect(err).to.be.an.instanceof(Error)
done()
})
it('.get errors when getting a non-existent key from the DHT', (done) => {
ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
describe('.findprovs', () => {
it('finds providers', (done) => {
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
expect(err).to.not.exist
it('.findprovs', (done) => {
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
expect(err).to.not.exist

expect(res).to.be.an('array')
done()
})
expect(res).to.be.an('array')
done()
})
})
})
describe('promise API', () => {
describe('.get', (done) => {
it('errors when getting a non-existent key from the DHT', (done) => {
ipfs.dht.get('non-existing', {timeout: '100ms'}).catch((err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
it('.get errors when getting a non-existent key from the DHT', (done) => {
ipfs.dht.get('non-existing', {timeout: '100ms'}).catch((err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
describe('.findprovs', () => {
it('finds providers', (done) => {
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP').then((res) => {
expect(res).to.be.an('array')
done()
}).catch(done)
})
it('.findprovs', (done) => {
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP').then((res) => {
expect(res).to.be.an('array')
done()
}).catch(done)
})
})
// Tests below are tests that haven't been implemented yet or is not
Expand All @@ -79,19 +71,17 @@ module.exports = (common) => {
})
})
})
xdescribe('.put & .get', () => {
it('puts and gets a key value pair in the DHT', (done) => {
peers.a.ipfs.dht.put('scope', 'interplanetary', (err, res) => {
expect(err).to.not.exist
xit('.put and .get a key value pair in the DHT', (done) => {
peers.a.ipfs.dht.put('scope', 'interplanetary', (err, res) => {
expect(err).to.not.exist

expect(res).to.be.an('array')
expect(res).to.be.an('array')

// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
peers.b.ipfs.dht.get('scope', (err, value) => {
expect(err).to.not.exist
expect(value).to.be.equal('interplanetary')
done()
})
// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
peers.b.ipfs.dht.get('scope', (err, value) => {
expect(err).to.not.exist
expect(value).to.be.equal('interplanetary')
done()
})
})
})
Expand Down

0 comments on commit 143333b

Please sign in to comment.