@@ -184,6 +184,146 @@ describe("db config store", () => {
184184 } ) ;
185185 } ) ;
186186
187+ describe ( "add db items" , ( ) => {
188+ let app : App ;
189+ let configPath : string ;
190+
191+ beforeEach ( async ( ) => {
192+ app = createMockApp ( {
193+ extensionPath,
194+ workspaceStoragePath : tempWorkspaceStoragePath ,
195+ } ) ;
196+
197+ configPath = join ( tempWorkspaceStoragePath , "workspace-databases.json" ) ;
198+ } ) ;
199+
200+ it ( "should add a remote repository" , async ( ) => {
201+ // Initial set up
202+ const dbConfig = createDbConfig ( ) ;
203+
204+ await writeJSON ( configPath , dbConfig ) ;
205+
206+ const configStore = new DbConfigStore ( app ) ;
207+ await configStore . initialize ( ) ;
208+
209+ // Add
210+ await configStore . addRemoteRepo ( "repo1" ) ;
211+
212+ // Read the config file
213+ const updatedDbConfig = ( await readJSON ( configPath ) ) as DbConfig ;
214+
215+ // Check that the config file has been updated
216+ const updatedRemoteDbs = updatedDbConfig . databases . remote ;
217+ expect ( updatedRemoteDbs . repositories ) . toHaveLength ( 1 ) ;
218+ expect ( updatedRemoteDbs . repositories ) . toEqual ( [ "repo1" ] ) ;
219+
220+ configStore . dispose ( ) ;
221+ } ) ;
222+
223+ it ( "should add a remote repository to the correct list" , async ( ) => {
224+ // Initial set up
225+ const dbConfig = createDbConfig ( {
226+ remoteLists : [
227+ {
228+ name : "list1" ,
229+ repositories : [ ] ,
230+ } ,
231+ ] ,
232+ } ) ;
233+
234+ await writeJSON ( configPath , dbConfig ) ;
235+
236+ const configStore = new DbConfigStore ( app ) ;
237+ await configStore . initialize ( ) ;
238+
239+ // Add
240+ await configStore . addRemoteRepo ( "repo1" , "list1" ) ;
241+
242+ // Read the config file
243+ const updatedDbConfig = ( await readJSON ( configPath ) ) as DbConfig ;
244+
245+ // Check that the config file has been updated
246+ const updatedRemoteDbs = updatedDbConfig . databases . remote ;
247+ expect ( updatedRemoteDbs . repositories ) . toHaveLength ( 0 ) ;
248+ expect ( updatedRemoteDbs . repositoryLists ) . toHaveLength ( 1 ) ;
249+ expect ( updatedRemoteDbs . repositoryLists [ 0 ] ) . toEqual ( {
250+ name : "list1" ,
251+ repositories : [ "repo1" ] ,
252+ } ) ;
253+
254+ configStore . dispose ( ) ;
255+ } ) ;
256+
257+ it ( "should add a remote owner" , async ( ) => {
258+ // Initial set up
259+ const dbConfig = createDbConfig ( ) ;
260+
261+ await writeJSON ( configPath , dbConfig ) ;
262+
263+ const configStore = new DbConfigStore ( app ) ;
264+ await configStore . initialize ( ) ;
265+
266+ // Add
267+ await configStore . addRemoteOwner ( "owner1" ) ;
268+
269+ // Read the config file
270+ const updatedDbConfig = ( await readJSON ( configPath ) ) as DbConfig ;
271+
272+ // Check that the config file has been updated
273+ const updatedRemoteDbs = updatedDbConfig . databases . remote ;
274+ expect ( updatedRemoteDbs . owners ) . toHaveLength ( 1 ) ;
275+ expect ( updatedRemoteDbs . owners ) . toEqual ( [ "owner1" ] ) ;
276+
277+ configStore . dispose ( ) ;
278+ } ) ;
279+
280+ it ( "should add a local list" , async ( ) => {
281+ // Initial set up
282+ const dbConfig = createDbConfig ( ) ;
283+
284+ await writeJSON ( configPath , dbConfig ) ;
285+
286+ const configStore = new DbConfigStore ( app ) ;
287+ await configStore . initialize ( ) ;
288+
289+ // Add
290+ await configStore . addLocalList ( "list1" ) ;
291+
292+ // Read the config file
293+ const updatedDbConfig = ( await readJSON ( configPath ) ) as DbConfig ;
294+
295+ // Check that the config file has been updated
296+ const updatedLocalDbs = updatedDbConfig . databases . local ;
297+ expect ( updatedLocalDbs . lists ) . toHaveLength ( 1 ) ;
298+ expect ( updatedLocalDbs . lists [ 0 ] . name ) . toEqual ( "list1" ) ;
299+
300+ configStore . dispose ( ) ;
301+ } ) ;
302+
303+ it ( "should add a remote list" , async ( ) => {
304+ // Initial set up
305+ const dbConfig = createDbConfig ( ) ;
306+
307+ await writeJSON ( configPath , dbConfig ) ;
308+
309+ const configStore = new DbConfigStore ( app ) ;
310+ await configStore . initialize ( ) ;
311+
312+ // Add
313+ await configStore . addRemoteList ( "list1" ) ;
314+
315+ // Read the config file
316+ const updatedDbConfig = ( await readJSON ( configPath ) ) as DbConfig ;
317+
318+ // Check that the config file has been updated
319+ const updatedRemoteDbs = updatedDbConfig . databases . remote ;
320+ expect ( updatedRemoteDbs . repositoryLists ) . toHaveLength ( 1 ) ;
321+ expect ( updatedRemoteDbs . repositoryLists [ 0 ] . name ) . toEqual ( "list1" ) ;
322+
323+ configStore . dispose ( ) ;
324+ } ) ;
325+ } ) ;
326+
187327 describe ( "db and list renaming" , ( ) => {
188328 let app : App ;
189329 let configPath : string ;
0 commit comments