@@ -13,6 +13,7 @@ const mockedGetInput = mocked(core.getInput);
13
13
const mockedSetFailed = mocked ( core . setFailed ) ;
14
14
const mockedSetOutput = mocked ( core . setOutput ) ;
15
15
const mockedGraphQL = mocked ( graphql ) ;
16
+ 3 ;
16
17
17
18
beforeEach ( async ( ) => {
18
19
await jest . clearAllMocks ( ) ;
@@ -30,34 +31,72 @@ afterAll(async () => {
30
31
await jest . clearAllMocks ( ) ;
31
32
} ) ;
32
33
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 ( ) => {
35
65
await mockedGetInput . mockReturnValueOnce ( "3" ) ;
36
66
await mockedGetInput . mockReturnValueOnce ( "3" ) ;
37
67
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 = {
45
72
commentId : "DC_kwDOKczwv84Abmrk" ,
46
73
commentText : "hello" ,
47
- reactionThreshold : 3 ,
48
74
totalReactions : 10 ,
49
75
totalPositiveReactions : 5 ,
50
76
} ;
51
77
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
+
53
87
await markDiscussionCommentAnswer ( ) ;
54
88
55
89
await expect ( mockedGetInput ) . toHaveBeenCalledTimes ( 3 ) ;
56
90
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
57
94
await expect ( mockedSetOutput ) . toHaveBeenCalledWith ( "commentText" , "hello" ) ;
58
95
await expect ( mockedSetOutput ) . toHaveBeenCalledWith ( "reactionThreshold" , 3 ) ;
59
96
await expect ( mockedSetOutput ) . toHaveBeenCalledWith ( "totalReactions" , 6 ) ;
60
97
await expect ( mockedSetOutput ) . toHaveBeenCalledWith ( "commentId" , "DC_kwDOKczwv84Abmrk" ) ;
98
+ await expect ( mockedSetOutput ) . toHaveBeenCalledWith ( "discussionId" , "D_kwDOKczwv84AV0aF" ) ;
99
+ await expect ( mockedSetOutput ) . toHaveBeenCalledWith ( "clientMutationId" , "1234" ) ;
61
100
} ) ;
62
101
63
102
test ( "Test if discussion is already answered" , async ( ) => {
0 commit comments