|
1 | 1 | import { afterEach } from "node:test"; |
2 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { add, Duration } from "../../shared/src/time.js"; |
4 | | -import { |
5 | | - createLogHook, |
6 | | - createRateLimitHook, |
7 | | - getCheckRuns, |
8 | | - getWorkflowRuns, |
9 | | - writeToActionsSummary, |
10 | | -} from "../src/github.js"; |
11 | | -import { createMockContext, createMockCore, createMockGithub, createMockLogger } from "./mocks.js"; |
| 4 | +import { createLogHook, createRateLimitHook, writeToActionsSummary } from "../src/github.js"; |
| 5 | +import { createMockCore, createMockLogger } from "./mocks.js"; |
12 | 6 |
|
13 | 7 | const mockCore = createMockCore(); |
14 | 8 |
|
15 | | -describe("getCheckRuns", () => { |
16 | | - it("returns matching check_run", async () => { |
17 | | - const githubMock = createMockGithub(); |
18 | | - githubMock.rest.checks.listForRef.mockResolvedValue({ |
19 | | - data: { |
20 | | - check_runs: [ |
21 | | - { |
22 | | - name: "checkRunName", |
23 | | - status: "completed", |
24 | | - conclusion: "success", |
25 | | - }, |
26 | | - ], |
27 | | - }, |
28 | | - }); |
29 | | - |
30 | | - const actual = await getCheckRuns(githubMock, createMockContext(), "checkRunName", "head_sha"); |
31 | | - |
32 | | - expect(actual).toEqual([ |
33 | | - expect.objectContaining({ |
34 | | - name: "checkRunName", |
35 | | - status: "completed", |
36 | | - conclusion: "success", |
37 | | - }), |
38 | | - ]); |
39 | | - }); |
40 | | - |
41 | | - it("returns null when no check matches", async () => { |
42 | | - const githubMock = createMockGithub(); |
43 | | - githubMock.rest.checks.listForRef.mockResolvedValue({ |
44 | | - data: { |
45 | | - check_runs: [], |
46 | | - }, |
47 | | - }); |
48 | | - |
49 | | - const actual = await getCheckRuns(githubMock, createMockContext(), "checkRunName", "head_sha"); |
50 | | - |
51 | | - expect(actual).toEqual([]); |
52 | | - }); |
53 | | - |
54 | | - it("throws when multiple checks match", async () => { |
55 | | - const githubMock = createMockGithub(); |
56 | | - const earlierDate = "2025-04-01T00:00:00Z"; |
57 | | - const laterDate = "2025-04-02T00:00:00Z"; |
58 | | - githubMock.rest.checks.listForRef.mockResolvedValue({ |
59 | | - data: { |
60 | | - check_runs: [ |
61 | | - { |
62 | | - name: "checkRunName", |
63 | | - status: "completed", |
64 | | - conclusion: "success", |
65 | | - completed_at: earlierDate, |
66 | | - }, |
67 | | - { |
68 | | - name: "checkRunName", |
69 | | - status: "completed", |
70 | | - conclusion: "success", |
71 | | - completed_at: laterDate, |
72 | | - }, |
73 | | - ], |
74 | | - }, |
75 | | - }); |
76 | | - |
77 | | - const actual = await getCheckRuns(githubMock, createMockContext(), "checkRunName", "head_sha"); |
78 | | - |
79 | | - expect(actual).toEqual([ |
80 | | - expect.objectContaining({ |
81 | | - name: "checkRunName", |
82 | | - status: "completed", |
83 | | - conclusion: "success", |
84 | | - completed_at: laterDate, |
85 | | - }), |
86 | | - expect.objectContaining({ |
87 | | - name: "checkRunName", |
88 | | - status: "completed", |
89 | | - conclusion: "success", |
90 | | - completed_at: earlierDate, |
91 | | - }), |
92 | | - ]); |
93 | | - }); |
94 | | -}); |
95 | | - |
96 | | -describe("getWorkflowRuns", () => { |
97 | | - it("returns matching workflow_run", async () => { |
98 | | - const githubMock = createMockGithub(); |
99 | | - githubMock.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({ |
100 | | - data: { |
101 | | - workflow_runs: [ |
102 | | - { |
103 | | - name: "workflowName", |
104 | | - status: "completed", |
105 | | - conclusion: "success", |
106 | | - }, |
107 | | - ], |
108 | | - }, |
109 | | - }); |
110 | | - |
111 | | - const actual = await getWorkflowRuns( |
112 | | - githubMock, |
113 | | - createMockContext(), |
114 | | - "workflowName", |
115 | | - "head_sha", |
116 | | - ); |
117 | | - |
118 | | - expect(actual).toEqual([ |
119 | | - expect.objectContaining({ |
120 | | - name: "workflowName", |
121 | | - status: "completed", |
122 | | - conclusion: "success", |
123 | | - }), |
124 | | - ]); |
125 | | - }); |
126 | | - |
127 | | - it("returns null when no workflow matches", async () => { |
128 | | - const githubMock = createMockGithub(); |
129 | | - githubMock.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({ |
130 | | - data: { |
131 | | - workflow_runs: [ |
132 | | - { |
133 | | - name: "otherWorkflowName", |
134 | | - }, |
135 | | - ], |
136 | | - }, |
137 | | - }); |
138 | | - |
139 | | - const actual = await getWorkflowRuns( |
140 | | - githubMock, |
141 | | - createMockContext(), |
142 | | - "workflowName", |
143 | | - "head_sha", |
144 | | - ); |
145 | | - |
146 | | - expect(actual).toEqual([]); |
147 | | - }); |
148 | | - |
149 | | - it("returns latest when multiple workflows match", async () => { |
150 | | - const githubMock = createMockGithub(); |
151 | | - const earlyDate = "2025-04-01T00:00:00Z"; |
152 | | - const laterDate = "2025-04-02T00:00:00Z"; |
153 | | - githubMock.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({ |
154 | | - data: { |
155 | | - workflow_runs: [ |
156 | | - { |
157 | | - name: "workflowName", |
158 | | - status: "completed", |
159 | | - conclusion: "success", |
160 | | - updated_at: earlyDate, |
161 | | - }, |
162 | | - { |
163 | | - name: "workflowName", |
164 | | - status: "completed", |
165 | | - conclusion: "success", |
166 | | - updated_at: laterDate, |
167 | | - }, |
168 | | - ], |
169 | | - }, |
170 | | - }); |
171 | | - |
172 | | - const actual = await getWorkflowRuns( |
173 | | - githubMock, |
174 | | - createMockContext(), |
175 | | - "workflowName", |
176 | | - "head_sha", |
177 | | - ); |
178 | | - |
179 | | - expect(actual).toEqual([ |
180 | | - expect.objectContaining({ |
181 | | - updated_at: laterDate, |
182 | | - }), |
183 | | - expect.objectContaining({ |
184 | | - updated_at: earlyDate, |
185 | | - }), |
186 | | - ]); |
187 | | - }); |
188 | | -}); |
189 | | - |
190 | 9 | describe("writeToActionsSummary function", () => { |
191 | 10 | it("should add content to the summary and write it", async () => { |
192 | 11 | // Call function |
|
0 commit comments