Skip to content

Commit 0ae7bb8

Browse files
committed
Extract mocking of repo states into method
1 parent ba419dd commit 0ae7bb8

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/variant-analysis-manager.test.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
VariantAnalysis,
3939
VariantAnalysisScannedRepository,
4040
VariantAnalysisScannedRepositoryDownloadStatus,
41+
VariantAnalysisScannedRepositoryState,
4142
VariantAnalysisStatus,
4243
} from "../../../remote-queries/shared/variant-analysis";
4344
import { createTimestampFile } from "../../../helpers";
@@ -622,26 +623,18 @@ describe("Variant Analysis Manager", () => {
622623
});
623624

624625
it("should update the repo state correctly", async () => {
625-
// To set some initial repo states, we need to mock the correct methods so that the repo states are read in.
626-
// The actual tests for these are in rehydrateVariantAnalysis, so we can just mock them here and test that
627-
// the methods are called.
628-
629-
pathExistsStub.mockImplementation(() => true);
630-
// This will read in the correct repo states
631-
readJsonStub.mockImplementation(() =>
632-
Promise.resolve({
633-
[scannedRepos[1].repository.id]: {
634-
repositoryId: scannedRepos[1].repository.id,
635-
downloadStatus:
636-
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
637-
},
638-
[scannedRepos[2].repository.id]: {
639-
repositoryId: scannedRepos[2].repository.id,
640-
downloadStatus:
641-
VariantAnalysisScannedRepositoryDownloadStatus.InProgress,
642-
},
643-
}),
644-
);
626+
mockRepoStates({
627+
[scannedRepos[1].repository.id]: {
628+
repositoryId: scannedRepos[1].repository.id,
629+
downloadStatus:
630+
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
631+
},
632+
[scannedRepos[2].repository.id]: {
633+
repositoryId: scannedRepos[2].repository.id,
634+
downloadStatus:
635+
VariantAnalysisScannedRepositoryDownloadStatus.InProgress,
636+
},
637+
});
645638

646639
await variantAnalysisManager.rehydrateVariantAnalysis(
647640
variantAnalysis,
@@ -692,6 +685,14 @@ describe("Variant Analysis Manager", () => {
692685
},
693686
);
694687
});
688+
689+
function mockRepoStates(
690+
repoStates: Record<number, VariantAnalysisScannedRepositoryState>,
691+
) {
692+
pathExistsStub.mockImplementation(() => true);
693+
// This will read in the correct repo states
694+
readJsonStub.mockImplementation(() => Promise.resolve(repoStates));
695+
}
695696
});
696697
});
697698
});

0 commit comments

Comments
 (0)