diff options
| -rw-r--r-- | lib/fetchGitData.js | 8 | ||||
| -rw-r--r-- | test/fetchGitData.js | 94 |
2 files changed, 94 insertions, 8 deletions
diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js index d79a3db..6ab0209 100644 --- a/lib/fetchGitData.js +++ b/lib/fetchGitData.js @@ -55,9 +55,6 @@ var fetchGitData = function(git) { } //-- Set required properties of git if they weren"t provided - if (!git.hasOwnProperty("head")) { - git.head = {}; - } if (!git.hasOwnProperty("branch")) { git.branch = ""; } @@ -66,13 +63,10 @@ var fetchGitData = function(git) { } //-- Assert the property types - if ("object" !== typeof git.head) { - git.head = {}; - } if ("string" !== typeof git.branch) { git.branch = ""; } - if (!git.remotes.hasOwnProperty("length")) { + if (!(git.remotes instanceof Array)) { git.remotes = []; } diff --git a/test/fetchGitData.js b/test/fetchGitData.js index aa5e2b2..c8ddbc5 100644 --- a/test/fetchGitData.js +++ b/test/fetchGitData.js @@ -77,7 +77,73 @@ describe("fetchGitData", function(){ ] }); }); - it("execute git commands when a valid commit hash is given", function() { + it("should convert git.branch to a string", function() { + var objectToString = git({ + "head": { + "id": "COMMIT_HASH" + }, + "branch": { + "covert": "to a string" + } + }); + var arrayToString = git({ + "head": { + "id": "COMMIT_HASH" + }, + "branch": ["convert", "to", "a", "string"] + }); + objectToString.branch.should.be.a("string"); + arrayToString.branch.should.be.a("string"); + }); + it("should convert git.remotes to an array", function() { + var stringToArray = git({ + "head": { + "id": "COMMIT_HASH" + }, + "remotes": "convert from string to an array" + }); + var objectToArray = git({ + "head": { + "id": "COMMIT_HASH" + }, + "remotes": { + "convert": "from object to an array" + } + }); + stringToArray.remotes.should.be.instanceof(Array); + objectToArray.remotes.should.be.instanceof(Array); + }); + it("should save passed remotes", function() { + var options = git({ + "head": { + "id": "COMMIT_HASH" + }, + "remotes": [ + { + "name": "test", + "url": "https://my.test.url" + } + ] + }); + options.should.eql({ + "head": { + "id": "COMMIT_HASH", + "author_name": "Unknown Author", + "author_email": "", + "committer_name": "Unknown Committer", + "committer_email": "", + "message": "Unknown Commit Message" + }, + "branch": "", + "remotes": [ + { + "name": "test", + "url": "https://my.test.url" + } + ] + }); + }); + it("should execute git commands when a valid commit hash is given", function() { var options = git({ "head": { "id": "5eaec7e76af0743f9764e617472ef434f283a195" @@ -96,4 +162,30 @@ describe("fetchGitData", function(){ options.remotes.should.be.instanceof(Array); options.remotes.length.should.be.above(0); }); + it("should combine passed remotes with git remotes when a valid commit hash is given", function() { + var options = git({ + "head": { + "id": "5eaec7e76af0743f9764e617472ef434f283a195" + }, + "remotes": [ + { + "name": "test", + "url": "https://my.test.url" + } + ] + }); + options.head.should.eql({ + "id": "5eaec7e76af0743f9764e617472ef434f283a195", + "author_name": "cainus", + "author_email": "[email protected]", + "committer_name": "cainus", + "committer_email": "[email protected]", + "message": "first commit" + }); + options.branch.should.equal("master"); + options.remotes.should.includeEql({ + "name": "test", + "url": "https://my.test.url" + }); + }); }); |
