Remove places where we are checking if credentials are undefined
This cannot happen already, even before the other changes in this PR. The Credentials.initialize method can never return undefined, so these checks would never return true. The real place that checks that we are authenticated is in the vscode.authentication.getSession method, and it will reject the promise if the user declines to authenticate or anything else means we can't get an authenticated session. I feel justified in removing the tests for these cases because the code was never actually called in production, and we are covered by the vscode authentication library rejecting the promise. Any exception thrown from Credentials.initialize would behave the same as the one I'm deleting.
This commit is contained in:
@@ -27,10 +27,6 @@ export class RemoteQueriesMonitor {
|
||||
): Promise<RemoteQueryWorkflowResult> {
|
||||
const credentials = await Credentials.initialize(this.extensionContext);
|
||||
|
||||
if (!credentials) {
|
||||
throw Error("Error authenticating with GitHub");
|
||||
}
|
||||
|
||||
let attemptCount = 0;
|
||||
|
||||
while (attemptCount <= RemoteQueriesMonitor.maxAttemptCount) {
|
||||
|
||||
@@ -480,9 +480,6 @@ export class VariantAnalysisManager
|
||||
await this.onRepoStateUpdated(variantAnalysis.id, repoState);
|
||||
|
||||
const credentials = await Credentials.initialize(this.ctx);
|
||||
if (!credentials) {
|
||||
throw Error("Error authenticating with GitHub");
|
||||
}
|
||||
|
||||
if (cancellationToken && cancellationToken.isCancellationRequested) {
|
||||
repoState.downloadStatus =
|
||||
@@ -581,9 +578,6 @@ export class VariantAnalysisManager
|
||||
}
|
||||
|
||||
const credentials = await Credentials.initialize(this.ctx);
|
||||
if (!credentials) {
|
||||
throw Error("Error authenticating with GitHub");
|
||||
}
|
||||
|
||||
void showAndLogInformationMessage(
|
||||
"Cancelling variant analysis. This may take a while.",
|
||||
|
||||
@@ -45,9 +45,6 @@ export class VariantAnalysisMonitor extends DisposableObject {
|
||||
cancellationToken: CancellationToken,
|
||||
): Promise<void> {
|
||||
const credentials = await Credentials.initialize(this.extensionContext);
|
||||
if (!credentials) {
|
||||
throw Error("Error authenticating with GitHub");
|
||||
}
|
||||
|
||||
let attemptCount = 0;
|
||||
const scannedReposDownloaded: number[] = [];
|
||||
|
||||
@@ -142,6 +142,14 @@ describe("Variant Analysis Manager", () => {
|
||||
beforeEach(async () => {
|
||||
writeFileStub.mockRestore();
|
||||
|
||||
const mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
|
||||
// Should not have asked for a language
|
||||
showQuickPickSpy = jest
|
||||
.spyOn(window, "showQuickPick")
|
||||
@@ -367,269 +375,267 @@ describe("Variant Analysis Manager", () => {
|
||||
});
|
||||
|
||||
describe("autoDownloadVariantAnalysisResult", () => {
|
||||
describe("when credentials are invalid", () => {
|
||||
let arrayBuffer: ArrayBuffer;
|
||||
|
||||
let getVariantAnalysisRepoStub: jest.SpiedFunction<
|
||||
typeof ghApiClient.getVariantAnalysisRepo
|
||||
>;
|
||||
let getVariantAnalysisRepoResultStub: jest.SpiedFunction<
|
||||
typeof ghApiClient.getVariantAnalysisRepoResult
|
||||
>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
|
||||
const sourceFilePath = join(
|
||||
__dirname,
|
||||
"../../../../src/vscode-tests/cli-integration/data/variant-analysis-results.zip",
|
||||
);
|
||||
arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
|
||||
|
||||
getVariantAnalysisRepoStub = jest.spyOn(
|
||||
ghApiClient,
|
||||
"getVariantAnalysisRepo",
|
||||
);
|
||||
getVariantAnalysisRepoResultStub = jest.spyOn(
|
||||
ghApiClient,
|
||||
"getVariantAnalysisRepoResult",
|
||||
);
|
||||
});
|
||||
|
||||
describe("when the artifact_url is missing", () => {
|
||||
beforeEach(async () => {
|
||||
jest
|
||||
.spyOn(Credentials, "initialize")
|
||||
.mockResolvedValue(undefined as unknown as Credentials);
|
||||
const dummyRepoTask = createMockVariantAnalysisRepoTask();
|
||||
delete dummyRepoTask.artifact_url;
|
||||
|
||||
getVariantAnalysisRepoStub.mockResolvedValue(dummyRepoTask);
|
||||
getVariantAnalysisRepoResultStub.mockResolvedValue(arrayBuffer);
|
||||
});
|
||||
|
||||
it("should return early if credentials are wrong", async () => {
|
||||
try {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
} catch (error: any) {
|
||||
expect(error.message).toBe("Error authenticating with GitHub");
|
||||
}
|
||||
it("should not try to download the result", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(getVariantAnalysisRepoResultStub).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when credentials are valid", () => {
|
||||
let arrayBuffer: ArrayBuffer;
|
||||
|
||||
let getVariantAnalysisRepoStub: jest.SpiedFunction<
|
||||
typeof ghApiClient.getVariantAnalysisRepo
|
||||
>;
|
||||
let getVariantAnalysisRepoResultStub: jest.SpiedFunction<
|
||||
typeof ghApiClient.getVariantAnalysisRepoResult
|
||||
>;
|
||||
describe("when the artifact_url is present", () => {
|
||||
let dummyRepoTask: VariantAnalysisRepoTask;
|
||||
|
||||
beforeEach(async () => {
|
||||
const mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest
|
||||
.spyOn(Credentials, "initialize")
|
||||
.mockResolvedValue(mockCredentials);
|
||||
dummyRepoTask = createMockVariantAnalysisRepoTask();
|
||||
|
||||
const sourceFilePath = join(
|
||||
__dirname,
|
||||
"../../../../src/vscode-tests/cli-integration/data/variant-analysis-results.zip",
|
||||
);
|
||||
arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
|
||||
getVariantAnalysisRepoStub.mockResolvedValue(dummyRepoTask);
|
||||
getVariantAnalysisRepoResultStub.mockResolvedValue(arrayBuffer);
|
||||
});
|
||||
|
||||
getVariantAnalysisRepoStub = jest.spyOn(
|
||||
ghApiClient,
|
||||
"getVariantAnalysisRepo",
|
||||
it("should return early if variant analysis is cancelled", async () => {
|
||||
cancellationTokenSource.cancel();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
getVariantAnalysisRepoResultStub = jest.spyOn(
|
||||
ghApiClient,
|
||||
"getVariantAnalysisRepoResult",
|
||||
|
||||
expect(getVariantAnalysisRepoStub).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should fetch a repo task", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(getVariantAnalysisRepoStub).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should fetch a repo result", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(getVariantAnalysisRepoResultStub).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should skip the download if the repository has already been downloaded", async () => {
|
||||
// First, do a download so it is downloaded. This avoids having to mock the repo states.
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
getVariantAnalysisRepoStub.mockClear();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(getVariantAnalysisRepoStub).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should write the repo state when the download is successful", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(storagePath, variantAnalysis.id.toString(), "repo_states.json"),
|
||||
{
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("when the artifact_url is missing", () => {
|
||||
beforeEach(async () => {
|
||||
const dummyRepoTask = createMockVariantAnalysisRepoTask();
|
||||
delete dummyRepoTask.artifact_url;
|
||||
it("should not write the repo state when the download fails", async () => {
|
||||
getVariantAnalysisRepoResultStub.mockRejectedValue(
|
||||
new Error("Failed to download"),
|
||||
);
|
||||
|
||||
getVariantAnalysisRepoStub.mockResolvedValue(dummyRepoTask);
|
||||
getVariantAnalysisRepoResultStub.mockResolvedValue(arrayBuffer);
|
||||
});
|
||||
|
||||
it("should not try to download the result", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
await expect(
|
||||
variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
),
|
||||
).rejects.toThrow();
|
||||
|
||||
expect(getVariantAnalysisRepoResultStub).not.toHaveBeenCalled();
|
||||
});
|
||||
expect(outputJsonStub).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("when the artifact_url is present", () => {
|
||||
let dummyRepoTask: VariantAnalysisRepoTask;
|
||||
it("should have a failed repo state when the repo task API fails", async () => {
|
||||
getVariantAnalysisRepoStub.mockRejectedValueOnce(
|
||||
new Error("Failed to download"),
|
||||
);
|
||||
|
||||
beforeEach(async () => {
|
||||
dummyRepoTask = createMockVariantAnalysisRepoTask();
|
||||
|
||||
getVariantAnalysisRepoStub.mockResolvedValue(dummyRepoTask);
|
||||
getVariantAnalysisRepoResultStub.mockResolvedValue(arrayBuffer);
|
||||
});
|
||||
|
||||
it("should return early if variant analysis is cancelled", async () => {
|
||||
cancellationTokenSource.cancel();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
await expect(
|
||||
variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
),
|
||||
).rejects.toThrow();
|
||||
|
||||
expect(getVariantAnalysisRepoStub).not.toHaveBeenCalled();
|
||||
});
|
||||
expect(outputJsonStub).not.toHaveBeenCalled();
|
||||
|
||||
it("should fetch a repo task", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[1],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(getVariantAnalysisRepoStub).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should fetch a repo result", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(getVariantAnalysisRepoResultStub).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should skip the download if the repository has already been downloaded", async () => {
|
||||
// First, do a download so it is downloaded. This avoids having to mock the repo states.
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
getVariantAnalysisRepoStub.mockClear();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(getVariantAnalysisRepoStub).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should write the repo state when the download is successful", async () => {
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(
|
||||
storagePath,
|
||||
variantAnalysis.id.toString(),
|
||||
"repo_states.json",
|
||||
),
|
||||
{
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(storagePath, variantAnalysis.id.toString(), "repo_states.json"),
|
||||
{
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Failed,
|
||||
},
|
||||
);
|
||||
});
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("should not write the repo state when the download fails", async () => {
|
||||
getVariantAnalysisRepoResultStub.mockRejectedValue(
|
||||
new Error("Failed to download"),
|
||||
);
|
||||
it("should have a failed repo state when the download fails", async () => {
|
||||
getVariantAnalysisRepoResultStub.mockRejectedValueOnce(
|
||||
new Error("Failed to download"),
|
||||
);
|
||||
|
||||
await expect(
|
||||
variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
),
|
||||
).rejects.toThrow();
|
||||
|
||||
expect(outputJsonStub).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should have a failed repo state when the repo task API fails", async () => {
|
||||
getVariantAnalysisRepoStub.mockRejectedValueOnce(
|
||||
new Error("Failed to download"),
|
||||
);
|
||||
|
||||
await expect(
|
||||
variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
),
|
||||
).rejects.toThrow();
|
||||
|
||||
expect(outputJsonStub).not.toHaveBeenCalled();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[1],
|
||||
await expect(
|
||||
variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
),
|
||||
).rejects.toThrow();
|
||||
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(
|
||||
storagePath,
|
||||
variantAnalysis.id.toString(),
|
||||
"repo_states.json",
|
||||
),
|
||||
{
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Failed,
|
||||
},
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
expect(outputJsonStub).not.toHaveBeenCalled();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[1],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(storagePath, variantAnalysis.id.toString(), "repo_states.json"),
|
||||
{
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Failed,
|
||||
},
|
||||
);
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("should update the repo state correctly", async () => {
|
||||
mockRepoStates({
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
[scannedRepos[2].repository.id]: {
|
||||
repositoryId: scannedRepos[2].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.InProgress,
|
||||
},
|
||||
});
|
||||
|
||||
it("should have a failed repo state when the download fails", async () => {
|
||||
getVariantAnalysisRepoResultStub.mockRejectedValueOnce(
|
||||
new Error("Failed to download"),
|
||||
);
|
||||
await variantAnalysisManager.rehydrateVariantAnalysis(variantAnalysis);
|
||||
|
||||
await expect(
|
||||
variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
),
|
||||
).rejects.toThrow();
|
||||
expect(pathExistsStub).toBeCalledWith(
|
||||
join(storagePath, variantAnalysis.id.toString()),
|
||||
);
|
||||
expect(readJsonStub).toHaveBeenCalledTimes(1);
|
||||
expect(readJsonStub).toHaveBeenCalledWith(
|
||||
join(storagePath, variantAnalysis.id.toString(), "repo_states.json"),
|
||||
);
|
||||
|
||||
expect(outputJsonStub).not.toHaveBeenCalled();
|
||||
pathExistsStub.mockRestore();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[1],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(
|
||||
storagePath,
|
||||
variantAnalysis.id.toString(),
|
||||
"repo_states.json",
|
||||
),
|
||||
{
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Failed,
|
||||
},
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("should update the repo state correctly", async () => {
|
||||
mockRepoStates({
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(storagePath, variantAnalysis.id.toString(), "repo_states.json"),
|
||||
{
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
@@ -640,66 +646,22 @@ describe("Variant Analysis Manager", () => {
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.InProgress,
|
||||
},
|
||||
});
|
||||
|
||||
await variantAnalysisManager.rehydrateVariantAnalysis(
|
||||
variantAnalysis,
|
||||
);
|
||||
|
||||
expect(pathExistsStub).toBeCalledWith(
|
||||
join(storagePath, variantAnalysis.id.toString()),
|
||||
);
|
||||
expect(readJsonStub).toHaveBeenCalledTimes(1);
|
||||
expect(readJsonStub).toHaveBeenCalledWith(
|
||||
join(
|
||||
storagePath,
|
||||
variantAnalysis.id.toString(),
|
||||
"repo_states.json",
|
||||
),
|
||||
);
|
||||
|
||||
pathExistsStub.mockRestore();
|
||||
|
||||
await variantAnalysisManager.autoDownloadVariantAnalysisResult(
|
||||
scannedRepos[0],
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(outputJsonStub).toHaveBeenCalledWith(
|
||||
join(
|
||||
storagePath,
|
||||
variantAnalysis.id.toString(),
|
||||
"repo_states.json",
|
||||
),
|
||||
{
|
||||
[scannedRepos[1].repository.id]: {
|
||||
repositoryId: scannedRepos[1].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
[scannedRepos[2].repository.id]: {
|
||||
repositoryId: scannedRepos[2].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.InProgress,
|
||||
},
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
[scannedRepos[0].repository.id]: {
|
||||
repositoryId: scannedRepos[0].repository.id,
|
||||
downloadStatus:
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Succeeded,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
function mockRepoStates(
|
||||
repoStates: Record<number, VariantAnalysisScannedRepositoryState>,
|
||||
) {
|
||||
pathExistsStub.mockImplementation(() => true);
|
||||
// This will read in the correct repo states
|
||||
readJsonStub.mockImplementation(() => Promise.resolve(repoStates));
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
function mockRepoStates(
|
||||
repoStates: Record<number, VariantAnalysisScannedRepositoryState>,
|
||||
) {
|
||||
pathExistsStub.mockImplementation(() => true);
|
||||
// This will read in the correct repo states
|
||||
readJsonStub.mockImplementation(() => Promise.resolve(repoStates));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -876,6 +838,8 @@ describe("Variant Analysis Manager", () => {
|
||||
|
||||
let variantAnalysisStorageLocation: string;
|
||||
|
||||
let mockCredentials: Credentials;
|
||||
|
||||
beforeEach(async () => {
|
||||
variantAnalysis = createMockVariantAnalysis({});
|
||||
|
||||
@@ -889,82 +853,54 @@ describe("Variant Analysis Manager", () => {
|
||||
);
|
||||
await createTimestampFile(variantAnalysisStorageLocation);
|
||||
await variantAnalysisManager.rehydrateVariantAnalysis(variantAnalysis);
|
||||
|
||||
mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(variantAnalysisStorageLocation, { recursive: true });
|
||||
});
|
||||
|
||||
describe("when the credentials are invalid", () => {
|
||||
beforeEach(async () => {
|
||||
jest
|
||||
.spyOn(Credentials, "initialize")
|
||||
.mockResolvedValue(undefined as unknown as Credentials);
|
||||
});
|
||||
|
||||
it("should return early", async () => {
|
||||
try {
|
||||
await variantAnalysisManager.cancelVariantAnalysis(
|
||||
variantAnalysis.id,
|
||||
);
|
||||
} catch (error: any) {
|
||||
expect(error.message).toBe("Error authenticating with GitHub");
|
||||
}
|
||||
});
|
||||
it("should return early if the variant analysis is not found", async () => {
|
||||
try {
|
||||
await variantAnalysisManager.cancelVariantAnalysis(
|
||||
variantAnalysis.id + 100,
|
||||
);
|
||||
} catch (error: any) {
|
||||
expect(error.message).toBe(
|
||||
`No variant analysis with id: ${variantAnalysis.id + 100}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
describe("when the credentials are valid", () => {
|
||||
let mockCredentials: Credentials;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest
|
||||
.spyOn(Credentials, "initialize")
|
||||
.mockResolvedValue(mockCredentials);
|
||||
it("should return early if the variant analysis does not have an actions workflow run id", async () => {
|
||||
await variantAnalysisManager.onVariantAnalysisUpdated({
|
||||
...variantAnalysis,
|
||||
actionsWorkflowRunId: undefined,
|
||||
});
|
||||
|
||||
it("should return early if the variant analysis is not found", async () => {
|
||||
try {
|
||||
await variantAnalysisManager.cancelVariantAnalysis(
|
||||
variantAnalysis.id + 100,
|
||||
);
|
||||
} catch (error: any) {
|
||||
expect(error.message).toBe(
|
||||
`No variant analysis with id: ${variantAnalysis.id + 100}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("should return early if the variant analysis does not have an actions workflow run id", async () => {
|
||||
await variantAnalysisManager.onVariantAnalysisUpdated({
|
||||
...variantAnalysis,
|
||||
actionsWorkflowRunId: undefined,
|
||||
});
|
||||
|
||||
try {
|
||||
await variantAnalysisManager.cancelVariantAnalysis(
|
||||
variantAnalysis.id,
|
||||
);
|
||||
} catch (error: any) {
|
||||
expect(error.message).toBe(
|
||||
`No workflow run id for variant analysis with id: ${variantAnalysis.id}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("should return cancel if valid", async () => {
|
||||
try {
|
||||
await variantAnalysisManager.cancelVariantAnalysis(variantAnalysis.id);
|
||||
|
||||
expect(mockCancelVariantAnalysis).toBeCalledWith(
|
||||
mockCredentials,
|
||||
variantAnalysis,
|
||||
} catch (error: any) {
|
||||
expect(error.message).toBe(
|
||||
`No workflow run id for variant analysis with id: ${variantAnalysis.id}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("should return cancel if valid", async () => {
|
||||
await variantAnalysisManager.cancelVariantAnalysis(variantAnalysis.id);
|
||||
|
||||
expect(mockCancelVariantAnalysis).toBeCalledWith(
|
||||
mockCredentials,
|
||||
variantAnalysis,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -77,260 +77,237 @@ describe("Variant Analysis Monitor", () => {
|
||||
.mockRejectedValue(new Error("Not mocked"));
|
||||
|
||||
limitNumberOfAttemptsToMonitor();
|
||||
|
||||
const mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
});
|
||||
|
||||
describe("when credentials are invalid", () => {
|
||||
it("should return early if variant analysis is cancelled", async () => {
|
||||
cancellationTokenSource.cancel();
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(onVariantAnalysisChangeSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should return early if variant analysis should be cancelled", async () => {
|
||||
shouldCancelMonitor.mockResolvedValue(true);
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(onVariantAnalysisChangeSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("when the variant analysis fails", () => {
|
||||
let mockFailedApiResponse: VariantAnalysisApiResponse;
|
||||
|
||||
beforeEach(async () => {
|
||||
jest
|
||||
.spyOn(Credentials, "initialize")
|
||||
.mockResolvedValue(undefined as unknown as Credentials);
|
||||
mockFailedApiResponse = createFailedMockApiResponse();
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockFailedApiResponse);
|
||||
});
|
||||
|
||||
it("should return early if credentials are wrong", async () => {
|
||||
try {
|
||||
it("should mark as failed and stop monitoring", async () => {
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetVariantAnalysis).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(onVariantAnalysisChangeSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
status: VariantAnalysisStatus.Failed,
|
||||
failureReason: processFailureReason(
|
||||
mockFailedApiResponse.failure_reason as VariantAnalysisFailureReason,
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the variant analysis is in progress", () => {
|
||||
let mockApiResponse: VariantAnalysisApiResponse;
|
||||
let scannedRepos: ApiVariantAnalysisScannedRepository[];
|
||||
let succeededRepos: ApiVariantAnalysisScannedRepository[];
|
||||
|
||||
describe("when there are successfully scanned repos", () => {
|
||||
beforeEach(async () => {
|
||||
scannedRepos = createMockScannedRepos([
|
||||
"pending",
|
||||
"pending",
|
||||
"in_progress",
|
||||
"in_progress",
|
||||
"succeeded",
|
||||
"succeeded",
|
||||
"succeeded",
|
||||
]);
|
||||
mockApiResponse = createMockApiResponse("succeeded", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockApiResponse);
|
||||
succeededRepos = scannedRepos.filter(
|
||||
(r) => r.analysis_status === "succeeded",
|
||||
);
|
||||
});
|
||||
|
||||
it("should trigger a download extension command for each repo", async () => {
|
||||
const succeededRepos = scannedRepos.filter(
|
||||
(r) => r.analysis_status === "succeeded",
|
||||
);
|
||||
const commandSpy = jest
|
||||
.spyOn(commands, "executeCommand")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
} catch (error: any) {
|
||||
expect(error.message).toBe("Error authenticating with GitHub");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("when credentials are valid", () => {
|
||||
beforeEach(async () => {
|
||||
const mockCredentials = {
|
||||
getOctokit: () =>
|
||||
Promise.resolve({
|
||||
request: jest.fn(),
|
||||
}),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
expect(commandSpy).toBeCalledTimes(succeededRepos.length);
|
||||
|
||||
succeededRepos.forEach((succeededRepo, index) => {
|
||||
expect(commandSpy).toHaveBeenNthCalledWith(
|
||||
index + 1,
|
||||
"codeQL.autoDownloadVariantAnalysisResult",
|
||||
processScannedRepository(succeededRepo),
|
||||
processUpdatedVariantAnalysis(variantAnalysis, mockApiResponse),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("should download all available results", async () => {
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetDownloadResult).toBeCalledTimes(succeededRepos.length);
|
||||
|
||||
succeededRepos.forEach((succeededRepo, index) => {
|
||||
expect(mockGetDownloadResult).toHaveBeenNthCalledWith(
|
||||
index + 1,
|
||||
processScannedRepository(succeededRepo),
|
||||
processUpdatedVariantAnalysis(variantAnalysis, mockApiResponse),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should return early if variant analysis is cancelled", async () => {
|
||||
cancellationTokenSource.cancel();
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(onVariantAnalysisChangeSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should return early if variant analysis should be cancelled", async () => {
|
||||
shouldCancelMonitor.mockResolvedValue(true);
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(onVariantAnalysisChangeSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("when the variant analysis fails", () => {
|
||||
let mockFailedApiResponse: VariantAnalysisApiResponse;
|
||||
describe("when there are only in progress repos", () => {
|
||||
let scannedRepos: ApiVariantAnalysisScannedRepository[];
|
||||
|
||||
beforeEach(async () => {
|
||||
mockFailedApiResponse = createFailedMockApiResponse();
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockFailedApiResponse);
|
||||
scannedRepos = createMockScannedRepos(["pending", "in_progress"]);
|
||||
mockApiResponse = createMockApiResponse("in_progress", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockApiResponse);
|
||||
});
|
||||
|
||||
it("should mark as failed and stop monitoring", async () => {
|
||||
it("should succeed and not download any repos via a command", async () => {
|
||||
const commandSpy = jest
|
||||
.spyOn(commands, "executeCommand")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetVariantAnalysis).toHaveBeenCalledTimes(1);
|
||||
expect(commandSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
expect(onVariantAnalysisChangeSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
status: VariantAnalysisStatus.Failed,
|
||||
failureReason: processFailureReason(
|
||||
mockFailedApiResponse.failure_reason as VariantAnalysisFailureReason,
|
||||
),
|
||||
}),
|
||||
it("should not try to download any repos", async () => {
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetDownloadResult).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the variant analysis is in progress", () => {
|
||||
let mockApiResponse: VariantAnalysisApiResponse;
|
||||
describe("when the responses change", () => {
|
||||
let scannedRepos: ApiVariantAnalysisScannedRepository[];
|
||||
let succeededRepos: ApiVariantAnalysisScannedRepository[];
|
||||
|
||||
describe("when there are successfully scanned repos", () => {
|
||||
beforeEach(async () => {
|
||||
scannedRepos = createMockScannedRepos([
|
||||
"pending",
|
||||
"pending",
|
||||
"in_progress",
|
||||
"in_progress",
|
||||
"succeeded",
|
||||
"succeeded",
|
||||
"succeeded",
|
||||
]);
|
||||
mockApiResponse = createMockApiResponse("succeeded", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockApiResponse);
|
||||
succeededRepos = scannedRepos.filter(
|
||||
(r) => r.analysis_status === "succeeded",
|
||||
);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
scannedRepos = createMockScannedRepos([
|
||||
"pending",
|
||||
"in_progress",
|
||||
"in_progress",
|
||||
"in_progress",
|
||||
"pending",
|
||||
"pending",
|
||||
]);
|
||||
mockApiResponse = createMockApiResponse("in_progress", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(mockApiResponse);
|
||||
|
||||
it("should trigger a download extension command for each repo", async () => {
|
||||
const succeededRepos = scannedRepos.filter(
|
||||
(r) => r.analysis_status === "succeeded",
|
||||
);
|
||||
const commandSpy = jest
|
||||
.spyOn(commands, "executeCommand")
|
||||
.mockResolvedValue(undefined);
|
||||
let nextApiResponse = {
|
||||
...mockApiResponse,
|
||||
scanned_repositories: [...scannedRepos.map((r) => ({ ...r }))],
|
||||
};
|
||||
nextApiResponse.scanned_repositories[0].analysis_status = "succeeded";
|
||||
nextApiResponse.scanned_repositories[1].analysis_status = "succeeded";
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(nextApiResponse);
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
nextApiResponse = {
|
||||
...mockApiResponse,
|
||||
scanned_repositories: [
|
||||
...nextApiResponse.scanned_repositories.map((r) => ({ ...r })),
|
||||
],
|
||||
};
|
||||
nextApiResponse.scanned_repositories[2].analysis_status = "succeeded";
|
||||
nextApiResponse.scanned_repositories[5].analysis_status = "succeeded";
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(nextApiResponse);
|
||||
|
||||
expect(commandSpy).toBeCalledTimes(succeededRepos.length);
|
||||
|
||||
succeededRepos.forEach((succeededRepo, index) => {
|
||||
expect(commandSpy).toHaveBeenNthCalledWith(
|
||||
index + 1,
|
||||
"codeQL.autoDownloadVariantAnalysisResult",
|
||||
processScannedRepository(succeededRepo),
|
||||
processUpdatedVariantAnalysis(variantAnalysis, mockApiResponse),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("should download all available results", async () => {
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetDownloadResult).toBeCalledTimes(succeededRepos.length);
|
||||
|
||||
succeededRepos.forEach((succeededRepo, index) => {
|
||||
expect(mockGetDownloadResult).toHaveBeenNthCalledWith(
|
||||
index + 1,
|
||||
processScannedRepository(succeededRepo),
|
||||
processUpdatedVariantAnalysis(variantAnalysis, mockApiResponse),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
nextApiResponse = {
|
||||
...mockApiResponse,
|
||||
scanned_repositories: [
|
||||
...nextApiResponse.scanned_repositories.map((r) => ({ ...r })),
|
||||
],
|
||||
};
|
||||
nextApiResponse.scanned_repositories[3].analysis_status = "succeeded";
|
||||
nextApiResponse.scanned_repositories[4].analysis_status = "failed";
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(nextApiResponse);
|
||||
});
|
||||
|
||||
describe("when there are only in progress repos", () => {
|
||||
let scannedRepos: ApiVariantAnalysisScannedRepository[];
|
||||
it("should trigger a download extension command for each repo", async () => {
|
||||
const commandSpy = jest
|
||||
.spyOn(commands, "executeCommand")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
beforeEach(async () => {
|
||||
scannedRepos = createMockScannedRepos(["pending", "in_progress"]);
|
||||
mockApiResponse = createMockApiResponse("in_progress", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockApiResponse);
|
||||
});
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
it("should succeed and not download any repos via a command", async () => {
|
||||
const commandSpy = jest
|
||||
.spyOn(commands, "executeCommand")
|
||||
.mockResolvedValue(undefined);
|
||||
expect(mockGetVariantAnalysis).toBeCalledTimes(4);
|
||||
expect(commandSpy).toBeCalledTimes(5);
|
||||
});
|
||||
});
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(commandSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not try to download any repos", async () => {
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetDownloadResult).not.toBeCalled();
|
||||
});
|
||||
describe("when there are no repos to scan", () => {
|
||||
beforeEach(async () => {
|
||||
scannedRepos = [];
|
||||
mockApiResponse = createMockApiResponse("succeeded", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockApiResponse);
|
||||
});
|
||||
|
||||
describe("when the responses change", () => {
|
||||
let scannedRepos: ApiVariantAnalysisScannedRepository[];
|
||||
it("should not try to download any repos", async () => {
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
beforeEach(async () => {
|
||||
scannedRepos = createMockScannedRepos([
|
||||
"pending",
|
||||
"in_progress",
|
||||
"in_progress",
|
||||
"in_progress",
|
||||
"pending",
|
||||
"pending",
|
||||
]);
|
||||
mockApiResponse = createMockApiResponse("in_progress", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(mockApiResponse);
|
||||
|
||||
let nextApiResponse = {
|
||||
...mockApiResponse,
|
||||
scanned_repositories: [...scannedRepos.map((r) => ({ ...r }))],
|
||||
};
|
||||
nextApiResponse.scanned_repositories[0].analysis_status = "succeeded";
|
||||
nextApiResponse.scanned_repositories[1].analysis_status = "succeeded";
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(nextApiResponse);
|
||||
|
||||
nextApiResponse = {
|
||||
...mockApiResponse,
|
||||
scanned_repositories: [
|
||||
...nextApiResponse.scanned_repositories.map((r) => ({ ...r })),
|
||||
],
|
||||
};
|
||||
nextApiResponse.scanned_repositories[2].analysis_status = "succeeded";
|
||||
nextApiResponse.scanned_repositories[5].analysis_status = "succeeded";
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(nextApiResponse);
|
||||
|
||||
nextApiResponse = {
|
||||
...mockApiResponse,
|
||||
scanned_repositories: [
|
||||
...nextApiResponse.scanned_repositories.map((r) => ({ ...r })),
|
||||
],
|
||||
};
|
||||
nextApiResponse.scanned_repositories[3].analysis_status = "succeeded";
|
||||
nextApiResponse.scanned_repositories[4].analysis_status = "failed";
|
||||
mockGetVariantAnalysis.mockResolvedValueOnce(nextApiResponse);
|
||||
});
|
||||
|
||||
it("should trigger a download extension command for each repo", async () => {
|
||||
const commandSpy = jest
|
||||
.spyOn(commands, "executeCommand")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetVariantAnalysis).toBeCalledTimes(4);
|
||||
expect(commandSpy).toBeCalledTimes(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there are no repos to scan", () => {
|
||||
beforeEach(async () => {
|
||||
scannedRepos = [];
|
||||
mockApiResponse = createMockApiResponse("succeeded", scannedRepos);
|
||||
mockGetVariantAnalysis.mockResolvedValue(mockApiResponse);
|
||||
});
|
||||
|
||||
it("should not try to download any repos", async () => {
|
||||
await variantAnalysisMonitor.monitorVariantAnalysis(
|
||||
variantAnalysis,
|
||||
cancellationTokenSource.token,
|
||||
);
|
||||
|
||||
expect(mockGetDownloadResult).not.toBeCalled();
|
||||
});
|
||||
expect(mockGetDownloadResult).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user