diff --git a/src/api/files.js b/src/api/files.js index 4eae607a0..2e848c39e 100644 --- a/src/api/files.js +++ b/src/api/files.js @@ -9,7 +9,7 @@ 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 = {} } @@ -17,11 +17,10 @@ module.exports = (send) => { }, 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') diff --git a/test/api/files.spec.js b/test/api/files.spec.js index 69e8769cb..5fa59913b 100644 --- a/test/api/files.spec.js +++ b/test/api/files.spec.js @@ -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 @@ -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) => { @@ -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) => { @@ -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}) })