Add test for extension-managed db location

This commit is contained in:
Koen Vlaswinkel
2024-03-11 11:15:15 +01:00
parent f426178b96
commit 82741e95c3
2 changed files with 42 additions and 3 deletions

View File

@@ -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"));
}

View File

@@ -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 () => {