Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,23 @@ module.exports = (common) => {

describe('promise API', () => {
describe('.get', () => {
it('retrieve the whole config', (done) => {
ipfs.config.get()
it('retrieve the whole config', () => {
return ipfs.config.get()
.then((config) => {
expect(config).to.exist
done()
})
.catch((err) => {
expect(err).to.not.exist
})
})
})

describe('.set', () => {
it('set a new key', (done) => {
ipfs.config.set('Fruit', 'banana')
it('set a new key', () => {
return ipfs.config.set('Fruit', 'banana')
.then(() => {
ipfs.config.get('Fruit', (err, fruit) => {
expect(err).to.not.exist
expect(fruit).to.equal('banana')
done()
})
})
.catch((err) => {
expect(err).to.not.exist
})
})
})

Expand Down
32 changes: 10 additions & 22 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,44 +226,37 @@ module.exports = (common) => {
})
})

describe('promise API', (done) => {
describe('promise API', () => {
describe('.add', () => {
it('buffer', (done) => {
it('buffer', () => {
return ipfs.files.add(smallFile)
.then((res) => {
const added = res[0] != null ? res[0] : res
const mh = bs58.encode(added.node.multihash()).toString()
expect(mh).to.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
expect(added.path).to.equal(mh)
expect(added.node.links).to.have.length(0)
done()
})
.catch((err) => {
expect(err).to.not.exist
})
})
})

describe('.cat', () => {
it('with a bas58 multihash encoded string', (done) => {
it('with a bas58 multihash encoded string', () => {
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
ipfs.cat(hash)

return ipfs.cat(hash)
.then((stream) => {
stream.pipe(bl((err, data) => {
expect(err).to.not.exist
expect(data.toString()).to.contain('Check out some of the other files in this directory:')
done()
}))
})
.catch((err) => {
expect(err).to.not.exist
})
})

it('errors on invalid key', (done) => {
it('errors on invalid key', () => {
const hash = 'somethingNotMultihash'
ipfs.cat(hash)
.then((stream) => {})

return ipfs.cat(hash)
.catch((err) => {
expect(err).to.exist
const errString = err.toString()
Expand All @@ -273,23 +266,18 @@ module.exports = (common) => {
if (errString === 'Error: Invalid Key') {
expect(err.toString()).to.contain('Error: Invalid Key')
}
done()
})
})

it('with a multihash', (done) => {
it('with a multihash', () => {
const hash = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'))
ipfs.cat(hash)
return ipfs.cat(hash)
.then((stream) => {
stream.pipe(bl((err, bldata) => {
expect(err).to.not.exist
expect(bldata.toString()).to.contain('Check out some of the other files in this directory:')
done()
}))
})
.catch((err) => {
expect(err).to.not.exist
})
})
})
})
Expand Down
Loading