Skip to content
166 changes: 31 additions & 135 deletions pkg/workflow/js/add_labels.test.cjs

Large diffs are not rendered by default.

73 changes: 14 additions & 59 deletions pkg/workflow/js/add_reaction.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,9 @@ describe("add_reaction.cjs", () => {
data: { id: 123, content: "eyes" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith("Reaction type:", "eyes");

consoleSpy.mockRestore();
expect(mockCore.info).toHaveBeenCalledWith(`Reaction type: ${"eyes"}`);
});

it("should fail with invalid reaction type", async () => {
Expand Down Expand Up @@ -161,13 +157,10 @@ describe("add_reaction.cjs", () => {
data: { id: 456, content: "eyes" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith(
"API endpoint:",
"/repos/testowner/testrepo/issues/123/reactions"
expect(mockCore.info).toHaveBeenCalledWith(
`API endpoint: ${"/repos/testowner/testrepo/issues/123/reactions"}`
);
expect(mockGithub.request).toHaveBeenCalledWith(
"POST /repos/testowner/testrepo/issues/123/reactions",
Expand All @@ -176,8 +169,6 @@ describe("add_reaction.cjs", () => {
headers: { Accept: "application/vnd.github+json" },
}
);

consoleSpy.mockRestore();
});

it("should handle issue_comment event", async () => {
Expand All @@ -188,13 +179,10 @@ describe("add_reaction.cjs", () => {
data: { id: 456, content: "eyes" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith(
"API endpoint:",
"/repos/testowner/testrepo/issues/comments/789/reactions"
expect(mockCore.info).toHaveBeenCalledWith(
`API endpoint: ${"/repos/testowner/testrepo/issues/comments/789/reactions"}`
);
expect(mockGithub.request).toHaveBeenCalledWith(
"POST /repos/testowner/testrepo/issues/comments/789/reactions",
Expand All @@ -203,8 +191,6 @@ describe("add_reaction.cjs", () => {
headers: { Accept: "application/vnd.github+json" },
}
);

consoleSpy.mockRestore();
});

it("should handle pull_request event", async () => {
Expand All @@ -215,13 +201,10 @@ describe("add_reaction.cjs", () => {
data: { id: 789, content: "eyes" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith(
"API endpoint:",
"/repos/testowner/testrepo/issues/456/reactions"
expect(mockCore.info).toHaveBeenCalledWith(
`API endpoint: ${"/repos/testowner/testrepo/issues/456/reactions"}`
);
expect(mockGithub.request).toHaveBeenCalledWith(
"POST /repos/testowner/testrepo/issues/456/reactions",
Expand All @@ -230,8 +213,6 @@ describe("add_reaction.cjs", () => {
headers: { Accept: "application/vnd.github+json" },
}
);

consoleSpy.mockRestore();
});

it("should handle pull_request_review_comment event", async () => {
Expand All @@ -242,13 +223,10 @@ describe("add_reaction.cjs", () => {
data: { id: 654, content: "eyes" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith(
"API endpoint:",
"/repos/testowner/testrepo/pulls/comments/321/reactions"
expect(mockCore.info).toHaveBeenCalledWith(
`API endpoint: ${"/repos/testowner/testrepo/pulls/comments/321/reactions"}`
);
expect(mockGithub.request).toHaveBeenCalledWith(
"POST /repos/testowner/testrepo/pulls/comments/321/reactions",
Expand All @@ -257,8 +235,6 @@ describe("add_reaction.cjs", () => {
headers: { Accept: "application/vnd.github+json" },
}
);

consoleSpy.mockRestore();
});

it("should fail on unsupported event type", async () => {
Expand Down Expand Up @@ -302,16 +278,12 @@ describe("add_reaction.cjs", () => {
data: { id: 123, content: "heart" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith(
expect(mockCore.info).toHaveBeenCalledWith(
"Successfully added reaction: heart (id: 123)"
);
expect(mockCore.setOutput).toHaveBeenCalledWith("reaction-id", "123");

consoleSpy.mockRestore();
});

it("should handle response without ID", async () => {
Expand All @@ -321,16 +293,12 @@ describe("add_reaction.cjs", () => {
data: { content: "rocket" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith(
expect(mockCore.info).toHaveBeenCalledWith(
"Successfully added reaction: rocket"
);
expect(mockCore.setOutput).toHaveBeenCalledWith("reaction-id", "");

consoleSpy.mockRestore();
});
});

Expand All @@ -351,8 +319,6 @@ describe("add_reaction.cjs", () => {
expect(mockCore.setFailed).toHaveBeenCalledWith(
"Failed to add reaction: API Error"
);

consoleSpy.mockRestore();
});

it("should handle non-Error objects in catch block", async () => {
Expand All @@ -371,8 +337,6 @@ describe("add_reaction.cjs", () => {
expect(mockCore.setFailed).toHaveBeenCalledWith(
"Failed to add reaction: String error"
);

consoleSpy.mockRestore();
});
});

Expand All @@ -384,30 +348,21 @@ describe("add_reaction.cjs", () => {
data: { id: 123, content: "rocket" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith("Reaction type:", "rocket");

consoleSpy.mockRestore();
expect(mockCore.info).toHaveBeenCalledWith(`Reaction type: ${"rocket"}`);
});

it("should log API endpoint", async () => {
mockGithub.request.mockResolvedValue({
data: { id: 123, content: "eyes" },
});

const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});

await eval(`(async () => { ${addReactionScript} })()`);

expect(consoleSpy).toHaveBeenCalledWith(
"API endpoint:",
"/repos/testowner/testrepo/issues/123/reactions"
expect(mockCore.info).toHaveBeenCalledWith(
`API endpoint: ${"/repos/testowner/testrepo/issues/123/reactions"}`
);

consoleSpy.mockRestore();
});
});
});
Loading
Loading