Skip to content

Commit ed11b20

Browse files
committed
Add tests for does exist methods
1 parent 8cb0cd2 commit ed11b20

1 file changed

Lines changed: 140 additions & 0 deletions

File tree

extensions/ql-vscode/test/unit-tests/databases/config/db-config-store.test.ts

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,4 +673,144 @@ describe("db config store", () => {
673673
configStore.dispose();
674674
});
675675
});
676+
677+
describe("does exist methods", () => {
678+
let app: App;
679+
let configPath: string;
680+
681+
beforeEach(async () => {
682+
app = createMockApp({
683+
extensionPath,
684+
workspaceStoragePath: tempWorkspaceStoragePath,
685+
});
686+
687+
configPath = join(tempWorkspaceStoragePath, "workspace-databases.json");
688+
});
689+
690+
it("should return true if a remote owner exists", async () => {
691+
// Initial set up
692+
const dbConfig = createDbConfig({
693+
remoteOwners: ["owner1", "owner2"],
694+
});
695+
696+
await writeJSON(configPath, dbConfig);
697+
698+
const configStore = new DbConfigStore(app);
699+
await configStore.initialize();
700+
701+
// Check
702+
const doesExist = await configStore.doesRemoteOwnerExist("owner1");
703+
expect(doesExist).toEqual(true);
704+
705+
configStore.dispose();
706+
});
707+
708+
it("should return true if a remote list exists", async () => {
709+
// Initial set up
710+
const dbConfig = createDbConfig({
711+
remoteLists: [
712+
{
713+
name: "list1",
714+
repositories: ["owner/repo1", "owner/repo2"],
715+
},
716+
],
717+
});
718+
719+
await writeJSON(configPath, dbConfig);
720+
721+
const configStore = new DbConfigStore(app);
722+
await configStore.initialize();
723+
724+
// Check
725+
const doesExist = await configStore.doesRemoteListExist("list1");
726+
expect(doesExist).toEqual(true);
727+
728+
configStore.dispose();
729+
});
730+
731+
it("should return true if a remote db exists", async () => {
732+
// Initial set up
733+
const dbConfig = createDbConfig({
734+
remoteLists: [
735+
{
736+
name: "list1",
737+
repositories: ["owner/repo1", "owner/repo2"],
738+
},
739+
],
740+
});
741+
742+
await writeJSON(configPath, dbConfig);
743+
744+
const configStore = new DbConfigStore(app);
745+
await configStore.initialize();
746+
747+
// Check
748+
const doesExist = await configStore.doesRemoteDbExist(
749+
"owner/repo1",
750+
"list1",
751+
);
752+
expect(doesExist).toEqual(true);
753+
754+
configStore.dispose();
755+
});
756+
757+
it("should return true if a local db and local list exists", async () => {
758+
// Initial set up
759+
const dbConfig = createDbConfig({
760+
localLists: [
761+
{
762+
name: "list1",
763+
databases: [createLocalDbConfigItem({ name: "db1" })],
764+
},
765+
],
766+
});
767+
768+
await writeJSON(configPath, dbConfig);
769+
770+
const configStore = new DbConfigStore(app);
771+
await configStore.initialize();
772+
773+
// Check
774+
const doesDbExist = await configStore.doesLocalDbExist("db1", "list1");
775+
expect(doesDbExist).toEqual(true);
776+
const doesListExist = await configStore.doesLocalListExist("list1");
777+
expect(doesListExist).toEqual(true);
778+
779+
configStore.dispose();
780+
});
781+
782+
it("should return false if items do not exist", async () => {
783+
// Initial set up
784+
const dbConfig = createDbConfig({});
785+
786+
await writeJSON(configPath, dbConfig);
787+
788+
const configStore = new DbConfigStore(app);
789+
await configStore.initialize();
790+
791+
// Check
792+
const doesLocalDbExist = await configStore.doesLocalDbExist(
793+
"db1",
794+
"list1",
795+
);
796+
expect(doesLocalDbExist).toEqual(false);
797+
const doesLocalListExist = await configStore.doesLocalListExist("list1");
798+
expect(doesLocalListExist).toEqual(false);
799+
const doesRemoteDbExist = await configStore.doesRemoteDbExist(
800+
"db1",
801+
"list1",
802+
);
803+
expect(doesRemoteDbExist).toEqual(false);
804+
const doesRemoteListExist = await configStore.doesRemoteListExist(
805+
"list1",
806+
);
807+
expect(doesRemoteListExist).toEqual(false);
808+
const doesRemoteOwnerExist = await configStore.doesRemoteOwnerExist(
809+
"owner1",
810+
);
811+
expect(doesRemoteOwnerExist).toEqual(false);
812+
813+
configStore.dispose();
814+
});
815+
});
676816
});

0 commit comments

Comments
 (0)