Skip to content

Commit 3d572e7

Browse files
committed
Finished full test suite, updated types and properties, now all tests pass
1 parent 581dc9d commit 3d572e7

File tree

2 files changed

+56
-24
lines changed

2 files changed

+56
-24
lines changed

src/__tests__/index.test.ts

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const mockedGetInput = mocked(core.getInput);
1313
const mockedSetFailed = mocked(core.setFailed);
1414
const mockedSetOutput = mocked(core.setOutput);
1515
const mockedGraphQL = mocked(graphql);
16+
3;
1617

1718
beforeEach(async () => {
1819
await jest.clearAllMocks();
@@ -30,34 +31,72 @@ afterAll(async () => {
3031
await jest.clearAllMocks();
3132
});
3233

33-
test("run function successfully runs", async () => {
34-
await mockedGetInput.mockReturnValueOnce("{{ secrets.GITHUB_TOKEN }}");
34+
// test("run function successfully runs", async () => {
35+
// await mockedGetInput.mockReturnValueOnce("{{ secrets.GITHUB_TOKEN }}");
36+
// await mockedGetInput.mockReturnValueOnce("3");
37+
// await mockedGetInput.mockReturnValueOnce("3");
38+
39+
// const mockedResponse = {
40+
// clientMutationId: "1234",
41+
// discussion: {
42+
// node_id: "DC_kwDOKczwv84Abmrk",
43+
// },
44+
// };
45+
// const mockedResult = {
46+
// commentId: "DC_kwDOKczwv84Abmrk",
47+
// commentText: "hello",
48+
// reactionThreshold: 3,
49+
// totalReactions: 10,
50+
// totalPositiveReactions: 5,
51+
// };
52+
53+
// await mockedGraphQL.mockResolvedValueOnce(commentsReactions);
54+
// await markDiscussionCommentAnswer();
55+
56+
// await expect(mockedGetInput).toHaveBeenCalledTimes(3);
57+
// await expect(mockedGraphQL).toHaveBeenCalledTimes(2);
58+
// await expect(mockedSetOutput).toHaveBeenCalledWith("commentText", "hello");
59+
// await expect(mockedSetOutput).toHaveBeenCalledWith("reactionThreshold", 3);
60+
// await expect(mockedSetOutput).toHaveBeenCalledWith("totalReactions", 6);
61+
// await expect(mockedSetOutput).toHaveBeenCalledWith("commentId", "DC_kwDOKczwv84Abmrk");
62+
// });
63+
64+
test("Run function successfully with mocked GraphQL responses", async () => {
3565
await mockedGetInput.mockReturnValueOnce("3");
3666
await mockedGetInput.mockReturnValueOnce("3");
3767

38-
const mockedResponse = {
39-
clientMutationId: "1234",
40-
discussion: {
41-
node_id: "DC_kwDOKczwv84Abmrk",
42-
},
43-
};
44-
const mockedResult = {
68+
await mockedGraphQL.mockResolvedValueOnce(commentsReactions);
69+
70+
// Mock GraphQL response for checkComments
71+
const mockedCheckCommentsResponse = {
4572
commentId: "DC_kwDOKczwv84Abmrk",
4673
commentText: "hello",
47-
reactionThreshold: 3,
4874
totalReactions: 10,
4975
totalPositiveReactions: 5,
5076
};
5177

52-
await mockedGraphQL.mockResolvedValueOnce(commentsReactions);
78+
// Mock GraphQL response for markDiscussionCommentAsAnswer
79+
const mockedMarkDiscussionResponse = {
80+
clientMutationId: "1234",
81+
discussion: {
82+
node_id: "D_kwDOKczwv84AV0aF",
83+
},
84+
};
85+
await mockedGraphQL.mockResolvedValueOnce(mockedMarkDiscussionResponse);
86+
5387
await markDiscussionCommentAnswer();
5488

5589
await expect(mockedGetInput).toHaveBeenCalledTimes(3);
5690
await expect(mockedGraphQL).toHaveBeenCalledTimes(2);
91+
await expect(mockedSetOutput).toHaveBeenCalledTimes(7);
92+
93+
// Add assertions for the final output (Res) based on your specific data
5794
await expect(mockedSetOutput).toHaveBeenCalledWith("commentText", "hello");
5895
await expect(mockedSetOutput).toHaveBeenCalledWith("reactionThreshold", 3);
5996
await expect(mockedSetOutput).toHaveBeenCalledWith("totalReactions", 6);
6097
await expect(mockedSetOutput).toHaveBeenCalledWith("commentId", "DC_kwDOKczwv84Abmrk");
98+
await expect(mockedSetOutput).toHaveBeenCalledWith("discussionId", "D_kwDOKczwv84AV0aF");
99+
await expect(mockedSetOutput).toHaveBeenCalledWith("clientMutationId", "1234");
61100
});
62101

63102
test("Test if discussion is already answered", async () => {

src/index.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import { getInput, setFailed, setOutput } from "@actions/core";
22
import { graphql } from "@octokit/graphql";
33

44
interface Res {
5-
markDiscussionCommentAsAnswer: {
6-
clientMutationId: string;
7-
discussion: {
8-
node_id: string;
9-
};
5+
clientMutationId: string;
6+
discussion: {
7+
node_id: string;
108
};
119
}
1210

@@ -154,23 +152,18 @@ export async function markDiscussionCommentAnswer() {
154152
await setFailed("Comment reaction threshold has not been met to be considered an answer.");
155153
return;
156154
}
155+
const response = await markDiscussionAnswerCall(commentNodeId, token);
157156
commentNodeId = result.commentId;
158157
await setOutput("commentText", result.commentText);
159158
await setOutput("reactionThreshold", Number(reactionThreshold));
160159
await setOutput("totalReactions", result.totalReactions);
161160
await setOutput("totalPositiveReactions", result.totalPositiveReactions);
162161
await setOutput("commentId", result.commentId);
162+
await setOutput("discussionId", response.discussion.node_id);
163+
await setOutput("clientMutationId", response.clientMutationId);
163164
} catch (err) {
164165
await setFailed(String(err));
165166
}
166-
167-
try {
168-
const response = await markDiscussionAnswerCall(commentNodeId, token);
169-
await setOutput("discussionId", response.markDiscussionCommentAsAnswer.discussion.node_id);
170-
await setOutput("clientMutationId", response.markDiscussionCommentAsAnswer.clientMutationId);
171-
} catch (error: any) {
172-
await setFailed(error.message);
173-
}
174167
}
175168

176169
if (!process.env.JEST_WORKER_ID) {

0 commit comments

Comments
 (0)