diff --git a/api/index.js b/api/index.js index 2f1192d90cd112..a966cdc0fb8209 100644 --- a/api/index.js +++ b/api/index.js @@ -51,9 +51,9 @@ export default async (req, res) => { try { const stats = await fetchStats( username, + parseArray(role), parseBoolean(count_private), parseBoolean(include_all_commits), - parseArray(role), ); const cacheSeconds = clampValue( diff --git a/api/top-langs.js b/api/top-langs.js index aa965741b30ccc..d0ec8cbc167f13 100644 --- a/api/top-langs.js +++ b/api/top-langs.js @@ -44,9 +44,8 @@ export default async (req, res) => { try { const topLangs = await fetchTopLanguages( username, - parseArray(exclude_repo), parseArray(role), - parseArray(hide), + parseArray(exclude_repo), ); const cacheSeconds = clampValue( diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index b5ba28564f0341..b590f6d8b3945e 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -213,9 +213,9 @@ const totalCommitsFetcher = async (username) => { */ const fetchStats = async ( username, + ownerAffiliations, count_private = false, include_all_commits = false, - ownerAffiliations, ) { if (!username) throw Error("Invalid username"); diff --git a/src/fetchers/top-languages-fetcher.js b/src/fetchers/top-languages-fetcher.js index 2d68a628caeb8d..be1cfd804f5f7a 100644 --- a/src/fetchers/top-languages-fetcher.js +++ b/src/fetchers/top-languages-fetcher.js @@ -47,7 +47,7 @@ const fetcher = (variables, token) => { ); }; -async function fetchTopLanguages(username, exclude_repo = [], ownerAffiliations) { +async function fetchTopLanguages(username, ownerAffiliations, exclude_repo = []) { if (!username) throw Error("Invalid username"); // Set default value for ownerAffiliations in GraphQL query won't work because diff --git a/tests/fetchStats.test.js b/tests/fetchStats.test.js index 04e943a75b50ad..ed733131aa5a3a 100644 --- a/tests/fetchStats.test.js +++ b/tests/fetchStats.test.js @@ -240,7 +240,7 @@ describe("Test fetchStats", () => { it("should fetch two pages of stars if 'FETCH_MULTI_PAGE_STARS' env variable is set to `true`", async () => { process.env.FETCH_MULTI_PAGE_STARS = true; - let stats = await fetchStats("anuraghazra"); + let stats = await fetchStats("anuraghazra", []); const rank = calculateRank({ totalCommits: 100, totalRepos: 5, @@ -265,7 +265,15 @@ describe("Test fetchStats", () => { it("should fetch one page of stars if 'FETCH_MULTI_PAGE_STARS' env variable is set to `false`", async () => { process.env.FETCH_MULTI_PAGE_STARS = "false"; - let stats = await fetchStats("anuraghazra"); + await expect(fetchStats("anuraghazra", [])).rejects.toThrow( + "Could not resolve to a User with the login of 'noname'.", + ); + }); + + it("should fetch and add private contributions", async () => { + mock.onPost("https://api.github.com/graphql").reply(200, data); + + let stats = await fetchStats("anuraghazra", [], true); const rank = calculateRank({ totalCommits: 100, totalRepos: 5, @@ -290,7 +298,7 @@ describe("Test fetchStats", () => { it("should fetch one page of stars if 'FETCH_MULTI_PAGE_STARS' env variable is not set", async () => { process.env.FETCH_MULTI_PAGE_STARS = undefined; - let stats = await fetchStats("anuraghazra"); + let stats = await fetchStats("anuraghazra", [], true, true); const rank = calculateRank({ totalCommits: 100, totalRepos: 5, diff --git a/tests/fetchTopLanguages.test.js b/tests/fetchTopLanguages.test.js index 24416cd294525e..0f7a151a11b13e 100644 --- a/tests/fetchTopLanguages.test.js +++ b/tests/fetchTopLanguages.test.js @@ -63,7 +63,7 @@ describe("FetchTopLanguages", () => { it("should fetch correct language data", async () => { mock.onPost("https://api.github.com/graphql").reply(200, data_langs); - let repo = await fetchTopLanguages("anuraghazra"); + let repo = await fetchTopLanguages("anuraghazra", []); expect(repo).toStrictEqual({ HTML: { color: "#0f0", @@ -99,7 +99,7 @@ describe("FetchTopLanguages", () => { it("should throw error", async () => { mock.onPost("https://api.github.com/graphql").reply(200, error); - await expect(fetchTopLanguages("anuraghazra")).rejects.toThrow( + await expect(fetchTopLanguages("anuraghazra", [])).rejects.toThrow( "Could not resolve to a User with the login of 'noname'.", ); });