@@ -291,30 +291,52 @@ describe('Unit: Command > Config', function () {
291
291
} ) ;
292
292
293
293
it ( 'calls handleAdvancedOptions without prompts if no-prompt is set' , function ( ) {
294
- const getInstanceStub = sinon . stub ( ) . returns ( { } ) ;
294
+ const checkEnvironmentStub = sinon . stub ( ) ;
295
+ const getInstanceStub = sinon . stub ( ) . returns ( { checkEnvironment : checkEnvironmentStub } ) ;
295
296
296
297
const config = new ConfigCommand ( { } , { getInstance : getInstanceStub } ) ;
297
298
const getConfigPromptsStub = sinon . stub ( config , 'getConfigPrompts' ) . returns ( [ ] ) ;
298
299
const handleAdvancedOptionsStub = sinon . stub ( config , 'handleAdvancedOptions' ) . resolves ( { result : true } ) ;
299
300
300
301
return config . run ( { prompt : false } ) . then ( ( result ) => {
301
302
expect ( result ) . to . deep . equal ( { result : true } ) ;
303
+ expect ( checkEnvironmentStub . calledOnce ) . to . be . true ;
302
304
expect ( getConfigPromptsStub . calledOnce ) . to . be . true ;
303
305
expect ( getConfigPromptsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : false } ) ;
304
306
expect ( handleAdvancedOptionsStub . calledOnce ) . to . be . true ;
305
307
expect ( handleAdvancedOptionsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : false } ) ;
306
308
} ) ;
307
309
} ) ;
308
310
311
+ it ( 'does not call checkEnvironment if ignoreEnvCheck is passed' , function ( ) {
312
+ const checkEnvironmentStub = sinon . stub ( ) ;
313
+ const getInstanceStub = sinon . stub ( ) . returns ( { checkEnvironment : checkEnvironmentStub } ) ;
314
+
315
+ const config = new ConfigCommand ( { } , { getInstance : getInstanceStub } ) ;
316
+ const getConfigPromptsStub = sinon . stub ( config , 'getConfigPrompts' ) . returns ( [ ] ) ;
317
+ const handleAdvancedOptionsStub = sinon . stub ( config , 'handleAdvancedOptions' ) . resolves ( { result : true } ) ;
318
+
319
+ return config . run ( { prompt : false , ignoreEnvCheck : true } ) . then ( ( result ) => {
320
+ expect ( result ) . to . deep . equal ( { result : true } ) ;
321
+ expect ( checkEnvironmentStub . called ) . to . be . false ;
322
+ expect ( getConfigPromptsStub . calledOnce ) . to . be . true ;
323
+ expect ( getConfigPromptsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : false , ignoreEnvCheck : true } ) ;
324
+ expect ( handleAdvancedOptionsStub . calledOnce ) . to . be . true ;
325
+ expect ( handleAdvancedOptionsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : false , ignoreEnvCheck : true } ) ;
326
+ } ) ;
327
+ } ) ;
328
+
309
329
it ( 'calls handleAdvancedOptions without prompts if no prompts are needed' , function ( ) {
310
- const getInstanceStub = sinon . stub ( ) . returns ( { } ) ;
330
+ const checkEnvironmentStub = sinon . stub ( ) ;
331
+ const getInstanceStub = sinon . stub ( ) . returns ( { checkEnvironment : checkEnvironmentStub } ) ;
311
332
312
333
const config = new ConfigCommand ( { } , { getInstance : getInstanceStub } ) ;
313
334
const getConfigPromptsStub = sinon . stub ( config , 'getConfigPrompts' ) . returns ( [ ] ) ;
314
335
const handleAdvancedOptionsStub = sinon . stub ( config , 'handleAdvancedOptions' ) . resolves ( { result : true } ) ;
315
336
316
337
return config . run ( { prompt : true } ) . then ( ( result ) => {
317
338
expect ( result ) . to . deep . equal ( { result : true } ) ;
339
+ expect ( checkEnvironmentStub . calledOnce ) . to . be . true ;
318
340
expect ( getConfigPromptsStub . calledOnce ) . to . be . true ;
319
341
expect ( getConfigPromptsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : true } ) ;
320
342
expect ( handleAdvancedOptionsStub . calledOnce ) . to . be . true ;
@@ -323,7 +345,8 @@ describe('Unit: Command > Config', function () {
323
345
} ) ;
324
346
325
347
it ( 'prompts with defined prompts, passes result to handleAdvancedOptions' , function ( ) {
326
- const getInstanceStub = sinon . stub ( ) . returns ( { } ) ;
348
+ const checkEnvironmentStub = sinon . stub ( ) ;
349
+ const getInstanceStub = sinon . stub ( ) . returns ( { checkEnvironment : checkEnvironmentStub } ) ;
327
350
const promptStub = sinon . stub ( ) . resolves ( { } ) ;
328
351
329
352
const config = new ConfigCommand ( { prompt : promptStub } , { getInstance : getInstanceStub } ) ;
@@ -332,6 +355,7 @@ describe('Unit: Command > Config', function () {
332
355
333
356
return config . run ( { prompt : true } ) . then ( ( result ) => {
334
357
expect ( result ) . to . deep . equal ( { result : true } ) ;
358
+ expect ( checkEnvironmentStub . calledOnce ) . to . be . true ;
335
359
expect ( getConfigPromptsStub . calledOnce ) . to . be . true ;
336
360
expect ( getConfigPromptsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : true } ) ;
337
361
expect ( promptStub . calledOnce ) . to . be . true ;
@@ -342,7 +366,8 @@ describe('Unit: Command > Config', function () {
342
366
} ) ;
343
367
344
368
it ( 'sets db to mysql if dbhost is provided via prompts' , function ( ) {
345
- const getInstanceStub = sinon . stub ( ) . returns ( { } ) ;
369
+ const checkEnvironmentStub = sinon . stub ( ) ;
370
+ const getInstanceStub = sinon . stub ( ) . returns ( { checkEnvironment : checkEnvironmentStub } ) ;
346
371
const promptStub = sinon . stub ( ) . resolves ( { dbhost : 'localhost' } ) ;
347
372
348
373
const config = new ConfigCommand ( { prompt : promptStub } , { getInstance : getInstanceStub } ) ;
@@ -351,6 +376,7 @@ describe('Unit: Command > Config', function () {
351
376
352
377
return config . run ( { prompt : true } ) . then ( ( result ) => {
353
378
expect ( result ) . to . deep . equal ( { result : true } ) ;
379
+ expect ( checkEnvironmentStub . calledOnce ) . to . be . true ;
354
380
expect ( getConfigPromptsStub . calledOnce ) . to . be . true ;
355
381
expect ( getConfigPromptsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : true , db : 'mysql' , dbhost : 'localhost' } ) ;
356
382
expect ( promptStub . calledOnce ) . to . be . true ;
@@ -361,7 +387,8 @@ describe('Unit: Command > Config', function () {
361
387
} ) ;
362
388
363
389
it ( 'doesn\'t add null prompt values to argv object' , function ( ) {
364
- const getInstanceStub = sinon . stub ( ) . returns ( { } ) ;
390
+ const checkEnvironmentStub = sinon . stub ( ) ;
391
+ const getInstanceStub = sinon . stub ( ) . returns ( { checkEnvironment : checkEnvironmentStub } ) ;
365
392
const promptStub = sinon . stub ( ) . resolves ( { dbhost : 'localhost' , dbpass : '' } ) ;
366
393
367
394
const config = new ConfigCommand ( { prompt : promptStub } , { getInstance : getInstanceStub } ) ;
@@ -370,6 +397,7 @@ describe('Unit: Command > Config', function () {
370
397
371
398
return config . run ( { prompt : true } ) . then ( ( result ) => {
372
399
expect ( result ) . to . deep . equal ( { result : true } ) ;
400
+ expect ( checkEnvironmentStub . calledOnce ) . to . be . true ;
373
401
expect ( getConfigPromptsStub . calledOnce ) . to . be . true ;
374
402
expect ( getConfigPromptsStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( { prompt : true , db : 'mysql' , dbhost : 'localhost' } ) ;
375
403
expect ( promptStub . calledOnce ) . to . be . true ;
0 commit comments