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

Extend test coverage in the files api #270

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