Skip to content

Commit 47ac9c6

Browse files
committed
Add basic integration test for 'add db' functionality
1 parent decbd52 commit 47ac9c6

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { DbManager } from "../db-manager";
1818
import { DbTreeDataProvider } from "./db-tree-data-provider";
1919
import { DbTreeViewItem } from "./db-tree-view-item";
2020

21-
interface RemoteDatabaseQuickPickItem extends QuickPickItem {
21+
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
2222
kind: string;
2323
}
2424

extensions/ql-vscode/src/vscode-tests/cli-integration/databases/db-panel.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CodeQLExtensionInterface } from "../../../extension";
44
import { readJson } from "fs-extra";
55
import * as path from "path";
66
import { DbConfig } from "../../../databases/config/db-config";
7+
import { RemoteDatabaseQuickPickItem } from "../../../databases/ui/db-panel";
78

89
jest.setTimeout(60_000);
910

@@ -33,4 +34,36 @@ describe("Db panel UI commands", () => {
3334
expect(dbConfig.databases.remote.repositoryLists).toHaveLength(1);
3435
expect(dbConfig.databases.remote.repositoryLists[0].name).toBe("my-list-1");
3536
});
37+
38+
it("should add new remote repository", async () => {
39+
// Add db
40+
jest.spyOn(window, "showQuickPick").mockResolvedValue({
41+
kind: "repo",
42+
} as RemoteDatabaseQuickPickItem);
43+
44+
jest.spyOn(window, "showInputBox").mockResolvedValue("owner1/repo1");
45+
await commands.executeCommand("codeQLDatabasesExperimental.addNewDatabase");
46+
47+
// Check db config
48+
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
49+
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
50+
expect(dbConfig.databases.remote.repositories).toHaveLength(1);
51+
expect(dbConfig.databases.remote.repositories[0]).toBe("owner1/repo1");
52+
});
53+
54+
it("should add new remote owner", async () => {
55+
// Add owner
56+
jest.spyOn(window, "showQuickPick").mockResolvedValue({
57+
kind: "owner",
58+
} as RemoteDatabaseQuickPickItem);
59+
60+
jest.spyOn(window, "showInputBox").mockResolvedValue("owner1");
61+
await commands.executeCommand("codeQLDatabasesExperimental.addNewDatabase");
62+
63+
// Check db config
64+
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
65+
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
66+
expect(dbConfig.databases.remote.owners).toHaveLength(1);
67+
expect(dbConfig.databases.remote.owners[0]).toBe("owner1");
68+
});
3669
});

0 commit comments

Comments
 (0)