Skip to content

Commit 323862a

Browse files
committed
Merge comments
1 parent 7a3d5c1 commit 323862a

File tree

2 files changed

+35
-49
lines changed

2 files changed

+35
-49
lines changed

extensions/ql-vscode/src/remote-queries/repository-selection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function getRepositorySelection(
3737
dbManager?: DbManager,
3838
): Promise<RepositorySelection> {
3939
if (isNewQueryRunExperienceEnabled()) {
40-
const selectedDbItem = await dbManager?.getSelectedDbItem();
40+
const selectedDbItem = dbManager?.getSelectedDbItem();
4141
if (selectedDbItem) {
4242
switch (selectedDbItem.kind) {
4343
case DbItemKind.LocalDatabase || DbItemKind.LocalList:
@@ -55,7 +55,7 @@ export async function getRepositorySelection(
5555
}
5656
} else {
5757
throw new Error(
58-
"Please select a remote database item to run the query against.",
58+
"Please select a remote database to run the query against.",
5959
);
6060
}
6161
}

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/repository-selection.test.ts

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { UserCancellationException } from "../../../commandRunner";
55
import * as config from "../../../config";
66
import { getRepositorySelection } from "../../../remote-queries/repository-selection";
77
import { DbManager } from "../../../databases/db-manager";
8-
import { DbItemKind } from "../../../databases/db-item";
8+
import { DbItem, DbItemKind } from "../../../databases/db-item";
99

1010
describe("repository selection", () => {
1111
describe("newQueryRunExperience true", () => {
@@ -16,38 +16,28 @@ describe("repository selection", () => {
1616
});
1717

1818
it("should throw error when no database item is selected", async () => {
19-
const dbManager = {
20-
getSelectedDbItem: jest.fn(() => undefined),
21-
} as any as DbManager;
19+
const dbManager = setUpDbManager(undefined);
2220

2321
await expect(getRepositorySelection(dbManager)).rejects.toThrow(
24-
Error("Please select a remote database item to run the query against."),
22+
Error("Please select a remote database to run the query against."),
2523
);
2624
});
2725

2826
it("should throw error when local database item is selected", async () => {
29-
const dbManager = {
30-
getSelectedDbItem: jest.fn(() => {
31-
return {
32-
kind: DbItemKind.LocalDatabase,
33-
};
34-
}),
35-
} as any as DbManager;
27+
const dbManager = setUpDbManager({
28+
kind: DbItemKind.LocalDatabase,
29+
} as DbItem);
3630

3731
await expect(getRepositorySelection(dbManager)).rejects.toThrow(
3832
Error("Local databases and lists are not supported yet."),
3933
);
4034
});
4135

4236
it("should return correct selection when remote system defined list is selected", async () => {
43-
const dbManager = {
44-
getSelectedDbItem: jest.fn(() => {
45-
return {
46-
kind: DbItemKind.RemoteSystemDefinedList,
47-
listName: "top_10",
48-
};
49-
}),
50-
} as any as DbManager;
37+
const dbManager = setUpDbManager({
38+
kind: DbItemKind.RemoteSystemDefinedList,
39+
listName: "top_10",
40+
} as DbItem);
5141

5242
const repoSelection = await getRepositorySelection(dbManager);
5343

@@ -57,17 +47,13 @@ describe("repository selection", () => {
5747
});
5848

5949
it("should return correct selection when remote user defined list is selected", async () => {
60-
const dbManager = {
61-
getSelectedDbItem: jest.fn(() => {
62-
return {
63-
kind: DbItemKind.RemoteUserDefinedList,
64-
repos: [
65-
{ repoFullName: "owner1/repo1" },
66-
{ repoFullName: "owner1/repo2" },
67-
],
68-
};
69-
}),
70-
} as any as DbManager;
50+
const dbManager = setUpDbManager({
51+
kind: DbItemKind.RemoteUserDefinedList,
52+
repos: [
53+
{ repoFullName: "owner1/repo1" },
54+
{ repoFullName: "owner1/repo2" },
55+
],
56+
} as DbItem);
7157

7258
const repoSelection = await getRepositorySelection(dbManager);
7359

@@ -80,14 +66,10 @@ describe("repository selection", () => {
8066
});
8167

8268
it("should return correct selection when remote owner is selected", async () => {
83-
const dbManager = {
84-
getSelectedDbItem: jest.fn(() => {
85-
return {
86-
kind: DbItemKind.RemoteOwner,
87-
ownerName: "owner2",
88-
};
89-
}),
90-
} as any as DbManager;
69+
const dbManager = setUpDbManager({
70+
kind: DbItemKind.RemoteOwner,
71+
ownerName: "owner2",
72+
} as DbItem);
9173

9274
const repoSelection = await getRepositorySelection(dbManager);
9375

@@ -97,21 +79,25 @@ describe("repository selection", () => {
9779
});
9880

9981
it("should return correct selection when remote repo is selected", async () => {
100-
const dbManager = {
101-
getSelectedDbItem: jest.fn(() => {
102-
return {
103-
kind: DbItemKind.RemoteRepo,
104-
repoFullName: "owner1/repo2",
105-
};
106-
}),
107-
} as any as DbManager;
82+
const dbManager = setUpDbManager({
83+
kind: DbItemKind.RemoteRepo,
84+
repoFullName: "owner1/repo2",
85+
} as DbItem);
10886

10987
const repoSelection = await getRepositorySelection(dbManager);
11088

11189
expect(repoSelection.repositoryLists).toBeUndefined();
11290
expect(repoSelection.owners).toBeUndefined();
11391
expect(repoSelection.repositories).toEqual(["owner1/repo2"]);
11492
});
93+
94+
function setUpDbManager(response: DbItem | undefined): DbManager {
95+
return {
96+
getSelectedDbItem: jest.fn(() => {
97+
return response;
98+
}),
99+
} as any as DbManager;
100+
}
115101
});
116102

117103
describe("newQueryRunExperience false", () => {

0 commit comments

Comments
 (0)