@@ -16,151 +16,155 @@ describe("db config store", () => {
1616 await remove ( tempWorkspaceStoragePath ) ;
1717 } ) ;
1818
19- it ( "should create a new config if one does not exist" , async ( ) => {
20- const app = createMockApp ( {
21- extensionPath,
22- workspaceStoragePath : tempWorkspaceStoragePath ,
19+ describe ( "initialize" , ( ) => {
20+ it ( "should create a new config if one does not exist" , async ( ) => {
21+ const app = createMockApp ( {
22+ extensionPath,
23+ workspaceStoragePath : tempWorkspaceStoragePath ,
24+ } ) ;
25+
26+ const configPath = join (
27+ tempWorkspaceStoragePath ,
28+ "workspace-databases.json" ,
29+ ) ;
30+
31+ const configStore = new DbConfigStore ( app ) ;
32+ await configStore . initialize ( ) ;
33+
34+ expect ( await pathExists ( configPath ) ) . toBe ( true ) ;
35+
36+ const config = configStore . getConfig ( ) . value ;
37+ expect ( config . databases . remote . repositoryLists ) . toHaveLength ( 0 ) ;
38+ expect ( config . databases . remote . owners ) . toHaveLength ( 0 ) ;
39+ expect ( config . databases . remote . repositories ) . toHaveLength ( 0 ) ;
40+ expect ( config . databases . local . lists ) . toHaveLength ( 0 ) ;
41+ expect ( config . databases . local . databases ) . toHaveLength ( 0 ) ;
42+ expect ( config . selected ) . toBeUndefined ( ) ;
43+
44+ configStore . dispose ( ) ;
2345 } ) ;
2446
25- const configPath = join (
26- tempWorkspaceStoragePath ,
27- "workspace-databases.json" ,
28- ) ;
29-
30- const configStore = new DbConfigStore ( app ) ;
31- await configStore . initialize ( ) ;
32-
33- expect ( await pathExists ( configPath ) ) . toBe ( true ) ;
34-
35- const config = configStore . getConfig ( ) . value ;
36- expect ( config . databases . remote . repositoryLists ) . toHaveLength ( 0 ) ;
37- expect ( config . databases . remote . owners ) . toHaveLength ( 0 ) ;
38- expect ( config . databases . remote . repositories ) . toHaveLength ( 0 ) ;
39- expect ( config . databases . local . lists ) . toHaveLength ( 0 ) ;
40- expect ( config . databases . local . databases ) . toHaveLength ( 0 ) ;
41- expect ( config . selected ) . toBeUndefined ( ) ;
42-
43- configStore . dispose ( ) ;
44- } ) ;
45-
46- it ( "should load an existing config" , async ( ) => {
47- const app = createMockApp ( {
48- extensionPath,
49- workspaceStoragePath : testDataStoragePath ,
50- } ) ;
51- const configStore = new DbConfigStore ( app ) ;
52- await configStore . initialize ( ) ;
53-
54- const config = configStore . getConfig ( ) . value ;
55- expect ( config . databases . remote . repositoryLists ) . toHaveLength ( 1 ) ;
56- expect ( config . databases . remote . repositoryLists [ 0 ] ) . toEqual ( {
57- name : "repoList1" ,
58- repositories : [ "foo/bar" , "foo/baz" ] ,
59- } ) ;
60- expect ( config . databases . remote . owners ) . toHaveLength ( 0 ) ;
61- expect ( config . databases . remote . repositories ) . toHaveLength ( 3 ) ;
62- expect ( config . databases . remote . repositories ) . toEqual ( [
63- "owner/repo1" ,
64- "owner/repo2" ,
65- "owner/repo3" ,
66- ] ) ;
67- expect ( config . databases . local . lists ) . toHaveLength ( 2 ) ;
68- expect ( config . databases . local . lists [ 0 ] ) . toEqual ( {
69- name : "localList1" ,
70- databases : [
71- {
72- name : "foo/bar" ,
73- dateAdded : 1668096745193 ,
74- language : "go" ,
75- storagePath : "/path/to/database/" ,
76- } ,
77- ] ,
78- } ) ;
79- expect ( config . databases . local . databases ) . toHaveLength ( 1 ) ;
80- expect ( config . databases . local . databases [ 0 ] ) . toEqual ( {
81- name : "example-db" ,
82- dateAdded : 1668096927267 ,
83- language : "ruby" ,
84- storagePath : "/path/to/database/" ,
85- } ) ;
86- expect ( config . selected ) . toEqual ( {
87- kind : "remoteUserDefinedList" ,
88- listName : "repoList1" ,
47+ it ( "should load an existing config" , async ( ) => {
48+ const app = createMockApp ( {
49+ extensionPath,
50+ workspaceStoragePath : testDataStoragePath ,
51+ } ) ;
52+ const configStore = new DbConfigStore ( app ) ;
53+ await configStore . initialize ( ) ;
54+
55+ const config = configStore . getConfig ( ) . value ;
56+ expect ( config . databases . remote . repositoryLists ) . toHaveLength ( 1 ) ;
57+ expect ( config . databases . remote . repositoryLists [ 0 ] ) . toEqual ( {
58+ name : "repoList1" ,
59+ repositories : [ "foo/bar" , "foo/baz" ] ,
60+ } ) ;
61+ expect ( config . databases . remote . owners ) . toHaveLength ( 0 ) ;
62+ expect ( config . databases . remote . repositories ) . toHaveLength ( 3 ) ;
63+ expect ( config . databases . remote . repositories ) . toEqual ( [
64+ "owner/repo1" ,
65+ "owner/repo2" ,
66+ "owner/repo3" ,
67+ ] ) ;
68+ expect ( config . databases . local . lists ) . toHaveLength ( 2 ) ;
69+ expect ( config . databases . local . lists [ 0 ] ) . toEqual ( {
70+ name : "localList1" ,
71+ databases : [
72+ {
73+ name : "foo/bar" ,
74+ dateAdded : 1668096745193 ,
75+ language : "go" ,
76+ storagePath : "/path/to/database/" ,
77+ } ,
78+ ] ,
79+ } ) ;
80+ expect ( config . databases . local . databases ) . toHaveLength ( 1 ) ;
81+ expect ( config . databases . local . databases [ 0 ] ) . toEqual ( {
82+ name : "example-db" ,
83+ dateAdded : 1668096927267 ,
84+ language : "ruby" ,
85+ storagePath : "/path/to/database/" ,
86+ } ) ;
87+ expect ( config . selected ) . toEqual ( {
88+ kind : "remoteUserDefinedList" ,
89+ listName : "repoList1" ,
90+ } ) ;
91+
92+ configStore . dispose ( ) ;
8993 } ) ;
9094
91- configStore . dispose ( ) ;
92- } ) ;
93-
94- it ( "should load an existing config without selected db" , async ( ) => {
95- const testDataStoragePathWithout = join (
96- __dirname ,
97- "data" ,
98- "without-selected" ,
99- ) ;
95+ it ( "should load an existing config without selected db" , async ( ) => {
96+ const testDataStoragePathWithout = join (
97+ __dirname ,
98+ "data" ,
99+ "without-selected" ,
100+ ) ;
100101
101- const app = createMockApp ( {
102- extensionPath,
103- workspaceStoragePath : testDataStoragePathWithout ,
104- } ) ;
102+ const app = createMockApp ( {
103+ extensionPath,
104+ workspaceStoragePath : testDataStoragePathWithout ,
105+ } ) ;
105106
106- const configStore = new DbConfigStore ( app ) ;
107- await configStore . initialize ( ) ;
107+ const configStore = new DbConfigStore ( app ) ;
108+ await configStore . initialize ( ) ;
108109
109- const config = configStore . getConfig ( ) . value ;
110- expect ( config . selected ) . toBeUndefined ( ) ;
111-
112- configStore . dispose ( ) ;
113- } ) ;
110+ const config = configStore . getConfig ( ) . value ;
111+ expect ( config . selected ) . toBeUndefined ( ) ;
114112
115- it ( "should not allow modification of the config" , async ( ) => {
116- const app = createMockApp ( {
117- extensionPath,
118- workspaceStoragePath : testDataStoragePath ,
113+ configStore . dispose ( ) ;
119114 } ) ;
120- const configStore = new DbConfigStore ( app ) ;
121- await configStore . initialize ( ) ;
122115
123- const config = configStore . getConfig ( ) . value ;
124- config . databases . remote . repositoryLists = [ ] ;
116+ it ( "should not allow modification of the config" , async ( ) => {
117+ const app = createMockApp ( {
118+ extensionPath,
119+ workspaceStoragePath : testDataStoragePath ,
120+ } ) ;
121+ const configStore = new DbConfigStore ( app ) ;
122+ await configStore . initialize ( ) ;
125123
126- const reRetrievedConfig = configStore . getConfig ( ) . value ;
127- expect ( reRetrievedConfig . databases . remote . repositoryLists ) . toHaveLength ( 1 ) ;
124+ const config = configStore . getConfig ( ) . value ;
125+ config . databases . remote . repositoryLists = [ ] ;
128126
129- configStore . dispose ( ) ;
130- } ) ;
131-
132- it ( "should set codeQLDatabasesExperimental.configError to true when config has error" , async ( ) => {
133- const testDataStoragePathInvalid = join ( __dirname , "data" , "invalid" ) ;
127+ const reRetrievedConfig = configStore . getConfig ( ) . value ;
128+ expect ( reRetrievedConfig . databases . remote . repositoryLists ) . toHaveLength (
129+ 1 ,
130+ ) ;
134131
135- const app = createMockApp ( {
136- extensionPath,
137- workspaceStoragePath : testDataStoragePathInvalid ,
132+ configStore . dispose ( ) ;
138133 } ) ;
139- const configStore = new DbConfigStore ( app ) ;
140- await configStore . initialize ( ) ;
141-
142- expect ( app . executeCommand ) . toBeCalledWith (
143- "setContext" ,
144- "codeQLDatabasesExperimental.configError" ,
145- true ,
146- ) ;
147- configStore . dispose ( ) ;
148- } ) ;
149134
150- it ( "should set codeQLDatabasesExperimental.configError to false when config is valid" , async ( ) => {
151- const app = createMockApp ( {
152- extensionPath,
153- workspaceStoragePath : testDataStoragePath ,
135+ it ( "should set codeQLDatabasesExperimental.configError to true when config has error" , async ( ) => {
136+ const testDataStoragePathInvalid = join ( __dirname , "data" , "invalid" ) ;
137+
138+ const app = createMockApp ( {
139+ extensionPath,
140+ workspaceStoragePath : testDataStoragePathInvalid ,
141+ } ) ;
142+ const configStore = new DbConfigStore ( app ) ;
143+ await configStore . initialize ( ) ;
144+
145+ expect ( app . executeCommand ) . toBeCalledWith (
146+ "setContext" ,
147+ "codeQLDatabasesExperimental.configError" ,
148+ true ,
149+ ) ;
150+ configStore . dispose ( ) ;
154151 } ) ;
155- const configStore = new DbConfigStore ( app ) ;
156- await configStore . initialize ( ) ;
157152
158- expect ( app . executeCommand ) . toBeCalledWith (
159- "setContext" ,
160- "codeQLDatabasesExperimental.configError" ,
161- false ,
162- ) ;
163-
164- configStore . dispose ( ) ;
153+ it ( "should set codeQLDatabasesExperimental.configError to false when config is valid" , async ( ) => {
154+ const app = createMockApp ( {
155+ extensionPath,
156+ workspaceStoragePath : testDataStoragePath ,
157+ } ) ;
158+ const configStore = new DbConfigStore ( app ) ;
159+ await configStore . initialize ( ) ;
160+
161+ expect ( app . executeCommand ) . toBeCalledWith (
162+ "setContext" ,
163+ "codeQLDatabasesExperimental.configError" ,
164+ false ,
165+ ) ;
166+
167+ configStore . dispose ( ) ;
168+ } ) ;
165169 } ) ;
166170} ) ;
0 commit comments