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

test: extend block coverage #266

Merged
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
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