|
1 | 1 | import * as ghApiClient from "../../../../src/variant-analysis/gh-api/gh-api-client"; |
| 2 | +import { RequestError } from "@octokit/request-error"; |
2 | 3 | import { VariantAnalysisMonitor } from "../../../../src/variant-analysis/variant-analysis-monitor"; |
3 | 4 | import { |
4 | 5 | VariantAnalysis as VariantAnalysisApiResponse, |
@@ -297,6 +298,55 @@ describe("Variant Analysis Monitor", () => { |
297 | 298 | expect(mockEecuteCommand).not.toBeCalled(); |
298 | 299 | }); |
299 | 300 | }); |
| 301 | + |
| 302 | + describe("when a 404 is returned", () => { |
| 303 | + let showAndLogWarningMessageSpy: jest.SpiedFunction< |
| 304 | + typeof helpers.showAndLogWarningMessage |
| 305 | + >; |
| 306 | + |
| 307 | + beforeEach(async () => { |
| 308 | + showAndLogWarningMessageSpy = jest |
| 309 | + .spyOn(helpers, "showAndLogWarningMessage") |
| 310 | + .mockResolvedValue(undefined); |
| 311 | + |
| 312 | + const scannedRepos = createMockScannedRepos([ |
| 313 | + "pending", |
| 314 | + "in_progress", |
| 315 | + "in_progress", |
| 316 | + "in_progress", |
| 317 | + "pending", |
| 318 | + "pending", |
| 319 | + ]); |
| 320 | + mockApiResponse = createMockApiResponse("in_progress", scannedRepos); |
| 321 | + mockGetVariantAnalysis.mockResolvedValueOnce(mockApiResponse); |
| 322 | + |
| 323 | + mockGetVariantAnalysis.mockRejectedValueOnce( |
| 324 | + new RequestError("Not Found", 404, { |
| 325 | + request: { |
| 326 | + method: "GET", |
| 327 | + url: "", |
| 328 | + headers: {}, |
| 329 | + }, |
| 330 | + response: { |
| 331 | + status: 404, |
| 332 | + headers: {}, |
| 333 | + url: "", |
| 334 | + data: {}, |
| 335 | + }, |
| 336 | + }), |
| 337 | + ); |
| 338 | + }); |
| 339 | + |
| 340 | + it("should stop requesting the variant analysis", async () => { |
| 341 | + await variantAnalysisMonitor.monitorVariantAnalysis(variantAnalysis); |
| 342 | + |
| 343 | + expect(mockGetVariantAnalysis).toHaveBeenCalledTimes(2); |
| 344 | + expect(showAndLogWarningMessageSpy).toHaveBeenCalledTimes(1); |
| 345 | + expect(showAndLogWarningMessageSpy).toHaveBeenCalledWith( |
| 346 | + expect.stringMatching(/not found/i), |
| 347 | + ); |
| 348 | + }); |
| 349 | + }); |
300 | 350 | }); |
301 | 351 |
|
302 | 352 | function limitNumberOfAttemptsToMonitor() { |
|
0 commit comments