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

Commit

Permalink
extend test coverage on the files api
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinmcdermott committed May 11, 2016
1 parent 65f4b75 commit 7392c65
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/api/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ module.exports = (send) => {
mkdir: argCommand(send, 'files/mkdir'),
stat: argCommand(send, 'files/stat'),
rm: function (path, opts, cb) {
if (typeof opts === 'function' && !cb) {
if (typeof opts === 'function' && cb === undefined) {
cb = opts
opts = {}
}
return send('files/rm', path, opts, null, cb)
},
read: argCommand(send, 'files/read'),
write: function (pathDst, files, opts, cb) {
if (typeof (opts) === 'function' && cb === undefined) {
if (typeof opts === 'function' && cb === undefined) {
cb = opts
opts = {}
}

return send('files/write', pathDst, opts, files, cb)
},
mv: argCommand(send, 'files/mv')
Expand Down
57 changes: 56 additions & 1 deletion test/api/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ describe('.files', () => {
})
})

it('files.write without options', (done) => {
apiClients.a.files
.write('/test-folder/test-file-2.txt', new Buffer('hello world'), (err) => {
expect(err).to.not.exist

apiClients.a.files.read('/test-folder/test-file-2.txt', (err, stream) => {
expect(err).to.not.exist

let buf = ''
stream
.on('error', (err) => {
expect(err).to.not.exist
})
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(buf).to.be.equal('hello world')
done()
})
})
})
})

it('files.stat', (done) => {
apiClients.a.files.stat('/test-folder/test-file', (err, res) => {
expect(err).to.not.exist
Expand Down Expand Up @@ -109,7 +133,12 @@ describe('.files', () => {
})
})

// -
it('files.rm without options', (done) => {
apiClients.a.files.rm('/test-folder/test-file-2.txt', (err) => {
expect(err).to.not.exist
done()
})
})

it('files.rm', (done) => {
apiClients.a.files.rm('/test-folder', {recursive: true}, (err) => {
Expand Down Expand Up @@ -157,6 +186,28 @@ describe('.files', () => {
})
})

it('files.write without options', (done) => {
return apiClients.a.files
.write('/test-folder/test-file-2.txt', new Buffer('hello world'))
.then(() => {
return apiClients.a.files.read('/test-folder/test-file-2.txt')
})
.then((stream) => {
let buf = ''
stream
.on('error', (err) => {
expect(err).to.not.exist
})
.on('data', (data) => {
buf += data
})
.on('end', () => {
expect(buf).to.be.equal('hello world')
done()
})
})
})

it('files.stat', () => {
return apiClients.a.files.stat('/test-folder/test-file')
.then((res) => {
Expand Down Expand Up @@ -200,6 +251,10 @@ describe('.files', () => {
})
})

it('files.rm without options', () => {
return apiClients.a.files.rm('/test-folder/test-file-2.txt')
})

it('files.rm', () => {
return apiClients.a.files.rm('/test-folder', {recursive: true})
})
Expand Down

0 comments on commit 7392c65

Please sign in to comment.