@@ -14,7 +14,7 @@ describe("Data Importation Without Docker", () => {
14
14
process . env = { ...mockEnv } ; // Restore environment variables
15
15
} ) ;
16
16
17
- it ( "should import sample data if the database is empty and user opts to import sample data" , async ( ) => {
17
+ it ( "should import default data if the database is empty and user opts to import default data" , async ( ) => {
18
18
const checkDbMock = vi
19
19
. fn ( )
20
20
. mockImplementation ( async ( ) : Promise < boolean > => {
@@ -36,9 +36,46 @@ describe("Data Importation Without Docker", () => {
36
36
return Promise . resolve ( ) ;
37
37
} ) ;
38
38
vi . spyOn ( inquirer , "prompt" ) . mockResolvedValueOnce ( {
39
- shouldImportSampleData : true ,
39
+ shouldImportDefaultData : true ,
40
40
} ) ;
41
41
42
+ await dataImportWithoutDocker (
43
+ checkDbMock ,
44
+ wipeExistingDataMock ,
45
+ importDefaultDataMock ,
46
+ importDataMock ,
47
+ ) ;
48
+ expect ( checkDbMock ) . toBeCalled ( ) ;
49
+ expect ( wipeExistingDataMock ) . not . toBeCalled ( ) ;
50
+ expect ( importDefaultDataMock ) . toBeCalled ( ) ;
51
+ expect ( importDataMock ) . not . toBeCalled ( ) ;
52
+ } ) ;
53
+
54
+ it ( "should import sample data if the database is empty and user opts not to import default data but import sample data" , async ( ) => {
55
+ const checkDbMock = vi
56
+ . fn ( )
57
+ . mockImplementation ( async ( ) : Promise < boolean > => {
58
+ return true ;
59
+ } ) ;
60
+ const wipeExistingDataMock = vi
61
+ . fn ( )
62
+ . mockImplementation ( async ( ) : Promise < void > => {
63
+ return Promise . resolve ( ) ;
64
+ } ) ;
65
+ const importDataMock = vi
66
+ . fn ( )
67
+ . mockImplementation ( async ( ) : Promise < void > => {
68
+ return Promise . resolve ( ) ;
69
+ } ) ;
70
+ const importDefaultDataMock = vi
71
+ . fn ( )
72
+ . mockImplementation ( async ( ) : Promise < void > => {
73
+ return Promise . resolve ( ) ;
74
+ } ) ;
75
+ vi . spyOn ( inquirer , "prompt" )
76
+ . mockResolvedValueOnce ( { shouldImportDefaultData : false } )
77
+ . mockResolvedValueOnce ( { shouldImportSampleData : true } ) ;
78
+
42
79
await dataImportWithoutDocker (
43
80
checkDbMock ,
44
81
wipeExistingDataMock ,
@@ -51,7 +88,7 @@ describe("Data Importation Without Docker", () => {
51
88
expect ( importDataMock ) . toBeCalled ( ) ;
52
89
} ) ;
53
90
54
- it ( "should not import sample data if the database is empty and user opts not to import sample data" , async ( ) => {
91
+ it ( "should do no-op if the database is empty and user imports neither default nor sample data" , async ( ) => {
55
92
const checkDbMock = vi
56
93
. fn ( )
57
94
. mockImplementation ( async ( ) : Promise < boolean > => {
@@ -72,9 +109,9 @@ describe("Data Importation Without Docker", () => {
72
109
. mockImplementation ( async ( ) : Promise < void > => {
73
110
return Promise . resolve ( ) ;
74
111
} ) ;
75
- vi . spyOn ( inquirer , "prompt" ) . mockResolvedValueOnce ( {
76
- shouldImportSampleData : false ,
77
- } ) ;
112
+ vi . spyOn ( inquirer , "prompt" )
113
+ . mockResolvedValueOnce ( { shouldImportDefaultData : false } )
114
+ . mockResolvedValueOnce ( { shouldImportSampleData : false } ) ;
78
115
79
116
await dataImportWithoutDocker (
80
117
checkDbMock ,
@@ -84,7 +121,7 @@ describe("Data Importation Without Docker", () => {
84
121
) ;
85
122
expect ( checkDbMock ) . toBeCalled ( ) ;
86
123
expect ( wipeExistingDataMock ) . not . toBeCalled ( ) ;
87
- expect ( importDefaultDataMock ) . toBeCalled ( ) ;
124
+ expect ( importDefaultDataMock ) . not . toBeCalled ( ) ;
88
125
expect ( importDataMock ) . not . toBeCalled ( ) ;
89
126
} ) ;
90
127
@@ -111,7 +148,8 @@ describe("Data Importation Without Docker", () => {
111
148
} ) ;
112
149
vi . spyOn ( inquirer , "prompt" )
113
150
. mockResolvedValueOnce ( { shouldOverwriteData : true } )
114
- . mockResolvedValueOnce ( { importSampleData : true } ) ;
151
+ . mockResolvedValueOnce ( { overwriteDefaultData : false } )
152
+ . mockResolvedValueOnce ( { overwriteSampleData : true } ) ;
115
153
116
154
await dataImportWithoutDocker (
117
155
checkDbMock ,
@@ -125,7 +163,7 @@ describe("Data Importation Without Docker", () => {
125
163
expect ( importDataMock ) . toBeCalled ( ) ;
126
164
} ) ;
127
165
128
- it ( "should not import sample data if the database is not empty and user opts to overwrite and not import sample data" , async ( ) => {
166
+ it ( "should import default data if the database is not empty and user opts to overwrite and import default data" , async ( ) => {
129
167
const checkDbMock = vi
130
168
. fn ( )
131
169
. mockImplementation ( async ( ) : Promise < boolean > => {
@@ -148,7 +186,7 @@ describe("Data Importation Without Docker", () => {
148
186
} ) ;
149
187
vi . spyOn ( inquirer , "prompt" )
150
188
. mockResolvedValueOnce ( { shouldOverwriteData : true } )
151
- . mockResolvedValueOnce ( { importSampleData : false } ) ;
189
+ . mockResolvedValueOnce ( { overwriteDefaultData : true } ) ;
152
190
153
191
await dataImportWithoutDocker (
154
192
checkDbMock ,
@@ -162,7 +200,45 @@ describe("Data Importation Without Docker", () => {
162
200
expect ( importDataMock ) . not . toBeCalled ( ) ;
163
201
} ) ;
164
202
165
- it ( "should complete the data importation if the database is not empty and user does not opt to overwrite" , async ( ) => {
203
+ it ( "should do no-op if db not empty and user imports neither default nor sample data" , async ( ) => {
204
+ const checkDbMock = vi
205
+ . fn ( )
206
+ . mockImplementation ( async ( ) : Promise < boolean > => {
207
+ return false ;
208
+ } ) ;
209
+ const wipeExistingDataMock = vi
210
+ . fn ( )
211
+ . mockImplementation ( async ( ) : Promise < void > => {
212
+ return Promise . resolve ( ) ;
213
+ } ) ;
214
+ const importDataMock = vi
215
+ . fn ( )
216
+ . mockImplementation ( async ( ) : Promise < void > => {
217
+ return Promise . resolve ( ) ;
218
+ } ) ;
219
+ const importDefaultDataMock = vi
220
+ . fn ( )
221
+ . mockImplementation ( async ( ) : Promise < void > => {
222
+ return Promise . resolve ( ) ;
223
+ } ) ;
224
+ vi . spyOn ( inquirer , "prompt" )
225
+ . mockResolvedValueOnce ( { shouldOverwriteData : true } )
226
+ . mockResolvedValueOnce ( { overwriteDefaultData : false } )
227
+ . mockResolvedValueOnce ( { overwriteSampleData : false } ) ;
228
+
229
+ await dataImportWithoutDocker (
230
+ checkDbMock ,
231
+ wipeExistingDataMock ,
232
+ importDefaultDataMock ,
233
+ importDataMock ,
234
+ ) ;
235
+ expect ( checkDbMock ) . toBeCalled ( ) ;
236
+ expect ( wipeExistingDataMock ) . not . toBeCalled ( ) ;
237
+ expect ( importDefaultDataMock ) . not . toBeCalled ( ) ;
238
+ expect ( importDataMock ) . not . toBeCalled ( ) ;
239
+ } ) ;
240
+
241
+ it ( "should do no-op if db not empty and user opts not to overwrite" , async ( ) => {
166
242
const checkDbMock = vi
167
243
. fn ( )
168
244
. mockImplementation ( async ( ) : Promise < boolean > => {
@@ -250,7 +326,7 @@ describe("Data Importation With Docker", () => {
250
326
process . env = { ...mockEnv } ; // Restore environment variables
251
327
} ) ;
252
328
253
- it ( "should complete data importation if user opts not to start containers" , async ( ) => {
329
+ it ( "should do no-op if user opts not to start containers" , async ( ) => {
254
330
const runDockerComposeMock = vi
255
331
. fn ( )
256
332
. mockImplementation ( async ( ) : Promise < void > => {
@@ -361,6 +437,43 @@ describe("Data Importation With Docker", () => {
361
437
expect ( importDataMock ) . not . toBeCalled ( ) ;
362
438
} ) ;
363
439
440
+ it ( "should import default data if user opts to import default data" , async ( ) => {
441
+ const runDockerComposeMock = vi
442
+ . fn ( )
443
+ . mockImplementation ( async ( ) : Promise < void > => {
444
+ return Promise . resolve ( ) ;
445
+ } ) ;
446
+ const importDataMock = vi
447
+ . fn ( )
448
+ . mockImplementation ( async ( ) : Promise < void > => {
449
+ return Promise . resolve ( ) ;
450
+ } ) ;
451
+ const importDefaultDataMock = vi
452
+ . fn ( )
453
+ . mockImplementation ( async ( ) : Promise < void > => {
454
+ return Promise . resolve ( ) ;
455
+ } ) ;
456
+ const connectDatabaseMock = vi
457
+ . fn ( )
458
+ . mockImplementation ( async ( ) : Promise < void > => {
459
+ return Promise . resolve ( ) ;
460
+ } ) ;
461
+ vi . spyOn ( inquirer , "prompt" )
462
+ . mockResolvedValueOnce ( { shouldStartDockerContainers : true } )
463
+ . mockResolvedValueOnce ( { shouldImportDefaultData : true } ) ;
464
+
465
+ await dataImportWithDocker (
466
+ runDockerComposeMock ,
467
+ importDefaultDataMock ,
468
+ importDataMock ,
469
+ connectDatabaseMock ,
470
+ ) ;
471
+ expect ( runDockerComposeMock ) . toBeCalled ( ) ;
472
+ expect ( connectDatabaseMock ) . toBeCalled ( ) ;
473
+ expect ( importDefaultDataMock ) . toBeCalled ( ) ;
474
+ expect ( importDataMock ) . not . toBeCalled ( ) ;
475
+ } ) ;
476
+
364
477
it ( "should import sample data if user opts to import sample data" , async ( ) => {
365
478
const runDockerComposeMock = vi
366
479
. fn ( )
@@ -384,6 +497,7 @@ describe("Data Importation With Docker", () => {
384
497
} ) ;
385
498
vi . spyOn ( inquirer , "prompt" )
386
499
. mockResolvedValueOnce ( { shouldStartDockerContainers : true } )
500
+ . mockResolvedValueOnce ( { shouldImportDefaultData : false } )
387
501
. mockResolvedValueOnce ( { shouldImportSampleData : true } ) ;
388
502
389
503
await dataImportWithDocker (
@@ -398,7 +512,7 @@ describe("Data Importation With Docker", () => {
398
512
expect ( importDataMock ) . toBeCalled ( ) ;
399
513
} ) ;
400
514
401
- it ( "should import default data if user does not opt to import sample data" , async ( ) => {
515
+ it ( "should do no-op if user opts to import neither sample data nor default data" , async ( ) => {
402
516
const runDockerComposeMock = vi
403
517
. fn ( )
404
518
. mockImplementation ( async ( ) : Promise < void > => {
@@ -421,6 +535,7 @@ describe("Data Importation With Docker", () => {
421
535
} ) ;
422
536
vi . spyOn ( inquirer , "prompt" )
423
537
. mockResolvedValueOnce ( { shouldStartDockerContainers : true } )
538
+ . mockResolvedValueOnce ( { shouldImportDefaultData : false } )
424
539
. mockResolvedValueOnce ( { shouldImportSampleData : false } ) ;
425
540
426
541
await dataImportWithDocker (
@@ -431,7 +546,7 @@ describe("Data Importation With Docker", () => {
431
546
) ;
432
547
expect ( runDockerComposeMock ) . toBeCalled ( ) ;
433
548
expect ( connectDatabaseMock ) . toBeCalled ( ) ;
434
- expect ( importDefaultDataMock ) . toBeCalled ( ) ;
549
+ expect ( importDefaultDataMock ) . not . toBeCalled ( ) ;
435
550
expect ( importDataMock ) . not . toBeCalled ( ) ;
436
551
} ) ;
437
552
0 commit comments