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

Commit b166d40

Browse files
committed
Merge pull request #270 from gavinmcdermott/test/extend_files_coverage
Extend test coverage in the files api
2 parents 6df8651 + 7392c65 commit b166d40

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

src/api/files.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ module.exports = (send) => {
99
mkdir: argCommand(send, 'files/mkdir'),
1010
stat: argCommand(send, 'files/stat'),
1111
rm: function (path, opts, cb) {
12-
if (typeof opts === 'function' && !cb) {
12+
if (typeof opts === 'function' && cb === undefined) {
1313
cb = opts
1414
opts = {}
1515
}
1616
return send('files/rm', path, opts, null, cb)
1717
},
1818
read: argCommand(send, 'files/read'),
1919
write: function (pathDst, files, opts, cb) {
20-
if (typeof (opts) === 'function' && cb === undefined) {
20+
if (typeof opts === 'function' && cb === undefined) {
2121
cb = opts
2222
opts = {}
2323
}
24-
2524
return send('files/write', pathDst, opts, files, cb)
2625
},
2726
mv: argCommand(send, 'files/mv')

test/api/files.spec.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ describe('.files', () => {
6262
})
6363
})
6464

65+
it('files.write without options', (done) => {
66+
apiClients.a.files
67+
.write('/test-folder/test-file-2.txt', new Buffer('hello world'), (err) => {
68+
expect(err).to.not.exist
69+
70+
apiClients.a.files.read('/test-folder/test-file-2.txt', (err, stream) => {
71+
expect(err).to.not.exist
72+
73+
let buf = ''
74+
stream
75+
.on('error', (err) => {
76+
expect(err).to.not.exist
77+
})
78+
.on('data', (data) => {
79+
buf += data
80+
})
81+
.on('end', () => {
82+
expect(buf).to.be.equal('hello world')
83+
done()
84+
})
85+
})
86+
})
87+
})
88+
6589
it('files.stat', (done) => {
6690
apiClients.a.files.stat('/test-folder/test-file', (err, res) => {
6791
expect(err).to.not.exist
@@ -109,7 +133,12 @@ describe('.files', () => {
109133
})
110134
})
111135

112-
// -
136+
it('files.rm without options', (done) => {
137+
apiClients.a.files.rm('/test-folder/test-file-2.txt', (err) => {
138+
expect(err).to.not.exist
139+
done()
140+
})
141+
})
113142

114143
it('files.rm', (done) => {
115144
apiClients.a.files.rm('/test-folder', {recursive: true}, (err) => {
@@ -157,6 +186,28 @@ describe('.files', () => {
157186
})
158187
})
159188

189+
it('files.write without options', (done) => {
190+
return apiClients.a.files
191+
.write('/test-folder/test-file-2.txt', new Buffer('hello world'))
192+
.then(() => {
193+
return apiClients.a.files.read('/test-folder/test-file-2.txt')
194+
})
195+
.then((stream) => {
196+
let buf = ''
197+
stream
198+
.on('error', (err) => {
199+
expect(err).to.not.exist
200+
})
201+
.on('data', (data) => {
202+
buf += data
203+
})
204+
.on('end', () => {
205+
expect(buf).to.be.equal('hello world')
206+
done()
207+
})
208+
})
209+
})
210+
160211
it('files.stat', () => {
161212
return apiClients.a.files.stat('/test-folder/test-file')
162213
.then((res) => {
@@ -200,6 +251,10 @@ describe('.files', () => {
200251
})
201252
})
202253

254+
it('files.rm without options', () => {
255+
return apiClients.a.files.rm('/test-folder/test-file-2.txt')
256+
})
257+
203258
it('files.rm', () => {
204259
return apiClients.a.files.rm('/test-folder', {recursive: true})
205260
})

0 commit comments

Comments
 (0)