diff --git a/extensions/ql-vscode/test/factories/databases/databases.ts b/extensions/ql-vscode/test/factories/databases/databases.ts index 60a533b32..6db032dbe 100644 --- a/extensions/ql-vscode/test/factories/databases/databases.ts +++ b/extensions/ql-vscode/test/factories/databases/databases.ts @@ -19,7 +19,7 @@ export function mockDbOptions(): FullDatabaseOptions { } export function createMockDB( - dir: DirResult, + dir: DirResult | string, dbOptions = mockDbOptions(), // source archive location must be a real(-ish) location since // tests will add this to the workspace location @@ -39,10 +39,18 @@ export function createMockDB( ); } -export function sourceLocationUri(dir: DirResult) { +export function sourceLocationUri(dir: DirResult | string) { + if (typeof dir === "string") { + return Uri.file(join(dir, "src.zip")); + } + return Uri.file(join(dir.name, "src.zip")); } -export function dbLocationUri(dir: DirResult) { +export function dbLocationUri(dir: DirResult | string) { + if (typeof dir === "string") { + return Uri.file(join(dir, "db")); + } + return Uri.file(join(dir.name, "db")); } diff --git a/extensions/ql-vscode/test/vscode-tests/minimal-workspace/local-queries/local-databases.test.ts b/extensions/ql-vscode/test/vscode-tests/minimal-workspace/local-queries/local-databases.test.ts index d0c6fda51..25c560e80 100644 --- a/extensions/ql-vscode/test/vscode-tests/minimal-workspace/local-queries/local-databases.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/minimal-workspace/local-queries/local-databases.test.ts @@ -242,6 +242,37 @@ describe("local databases", () => { await expect(pathExists(mockDbItem.databaseUri.fsPath)).resolves.toBe( false, ); + await expect(pathExists(dir.name)).resolves.toBe(true); + }); + + it("should remove a database item with an extension managed location", async () => { + const dbLocation = join(dir.name, "org-repo-12"); + await ensureDir(dbLocation); + + const mockDbItem = createMockDB(dbLocation, { + ...mockDbOptions(), + extensionManagedLocation: dbLocation, + }); + await ensureDir(mockDbItem.databaseUri.fsPath); + + // pretend that this item is the first workspace folder in the list + jest + .spyOn(mockDbItem, "belongsToSourceArchiveExplorerUri") + .mockReturnValue(true); + + await (databaseManager as any).addDatabaseItem(mockDbItem); + + updateSpy.mockClear(); + + await databaseManager.removeDatabaseItem(mockDbItem); + + expect(databaseManager.databaseItems).toEqual([]); + expect(updateSpy).toHaveBeenCalledWith("databaseList", []); + // should remove the folder + expect(workspace.updateWorkspaceFolders).toHaveBeenCalledWith(0, 1); + + // should delete the complete extension managed location + await expect(pathExists(dbLocation)).resolves.toBe(false); }); it("should remove a database item outside of the extension controlled area", async () => {