-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathvariant-analysis-submission-integration.test.ts
125 lines (101 loc) · 3.64 KB
/
variant-analysis-submission-integration.test.ts
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
import { resolve } from "path";
import {
authentication,
commands,
extensions,
TextDocument,
window,
workspace,
} from "vscode";
import { CodeQLExtensionInterface } from "../../../../src/extension";
import { MockGitHubApiServer } from "../../../../src/mocks/mock-gh-api-server";
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
import { setRemoteControllerRepo } from "../../../../src/config";
jest.setTimeout(30_000);
const mockServer = new MockGitHubApiServer();
beforeAll(() => mockServer.startServer());
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;
}
describe("Variant Analysis Submission Integration", () => {
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 extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
"GitHub.vscode-codeql",
)!
.activate();
});
describe("Successful scenario", () => {
beforeEach(async () => {
await mockServer.loadScenario("problem-query-success");
});
it("opens the variant analysis view", async () => {
await showQlDocument("query.ql");
// Select target language for your query
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));
await commands.executeCommand("codeQL.runVariantAnalysis");
expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.openVariantAnalysisView",
146,
);
});
});
describe("Missing controller repo", () => {
beforeEach(async () => {
await mockServer.loadScenario("missing-controller-repo");
});
it("shows the error message", async () => {
await showQlDocument("query.ql");
await commands.executeCommand("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("submission-failure");
});
it("shows the error message", async () => {
await showQlDocument("query.ql");
// Select target language for your query
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));
await commands.executeCommand("codeQL.runVariantAnalysis");
expect(showErrorMessageSpy).toHaveBeenCalledWith(
expect.stringContaining(
"Unable to trigger a variant analysis. None of the requested repositories could be found.",
),
expect.any(String),
);
});
});
});