Skip to content
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

test: added end-to-end-style unit test #205

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Changes from 1 commit
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
Next Next commit
test: added end-to-end-style unit test
  • Loading branch information
JoshuaKGoldberg committed Jan 6, 2024
commit 2faadf008bf069c0e2d60224dbc246612afa01b3
104 changes: 104 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { describe, expect, test, vi } from "vitest";

import { getAllContributorsForRepository } from "./index.js";

const mockRequest = (url: string) => {
switch (url) {
case "GET /repos/{owner}/{repo}/issues":
return {
data: [
{
labels: ["type: bug"],
number: 111,
user: {
login: "AcceptedIssueUser",
},
},
],
};
case "GET /repos/{owner}/{repo}/issues/events":
return {
data: [
{
actor: {
login: "IssueEventUser",
},
event: "assigned",
issue: {
number: 222,
},
},
],
};
case "GET /search/issues":
return {
data: {
items: [
{
number: 333,
title: "feat: Merged PR",
user: {
login: "MergedPullUser",
},
},
],
},
};
case "GET /repos/{owner}/{repo}/events":
return {
data: [
{
actor: {
login: "IssueEventUser",
},
issue: {
number: 222,
},
type: "PullRequestReviewEvent",
},
],
};
}
};

vi.mock("octokit", () => ({
get Octokit() {
return class MockOctokit {
static defaults = () => MockOctokit;

request = mockRequest;
};
},
}));

describe("end-to-end", () => {
test("getAllContributorsForRepository", async () => {
const actual = await getAllContributorsForRepository({
owner: "TestOwner",
repo: "test-repository",
});

expect(actual).toMatchInlineSnapshot(`
{
"acceptedissueuser": {
"bug": [
111,
],
},
"issueeventuser": {
"maintenance": [
222,
],
"review": [
222,
],
},
"mergedpulluser": {
"code": [
333,
],
},
}
`);
});
});
Loading