forked from vn7n24fzkq/github-profile-summary-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
545c433
commit fc80cd0
Showing
7 changed files
with
320 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const getProfileDetails = require("../../src/github-api/profile-details"); | ||
const axios = require("axios"); | ||
const MockAdapter = require("axios-mock-adapter"); | ||
const mock = new MockAdapter(axios); | ||
|
||
const data = { | ||
data: { | ||
user: { | ||
name: "vn7", | ||
email: "[email protected]", | ||
createdAt: "2016-07-01T10:46:25Z", | ||
twitterUsername: null, | ||
company: "vn7", | ||
location: "Taiwan", | ||
websiteUrl: null, | ||
repositories: { | ||
totalCount: 30, | ||
}, | ||
contributionsCollection: { | ||
totalIssueContributions: 10, | ||
totalCommitContributions: 20, | ||
totalRepositoryContributions: 30, | ||
totalPullRequestContributions: 40, | ||
totalPullRequestReviewContributions: 50, | ||
contributionCalendar: { | ||
totalContributions: 1030, | ||
weeks: [ | ||
{ | ||
contributionDays: [ | ||
{ | ||
date: "2019-09-06T00:00:00.000+00:00", | ||
contributionCount: 20, | ||
}, | ||
{ | ||
date: "2019-09-07T00:00:00.000+00:00", | ||
contributionCount: 10, | ||
}, | ||
], | ||
}, | ||
{ | ||
contributionDays: [ | ||
{ | ||
date: "2020-01-12T00:00:00.000+00:00", | ||
contributionCount: 5, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const error = { | ||
errors: [ | ||
{ | ||
type: "NOT_FOUND", | ||
path: ["user"], | ||
locations: [], | ||
message: "Github api failed", | ||
}, | ||
], | ||
}; | ||
|
||
afterEach(() => { | ||
mock.reset(); | ||
}); | ||
|
||
describe("github api for profile details", () => { | ||
it("should get correct profile data", async () => { | ||
mock.onPost("https://api.github.com/graphql").reply(200, data); | ||
let profileDetails = await getProfileDetails("vn7n24fzkq"); | ||
expect(profileDetails).toStrictEqual({ | ||
name: "vn7", | ||
email: "[email protected]", | ||
joinedAt: "2016-07-01T10:46:25Z", | ||
company: "vn7", | ||
location: "Taiwan", | ||
websiteUrl: null, | ||
twitterUsername: null, | ||
totalContributions: 1030, | ||
totalPublicRepos: 30, | ||
contributions: [ | ||
{ | ||
date: new Date("2019-09-06T00:00:00.000+00:00"), | ||
contributionCount: 20, | ||
}, | ||
{ | ||
date: new Date("2019-09-07T00:00:00.000+00:00"), | ||
contributionCount: 10, | ||
}, | ||
{ | ||
date: new Date("2020-01-12T00:00:00.000+00:00"), | ||
contributionCount: 5, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("should throw error when api failed", async () => { | ||
mock.onPost("https://api.github.com/graphql").reply(200, error); | ||
await expect(getProfileDetails("vn7n24fzkq")).rejects.toThrow( | ||
"Github api failed" | ||
); | ||
}); | ||
}); | ||
|
Oops, something went wrong.