|
7 | 7 | } from "../../../src/databases/config/db-config"; |
8 | 8 | import { DbConfigStore } from "../../../src/databases/config/db-config-store"; |
9 | 9 | import { |
| 10 | + DbListKind, |
10 | 11 | flattenDbItems, |
11 | 12 | isLocalDatabaseDbItem, |
12 | 13 | isLocalListDbItem, |
@@ -67,6 +68,189 @@ describe("db manager", () => { |
67 | 68 | dbConfigStore.dispose(); |
68 | 69 | }); |
69 | 70 |
|
| 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 | + |
70 | 254 | describe("renaming items", () => { |
71 | 255 | const remoteList = { |
72 | 256 | name: "my-list-1", |
|
0 commit comments