Skip to content

test: add performance test for code in GitHub stats fetcher file #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion tests/renderStatsCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ jest.mock("express", () => ({
},
}));

const exampleUserData: User = {
type ExtendUser = User & {
joinedAt: string;
totalCommitsSinceJoined: number;
}

const exampleUserData: ExtendUser = {
name: "Fajar",
login: "FajarKim",
avatarUrl: "base64-encoded-image",
Expand All @@ -34,6 +39,8 @@ const exampleUserData: User = {
totalCommitContributions: 1200,
restrictedContributionsCount: 130,
totalPullRequestReviewContributions: 340,
joinedAt: "2020-01-01T00:00:00Z",
totalCommitsSinceJoined: 1500,
};

describe("Test GitHub Readme Profile API", () => {
Expand All @@ -52,6 +59,8 @@ describe("Test GitHub Readme Profile API", () => {
status: jest.fn(),
};

(getData as jest.Mock).mockResolvedValue(exampleUserData);

jest.clearAllMocks();
});

Expand Down Expand Up @@ -148,4 +157,19 @@ describe("Test GitHub Readme Profile API", () => {
expect(mockResponse.send).toHaveBeenCalled();
expect(mockResponse.json).not.toHaveBeenCalled();
});

it("should correctly fetch user join date and total commits since joining", async () => {
mockRequest.query.username = "FajarKim";
(getData as jest.Mock).mockResolvedValueOnce(exampleUserData);

await readmeStats(mockRequest, mockResponse);

expect(getData).toHaveBeenCalledWith(mockRequest.query.username);
expect(mockResponse.json).toHaveBeenCalledWith(
expect.objectContaining({
joinedAt: "2020-01-01T00:00:00Z",
totalCommitsSinceJoined: 1500,
})
);
});
});
Loading