From eb2b4f311c2d5f876bcc669c2b78092847e9f9b7 Mon Sep 17 00:00:00 2001 From: Mahmudul Hazra Date: Thu, 19 Sep 2019 21:30:55 +0200 Subject: [PATCH 1/2] fix(repository): prevents lib from crashing when not providing optional arguments --- lib/Repository.js | 1 + test/repository.spec.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/Repository.js b/lib/Repository.js index 3908775c..daf9443f 100644 --- a/lib/Repository.js +++ b/lib/Repository.js @@ -749,6 +749,7 @@ class Repository extends Requestable { * @return {Promise} - the promise for the http request */ writeFile(branch, path, content, message, options, cb) { + options = options || {}; if (typeof options === 'function') { cb = options; options = {}; diff --git a/test/repository.spec.js b/test/repository.spec.js index 3de25bef..5885916f 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -385,6 +385,17 @@ describe('Repository', function() { })); }); + it('should successfully write to repo when not providing optional options argument', function(done) { + remoteRepo.writeFile('master', fileName, initialText, initialMessage, undefined, assertSuccessful(done, function() { + wait()().then(() => remoteRepo.getContents('master', fileName, 'raw', + assertSuccessful(done, function(err, fileText) { + expect(fileText).to.be(initialText); + + done(); + }))); + })); + }); + it('should rename files', function(done) { remoteRepo.writeFile('master', fileName, initialText, initialMessage, assertSuccessful(done, function() { wait()().then(() => remoteRepo.move('master', fileName, 'new_name', assertSuccessful(done, function() { From 0234b39555e25065e4db1847d2ebd29731740590 Mon Sep 17 00:00:00 2001 From: Mahmudul Hazra Date: Sat, 19 Oct 2019 17:11:22 +0200 Subject: [PATCH 2/2] test(repository): updates test to use promise instead of callback --- test/repository.spec.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/repository.spec.js b/test/repository.spec.js index 5885916f..7102874b 100644 --- a/test/repository.spec.js +++ b/test/repository.spec.js @@ -386,14 +386,13 @@ describe('Repository', function() { }); it('should successfully write to repo when not providing optional options argument', function(done) { - remoteRepo.writeFile('master', fileName, initialText, initialMessage, undefined, assertSuccessful(done, function() { - wait()().then(() => remoteRepo.getContents('master', fileName, 'raw', - assertSuccessful(done, function(err, fileText) { - expect(fileText).to.be(initialText); + const promise = remoteRepo.writeFile('master', fileName, initialText, initialMessage); + promise.then(() => remoteRepo.getContents('master', fileName, 'raw', + assertSuccessful(done, function(err, fileText) { + expect(fileText).to.be(initialText); - done(); - }))); - })); + done(); + }))) }); it('should rename files', function(done) {