Created
August 23, 2013 19:59
-
-
Save DannyDouglass/6323369 to your computer and use it in GitHub Desktop.
Simple api mock test against github enterprise api to create a new repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('POST to Github API to create new repository with answers', function() { | |
it('should return an HTTP Status 201 Completed', function() { | |
var fakeAnswers = { | |
githubRepoName: 'test-repo', | |
githubOrganization: 'test-organization' | |
}; | |
var githubMock = nock('http://github.nreca.org') | |
.post('/api/v3/orgs/' + fakeAnswers.githubOrganization + '/repos', fakeAnswers) | |
.reply(201, 'POST was successful'); | |
var options = { | |
uri: "http://github.nreca.org/api/v3/orgs/" + fakeAnswers.githubOrganization + "/repos", | |
method: "POST", | |
json: fakeAnswers | |
}; | |
request.post(options, function(error, response, body) { | |
githubMock.done(); | |
assert(response.statusCode === 201) | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 2: function(done) instead of function(). Done will allow you to indicate you are done with asynchronous processing - which you have here.
Line 21: below this call done() - this will indicate you've finished async
Line 0: require('should') - so we can easily test some assertions
Line 21: response.statusCode.should.be(201) - actual test verification