Skip to content

Commit 1bd749d

Browse files
authored
Convert integration tests to unit tests (#1986)
1 parent 13389fd commit 1bd749d

3 files changed

Lines changed: 184 additions & 321 deletions

File tree

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

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "../../../src/databases/config/db-config";
88
import { DbConfigStore } from "../../../src/databases/config/db-config-store";
99
import {
10+
DbListKind,
1011
flattenDbItems,
1112
isLocalDatabaseDbItem,
1213
isLocalListDbItem,
@@ -67,6 +68,189 @@ describe("db manager", () => {
6768
dbConfigStore.dispose();
6869
});
6970

71+
describe("adding items", () => {
72+
describe("adding a remote repo", () => {
73+
it("should add a new remote repo", async () => {
74+
const dbConfig: DbConfig = createDbConfig({
75+
remoteRepos: ["owner1/repo1"],
76+
});
77+
78+
await saveDbConfig(dbConfig);
79+
80+
await dbManager.addNewRemoteRepo("owner2/repo2");
81+
82+
const dbConfigFileContents = await readDbConfigDirectly();
83+
expect(
84+
dbConfigFileContents.databases.variantAnalysis.repositories.length,
85+
).toBe(2);
86+
expect(
87+
dbConfigFileContents.databases.variantAnalysis.repositories[1],
88+
).toEqual("owner2/repo2");
89+
});
90+
91+
it("should add a new remote repo to a user defined list", async () => {
92+
const dbConfig: DbConfig = createDbConfig({
93+
remoteLists: [
94+
{
95+
name: "my-list-1",
96+
repositories: ["owner1/repo1"],
97+
},
98+
],
99+
});
100+
101+
await saveDbConfig(dbConfig);
102+
103+
await dbManager.addNewRemoteRepo("owner2/repo2", "my-list-1");
104+
105+
const dbConfigFileContents = await readDbConfigDirectly();
106+
expect(
107+
dbConfigFileContents.databases.variantAnalysis.repositoryLists.length,
108+
).toBe(1);
109+
110+
expect(
111+
dbConfigFileContents.databases.variantAnalysis.repositoryLists[0],
112+
).toEqual({
113+
name: "my-list-1",
114+
repositories: ["owner1/repo1", "owner2/repo2"],
115+
});
116+
});
117+
118+
it("should not allow adding a new remote db with empty name", async () => {
119+
const dbConfig = createDbConfig();
120+
121+
await saveDbConfig(dbConfig);
122+
123+
await expect(dbManager.addNewRemoteRepo("")).rejects.toThrow(
124+
new Error("Repository name cannot be empty"),
125+
);
126+
});
127+
128+
it("should not allow adding a remote db with duplicate name", async () => {
129+
const dbConfig = createDbConfig({
130+
remoteRepos: ["owner1/repo1"],
131+
});
132+
133+
await saveDbConfig(dbConfig);
134+
135+
await expect(
136+
dbManager.addNewRemoteRepo("owner1/repo1"),
137+
).rejects.toThrow(
138+
new Error(
139+
"A variant analysis repository with the name 'owner1/repo1' already exists",
140+
),
141+
);
142+
});
143+
});
144+
145+
describe("adding a list", () => {
146+
it("should add a new remote list", async () => {
147+
const dbConfig: DbConfig = createDbConfig({
148+
remoteLists: [
149+
{
150+
name: "my-list-1",
151+
repositories: ["owner1/repo1", "owner1/repo2"],
152+
},
153+
],
154+
selected: {
155+
kind: SelectedDbItemKind.VariantAnalysisUserDefinedList,
156+
listName: "my-list-1",
157+
},
158+
});
159+
160+
await saveDbConfig(dbConfig);
161+
162+
await dbManager.addNewList(DbListKind.Remote, "my-list-2");
163+
164+
const dbConfigFileContents = await readDbConfigDirectly();
165+
expect(
166+
dbConfigFileContents.databases.variantAnalysis.repositoryLists.length,
167+
).toBe(2);
168+
expect(
169+
dbConfigFileContents.databases.variantAnalysis.repositoryLists[1],
170+
).toEqual({
171+
name: "my-list-2",
172+
repositories: [],
173+
});
174+
});
175+
176+
it("should throw error when adding a new list to a local node", async () => {
177+
const dbConfig: DbConfig = createDbConfig({
178+
localLists: [
179+
{
180+
name: "my-list-1",
181+
databases: [],
182+
},
183+
],
184+
});
185+
await saveDbConfig(dbConfig);
186+
187+
await dbManager.addNewList(DbListKind.Local, "my-list-2");
188+
189+
const dbConfigFileContents = await readDbConfigDirectly();
190+
expect(dbConfigFileContents.databases.local.lists.length).toBe(2);
191+
expect(dbConfigFileContents.databases.local.lists[1]).toEqual({
192+
name: "my-list-2",
193+
databases: [],
194+
});
195+
});
196+
197+
it("should not allow adding a new list with empty name", async () => {
198+
const dbConfig = createDbConfig();
199+
200+
await saveDbConfig(dbConfig);
201+
202+
await expect(
203+
dbManager.addNewList(DbListKind.Remote, ""),
204+
).rejects.toThrow(new Error("List name cannot be empty"));
205+
});
206+
207+
it("should not allow adding a list with duplicate name", async () => {
208+
const dbConfig = createDbConfig({
209+
remoteLists: [
210+
{
211+
name: "my-list-1",
212+
repositories: ["owner1/repo1", "owner1/repo2"],
213+
},
214+
],
215+
});
216+
217+
await saveDbConfig(dbConfig);
218+
219+
await expect(
220+
dbManager.addNewList(DbListKind.Remote, "my-list-1"),
221+
).rejects.toThrow(
222+
new Error(
223+
"A variant analysis list with the name 'my-list-1' already exists",
224+
),
225+
);
226+
});
227+
});
228+
});
229+
230+
describe("adding an owner", () => {
231+
it("should not allow adding a new remote owner with empty name", async () => {
232+
const dbConfig = createDbConfig();
233+
234+
await saveDbConfig(dbConfig);
235+
236+
await expect(dbManager.addNewRemoteOwner("")).rejects.toThrow(
237+
new Error("Owner name cannot be empty"),
238+
);
239+
});
240+
241+
it("should not allow adding a remote owner with duplicate name", async () => {
242+
const dbConfig = createDbConfig({
243+
remoteOwners: ["owner1"],
244+
});
245+
246+
await saveDbConfig(dbConfig);
247+
248+
await expect(dbManager.addNewRemoteOwner("owner1")).rejects.toThrow(
249+
new Error("An owner with the name 'owner1' already exists"),
250+
);
251+
});
252+
});
253+
70254
describe("renaming items", () => {
71255
const remoteList = {
72256
name: "my-list-1",

extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases/db-panel.test.ts

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { DbConfig } from "../../../../src/databases/config/db-config";
55
import { DbManager } from "../../../../src/databases/db-manager";
66
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
77
import { DbTreeDataProvider } from "../../../../src/databases/ui/db-tree-data-provider";
8-
import { DbListKind } from "../../../../src/databases/db-item";
98
import { DbTreeViewItem } from "../../../../src/databases/ui/db-tree-view-item";
109
import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
1110
import { createMockExtensionContext } from "../../../factories/extension-context";
@@ -104,85 +103,6 @@ describe("db panel", () => {
104103
});
105104
});
106105

107-
describe("name validation", () => {
108-
it("should not allow adding a new list with empty name", async () => {
109-
const dbConfig = createDbConfig();
110-
111-
await saveDbConfig(dbConfig);
112-
113-
await expect(dbManager.addNewList(DbListKind.Remote, "")).rejects.toThrow(
114-
new Error("List name cannot be empty"),
115-
);
116-
});
117-
118-
it("should not allow adding a list with duplicate name", async () => {
119-
const dbConfig = createDbConfig({
120-
remoteLists: [
121-
{
122-
name: "my-list-1",
123-
repositories: ["owner1/repo1", "owner1/repo2"],
124-
},
125-
],
126-
});
127-
128-
await saveDbConfig(dbConfig);
129-
130-
await expect(
131-
dbManager.addNewList(DbListKind.Remote, "my-list-1"),
132-
).rejects.toThrow(
133-
new Error(
134-
"A variant analysis list with the name 'my-list-1' already exists",
135-
),
136-
);
137-
});
138-
139-
it("should not allow adding a new remote db with empty name", async () => {
140-
const dbConfig = createDbConfig();
141-
142-
await saveDbConfig(dbConfig);
143-
144-
await expect(dbManager.addNewRemoteRepo("")).rejects.toThrow(
145-
new Error("Repository name cannot be empty"),
146-
);
147-
});
148-
149-
it("should not allow adding a remote db with duplicate name", async () => {
150-
const dbConfig = createDbConfig({
151-
remoteRepos: ["owner1/repo1"],
152-
});
153-
154-
await saveDbConfig(dbConfig);
155-
156-
await expect(dbManager.addNewRemoteRepo("owner1/repo1")).rejects.toThrow(
157-
new Error(
158-
"A variant analysis repository with the name 'owner1/repo1' already exists",
159-
),
160-
);
161-
});
162-
163-
it("should not allow adding a new remote owner with empty name", async () => {
164-
const dbConfig = createDbConfig();
165-
166-
await saveDbConfig(dbConfig);
167-
168-
await expect(dbManager.addNewRemoteOwner("")).rejects.toThrow(
169-
new Error("Owner name cannot be empty"),
170-
);
171-
});
172-
173-
it("should not allow adding a remote owner with duplicate name", async () => {
174-
const dbConfig = createDbConfig({
175-
remoteOwners: ["owner1"],
176-
});
177-
178-
await saveDbConfig(dbConfig);
179-
180-
await expect(dbManager.addNewRemoteOwner("owner1")).rejects.toThrow(
181-
new Error("An owner with the name 'owner1' already exists"),
182-
);
183-
});
184-
});
185-
186106
async function saveDbConfig(dbConfig: DbConfig): Promise<void> {
187107
await writeJson(dbConfigFilePath, dbConfig);
188108

0 commit comments

Comments
 (0)