Skip to content

Commit 2d2a1fb

Browse files
committed
Add tests for variant analysis monitor
1 parent 5b9ed39 commit 2d2a1fb

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

extensions/ql-vscode/test/vscode-tests/activated-extension/variant-analysis/variant-analysis-monitor.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as ghApiClient from "../../../../src/variant-analysis/gh-api/gh-api-client";
2+
import { RequestError } from "@octokit/request-error";
23
import { VariantAnalysisMonitor } from "../../../../src/variant-analysis/variant-analysis-monitor";
34
import {
45
VariantAnalysis as VariantAnalysisApiResponse,
@@ -297,6 +298,55 @@ describe("Variant Analysis Monitor", () => {
297298
expect(mockEecuteCommand).not.toBeCalled();
298299
});
299300
});
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+
});
300350
});
301351

302352
function limitNumberOfAttemptsToMonitor() {

0 commit comments

Comments
 (0)