-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathvariant-analysis-submission-integration.test.ts
More file actions
135 lines (111 loc) · 4.2 KB
/
variant-analysis-submission-integration.test.ts
File metadata and controls
135 lines (111 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { resolve } from "path";
import type { TextDocument } from "vscode";
import { authentication, commands, window, workspace } from "vscode";
import { MockGitHubApiServer } from "../../../../src/common/mock-gh-api/mock-gh-api-server";
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
import { setRemoteControllerRepo } from "../../../../src/config";
import { getActivatedExtension } from "../../global.helper";
import { createVSCodeCommandManager } from "../../../../src/common/vscode/commands";
import type { AllCommands } from "../../../../src/common/commands";
const mockServer = new MockGitHubApiServer();
beforeAll(() => mockServer.startServer("bypass"));
afterEach(() => mockServer.unloadScenario());
afterAll(() => mockServer.stopServer());
async function showQlDocument(name: string): Promise<TextDocument> {
const folderPath = workspace.workspaceFolders![0].uri.fsPath;
const documentPath = resolve(folderPath, name);
const document = await workspace.openTextDocument(documentPath);
await window.showTextDocument(document!);
return document;
}
// MSW can't intercept fetch requests made in VS Code, so we are skipping these tests for now
describe.skip("Variant Analysis Submission Integration", () => {
const commandManager = createVSCodeCommandManager<AllCommands>();
let quickPickSpy: jest.SpiedFunction<typeof window.showQuickPick>;
let executeCommandSpy: jest.SpiedFunction<typeof commands.executeCommand>;
let showErrorMessageSpy: jest.SpiedFunction<typeof window.showErrorMessage>;
beforeEach(async () => {
await setRemoteControllerRepo("github/vscode-codeql");
jest.spyOn(authentication, "getSession").mockResolvedValue({
id: "test",
accessToken: "test-token",
scopes: [],
account: {
id: "test",
label: "test",
},
});
quickPickSpy = jest
.spyOn(window, "showQuickPick")
.mockResolvedValue(undefined);
executeCommandSpy = jest.spyOn(commands, "executeCommand");
showErrorMessageSpy = jest
.spyOn(window, "showErrorMessage")
.mockResolvedValue(undefined);
await getActivatedExtension();
});
describe("Successful scenario", () => {
beforeEach(async () => {
await mockServer.loadScenario("mrva-problem-query-success");
});
it("opens the variant analysis view", async () => {
await showQlDocument("query.ql");
// Select target language for your query
quickPickSpy.mockResolvedValueOnce(
mockedQuickPickItem({
label: "JavaScript",
language: "javascript",
}),
);
await commandManager.execute("codeQL.runVariantAnalysis");
expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.openVariantAnalysisView",
146,
);
});
});
describe("Missing controller repo", () => {
beforeEach(async () => {
await mockServer.loadScenario("mrva-missing-controller-repo");
});
it("shows the error message", async () => {
await showQlDocument("query.ql");
// Select target language for your query
quickPickSpy.mockResolvedValueOnce(
mockedQuickPickItem({
label: "JavaScript",
language: "javascript",
}),
);
await commandManager.execute("codeQL.runVariantAnalysis");
expect(showErrorMessageSpy).toHaveBeenCalledWith(
expect.stringContaining(
'Controller repository "github/vscode-codeql" not found',
),
expect.any(String),
);
});
});
describe("Submission failure", () => {
beforeEach(async () => {
await mockServer.loadScenario("mrva-submission-failure");
});
it("shows the error message", async () => {
await showQlDocument("query.ql");
// Select target language for your query
quickPickSpy.mockResolvedValueOnce(
mockedQuickPickItem({
label: "JavaScript",
language: "javascript",
}),
);
await commandManager.execute("codeQL.runVariantAnalysis");
expect(showErrorMessageSpy).toHaveBeenCalledWith(
expect.stringContaining(
"Unable to trigger a variant analysis. None of the requested repositories could be found.",
),
expect.any(String),
);
});
});
});