Skip to content

Commit 62bebc0

Browse files
committed
Set storage path after the user selects language
And add tests for getFirstStoragePath method
1 parent 16a8289 commit 62bebc0

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

extensions/ql-vscode/src/skeleton-query-wizard.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export class SkeletonQueryWizard {
3636
private readonly extLogger: OutputChannelLogger,
3737
private readonly databaseManager: DatabaseManager,
3838
private readonly token: CancellationToken,
39-
) {
40-
this.storagePath = this.workoutStoragePath();
41-
}
39+
) {}
4240

4341
private get folderName() {
4442
return `codeql-custom-queries-${this.language}`;
@@ -51,6 +49,8 @@ export class SkeletonQueryWizard {
5149
return;
5250
}
5351

52+
this.storagePath = this.getFirstStoragePath();
53+
5454
const skeletonPackAlreadyExists = isFolderAlreadyInWorkspace(
5555
this.folderName,
5656
);
@@ -91,7 +91,7 @@ export class SkeletonQueryWizard {
9191
}
9292
}
9393

94-
private workoutStoragePath() {
94+
public getFirstStoragePath() {
9595
const workspaceFolders = workspace.workspaceFolders;
9696

9797
if (!workspaceFolders || workspaceFolders.length === 0) {

extensions/ql-vscode/test/vscode-tests/cli-integration/skeleton-query-wizard.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,52 @@ describe("SkeletonQueryWizard", () => {
245245
});
246246
});
247247
});
248+
249+
describe("getFirstStoragePath", () => {
250+
it("should return the first workspace folder", async () => {
251+
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
252+
{
253+
name: "codeql-custom-queries-cpp",
254+
uri: { path: "codespaces-codeql" },
255+
},
256+
] as WorkspaceFolder[]);
257+
258+
wizard = new SkeletonQueryWizard(
259+
mockCli,
260+
jest.fn(),
261+
credentials,
262+
extLogger,
263+
mockDatabaseManager,
264+
token,
265+
);
266+
267+
expect(wizard.getFirstStoragePath()).toEqual("codespaces-codeql");
268+
});
269+
270+
describe("if user is in vscode-codeql-starter workspace", () => {
271+
it("should set storage path to parent folder", async () => {
272+
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
273+
{
274+
name: "codeql-custom-queries-cpp",
275+
uri: { path: "vscode-codeql-starter/codeql-custom-queries-cpp" },
276+
},
277+
{
278+
name: "codeql-custom-queries-csharp",
279+
uri: { path: "vscode-codeql-starter/codeql-custom-queries-csharp" },
280+
},
281+
] as WorkspaceFolder[]);
282+
283+
wizard = new SkeletonQueryWizard(
284+
mockCli,
285+
jest.fn(),
286+
credentials,
287+
extLogger,
288+
mockDatabaseManager,
289+
token,
290+
);
291+
292+
expect(wizard.getFirstStoragePath()).toEqual("vscode-codeql-starter");
293+
});
294+
});
295+
});
248296
});

0 commit comments

Comments
 (0)