mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-05-19 01:26:17 +00:00
107f7ca52c
* GRS-1955: Using ES6 import/export in src files * GRS-1955: Using ES6 import/export in test files * GRS-1955: Using ES6 import/export in themes index.js * GRS-1955: Readding blank line at end of top-languages-card.js * feat: fix test es6 import errors This commit makes sure jest is set-up to support es6. It also fixes several test errors and sorts the imports. * test: update test node version This commit makes sure node 16 is used in the github actions. * refactor: run prettier Co-authored-by: rickstaa <rick.staa@outlook.com>
104 lines
2.8 KiB
JavaScript
104 lines
2.8 KiB
JavaScript
import "@testing-library/jest-dom";
|
|
import axios from "axios";
|
|
import MockAdapter from "axios-mock-adapter";
|
|
import fetchRepo from "../src/fetchers/repo-fetcher";
|
|
|
|
const data_repo = {
|
|
repository: {
|
|
name: "convoychat",
|
|
stargazers: { totalCount: 38000 },
|
|
description: "Help us take over the world! React + TS + GraphQL Chat App",
|
|
primaryLanguage: {
|
|
color: "#2b7489",
|
|
id: "MDg6TGFuZ3VhZ2UyODc=",
|
|
name: "TypeScript",
|
|
},
|
|
forkCount: 100,
|
|
},
|
|
};
|
|
|
|
const data_user = {
|
|
data: {
|
|
user: { repository: data_repo.repository },
|
|
organization: null,
|
|
},
|
|
};
|
|
const data_org = {
|
|
data: {
|
|
user: null,
|
|
organization: { repository: data_repo.repository },
|
|
},
|
|
};
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
afterEach(() => {
|
|
mock.reset();
|
|
});
|
|
|
|
describe("Test fetchRepo", () => {
|
|
it("should fetch correct user repo", async () => {
|
|
mock.onPost("https://api.github.com/graphql").reply(200, data_user);
|
|
|
|
let repo = await fetchRepo("anuraghazra", "convoychat");
|
|
|
|
expect(repo).toStrictEqual({
|
|
...data_repo.repository,
|
|
starCount: data_repo.repository.stargazers.totalCount,
|
|
});
|
|
});
|
|
|
|
it("should fetch correct org repo", async () => {
|
|
mock.onPost("https://api.github.com/graphql").reply(200, data_org);
|
|
|
|
let repo = await fetchRepo("anuraghazra", "convoychat");
|
|
expect(repo).toStrictEqual({
|
|
...data_repo.repository,
|
|
starCount: data_repo.repository.stargazers.totalCount,
|
|
});
|
|
});
|
|
|
|
it("should throw error if user is found but repo is null", async () => {
|
|
mock
|
|
.onPost("https://api.github.com/graphql")
|
|
.reply(200, { data: { user: { repository: null }, organization: null } });
|
|
|
|
await expect(fetchRepo("anuraghazra", "convoychat")).rejects.toThrow(
|
|
"User Repository Not found",
|
|
);
|
|
});
|
|
|
|
it("should throw error if org is found but repo is null", async () => {
|
|
mock
|
|
.onPost("https://api.github.com/graphql")
|
|
.reply(200, { data: { user: null, organization: { repository: null } } });
|
|
|
|
await expect(fetchRepo("anuraghazra", "convoychat")).rejects.toThrow(
|
|
"Organization Repository Not found",
|
|
);
|
|
});
|
|
|
|
it("should throw error if both user & org data not found", async () => {
|
|
mock
|
|
.onPost("https://api.github.com/graphql")
|
|
.reply(200, { data: { user: null, organization: null } });
|
|
|
|
await expect(fetchRepo("anuraghazra", "convoychat")).rejects.toThrow(
|
|
"Not found",
|
|
);
|
|
});
|
|
|
|
it("should throw error if repository is private", async () => {
|
|
mock.onPost("https://api.github.com/graphql").reply(200, {
|
|
data: {
|
|
user: { repository: { ...data_repo, isPrivate: true } },
|
|
organization: null,
|
|
},
|
|
});
|
|
|
|
await expect(fetchRepo("anuraghazra", "convoychat")).rejects.toThrow(
|
|
"User Repository Not found",
|
|
);
|
|
});
|
|
});
|