Skip to content

Commit 72b76d0

Browse files
committed
Testing: getting repos - mocking GitHub with nock
Simulate a case where a user Strider Tester is registered with github and has admin access to TWO repositories one which belongs to him (stridertester/proj1) and one that belongs to a team Strider Testers Union (stridertestersunion/union-proj-1) getRepos should return an array containing the two repositories. we are using actual responses received from github.com - as recorded and mocked by nock to simulate. This test was failing and we were getting three repositories. This is because when getting the repos for the user, we also get all the repos that he has access to from the teams of which he is a member. Also this was from the fix I intended to check in for Strider-CD/strider#846 xdissent has already checked in the fix, I have changed the comment to explain why a de-dupe is really needed.
1 parent 8fffbbc commit 72b76d0

File tree

4 files changed

+390
-6
lines changed

4 files changed

+390
-6
lines changed

lib/api.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ function getRepos(token, username, callback) {
420420
_.each(results, function (result) {
421421
var team_id = result.req.path.split('/');
422422
debug("We get the following repo path: " + util.inspect(result.req.path));
423-
team_id = team_id[2];
423+
team_id = team_id[2]; //TODO: add Enterprise support. This might be different for Github Enterprise
424424

425425
var team_detail = team_detail_requests[parseInt(team_id, 10)];
426426
if (result.statusCode === 204) {
@@ -458,7 +458,8 @@ function getRepos(token, username, callback) {
458458
}
459459
});
460460

461-
// Sometimes we can get multiple copies of the same repo, so we uniq it
461+
//If the user is a member of a team, we get a repository in repos
462+
//as well as team_repos. Thus we need to merge the two and de-dupe
462463
repos = _.uniq(repos.concat(team_repos), false, function (item) {
463464
return item.id;
464465
});

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
"inline_icon": "github"
3636
},
3737
"devDependencies": {
38-
"jshint": "~2.1.11",
3938
"expect.js": "~0.2.0",
40-
"mocha": "~1.13.0"
39+
"jshint": "~2.1.11",
40+
"mocha": "~1.13.0",
41+
"nock": "^2.10.0"
4142
},
4243
"dependencies": {
4344
"async": "~0.2.9",

0 commit comments

Comments
 (0)