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

Commit

Permalink
Merge pull request #266 from gavinmcdermott/test/extend_block_coverage
Browse files Browse the repository at this point in the history
test: extend block coverage
  • Loading branch information
dignifiedquire committed May 11, 2016
2 parents 18e20af + 9353145 commit 6df8651
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/api/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module.exports = (send) => {
stat: argCommand(send, 'block/stat'),
put (file, cb) {
if (Array.isArray(file)) {
return cb(null, new Error('block.put() only accepts 1 file'))
let err = new Error('block.put() only accepts 1 file')
if (typeof cb !== 'function' && typeof Promise !== 'undefined') {
return new Promise((resolve, reject) => reject(err))
}
return cb(err)
}
return send('block/put', null, null, file, cb)
}
Expand Down
13 changes: 13 additions & 0 deletions test/api/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ describe('.block', () => {
const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const blorb = Buffer('blorb')

it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb], (err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('block.put', (done) => {
apiClients.a.block.put(blorb, (err, res) => {
expect(err).to.not.exist
Expand Down Expand Up @@ -40,6 +46,13 @@ describe('.block', () => {
})

describe('promise', () => {
it('returns an error when putting an array of files', () => {
return apiClients.a.block.put([blorb, blorb])
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})

it('block.put', () => {
return apiClients.a.block.put(blorb)
.then((res) => {
Expand Down

0 comments on commit 6df8651

Please sign in to comment.