Merge pull request #1832 from github/koesie10/restructure-varianta-analysis-manager-tests
Restructure variant analysis manager tests
This commit is contained in:
@@ -41,6 +41,7 @@ import {
|
||||
VariantAnalysis,
|
||||
VariantAnalysisScannedRepository,
|
||||
VariantAnalysisScannedRepositoryDownloadStatus,
|
||||
VariantAnalysisScannedRepositoryState,
|
||||
VariantAnalysisStatus,
|
||||
} from "../../../remote-queries/shared/variant-analysis";
|
||||
import { createTimestampFile } from "../../../helpers";
|
||||
@@ -365,6 +366,7 @@ describe("Variant Analysis Manager", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("autoDownloadVariantAnalysisResult", () => {
|
||||
describe("when credentials are invalid", () => {
|
||||
beforeEach(async () => {
|
||||
jest
|
||||
@@ -402,7 +404,9 @@ describe("Variant Analysis Manager", () => {
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
jest
|
||||
.spyOn(Credentials, "initialize")
|
||||
.mockResolvedValue(mockCredentials);
|
||||
|
||||
const sourceFilePath = join(
|
||||
__dirname,
|
||||
@@ -450,7 +454,6 @@ describe("Variant Analysis Manager", () => {
|
||||
getVariantAnalysisRepoResultStub.mockResolvedValue(arrayBuffer);
|
||||
});
|
||||
|
||||
describe("autoDownloadVariantAnalysisResult", () => {
|
||||
it("should return early if variant analysis is cancelled", async () => {
|
||||
cancellationTokenSource.cancel();
|
||||
|
||||
@@ -626,14 +629,7 @@ describe("Variant Analysis Manager", () => {
|
||||
});
|
||||
|
||||
it("should update the repo state correctly", async () => {
|
||||
// To set some initial repo states, we need to mock the correct methods so that the repo states are read in.
|
||||
// The actual tests for these are in rehydrateVariantAnalysis, so we can just mock them here and test that
|
||||
// the methods are called.
|
||||
|
||||
pathExistsStub.mockImplementation(() => true);
|
||||
// This will read in the correct repo states
|
||||
readJsonStub.mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
mockRepoStates({
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
@@ -644,8 +640,7 @@ describe("Variant Analysis Manager", () => {
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.InProgress,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
await variantAnalysisManager.rehydrateVariantAnalysis(
|
||||
variantAnalysis,
|
||||
@@ -696,14 +691,33 @@ describe("Variant Analysis Manager", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
function mockRepoStates(
|
||||
repoStates: Record<number, VariantAnalysisScannedRepositoryState>,
|
||||
) {
|
||||
pathExistsStub.mockImplementation(() => true);
|
||||
// This will read in the correct repo states
|
||||
readJsonStub.mockImplementation(() => Promise.resolve(repoStates));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("enqueueDownload", () => {
|
||||
beforeEach(async () => {
|
||||
const mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
});
|
||||
|
||||
it("should pop download tasks off the queue", async () => {
|
||||
const getResultsSpy = jest.spyOn(
|
||||
variantAnalysisManager,
|
||||
"autoDownloadVariantAnalysisResult",
|
||||
);
|
||||
const getResultsSpy = jest
|
||||
.spyOn(variantAnalysisManager, "autoDownloadVariantAnalysisResult")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
await variantAnalysisManager.enqueueDownload(
|
||||
scannedRepos[0],
|
||||
@@ -740,9 +754,7 @@ describe("Variant Analysis Manager", () => {
|
||||
.spyOn(variantAnalysisResultsManager, "removeAnalysisResults")
|
||||
.mockReturnValue(undefined);
|
||||
|
||||
removeStorageStub = jest
|
||||
.spyOn(fs, "remove")
|
||||
.mockReturnValue(undefined);
|
||||
removeStorageStub = jest.spyOn(fs, "remove").mockReturnValue(undefined);
|
||||
});
|
||||
|
||||
it("should remove variant analysis", async () => {
|
||||
@@ -755,19 +767,15 @@ describe("Variant Analysis Manager", () => {
|
||||
);
|
||||
expect(variantAnalysisManager.variantAnalysesSize).toBe(1);
|
||||
|
||||
await variantAnalysisManager.removeVariantAnalysis(
|
||||
dummyVariantAnalysis,
|
||||
);
|
||||
await variantAnalysisManager.removeVariantAnalysis(dummyVariantAnalysis);
|
||||
|
||||
expect(removeAnalysisResultsStub).toBeCalledTimes(1);
|
||||
expect(removeStorageStub).toBeCalledTimes(1);
|
||||
expect(variantAnalysisManager.variantAnalysesSize).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when rehydrating a query", () => {
|
||||
describe("rehydrateVariantAnalysis", () => {
|
||||
let variantAnalysis: VariantAnalysis;
|
||||
const variantAnalysisRemovedSpy = jest.fn();
|
||||
let executeCommandSpy: jest.SpiedFunction<typeof commands.executeCommand>;
|
||||
|
||||
Reference in New Issue
Block a user