@@ -3,57 +3,39 @@ import envs from '../../../src/cmds/envs'
3
3
4
4
import { fromEnvsAddCmd } from '../../fixtures/configs'
5
5
6
- jest . mock ( 'configstore' ) ;
6
+ const makeOutput = config => {
7
+ const output = {
8
+ ...config
9
+ }
10
+
11
+ // @ts -ignore
12
+ output . apiToken = config [ 'api-token' ]
13
+ delete output [ 'api-token' ]
7
14
15
+ return output
16
+ }
17
+
18
+ jest . mock ( 'configstore' ) ;
8
19
const mockedConfigstore = jest . mocked ( configStore , true )
9
20
10
- describe ( 'Add command' , ( ) => {
11
- const envName = 'boron'
21
+ it ( 'should call correctly the config store to set an entry' , ( ) => {
12
22
const set = mockedConfigstore . mock . instances [ 0 ] . set as jest . Mock
13
23
envs ( {
14
- _ : [ 'add' , envName ] ,
24
+ _ : [ 'add' , 'env1' ] ,
15
25
...fromEnvsAddCmd
16
26
} )
27
+ expect ( set ) . toHaveBeenCalledTimes ( 1 )
17
28
18
- it ( 'should call correctly the config store to set an entry' , ( ) => {
19
- expect ( set ) . toHaveBeenCalled ( )
20
-
21
- const [ key , config ] = set . mock . calls [ 0 ]
22
-
23
- expect ( key ) . toBe ( `envs.${ envName } ` )
24
-
25
- const output = {
26
- ...fromEnvsAddCmd
27
- }
29
+ expect ( set . mock . calls [ 0 ] [ 0 ] ) . toBe ( `envs.env1` )
30
+ expect ( set . mock . calls [ 0 ] [ 1 ] ) . toStrictEqual ( makeOutput ( fromEnvsAddCmd ) )
28
31
29
- // @ts -ignore
30
- output . apiToken = fromEnvsAddCmd [ 'api-token' ]
31
- delete output [ 'api-token' ]
32
- expect ( config ) . toStrictEqual ( output )
33
- } ) ;
34
-
35
- it ( 'should update correctly an entry in the config store ' , ( ) => {
36
- const dataTopdate = {
37
- ...fromEnvsAddCmd ,
38
- endpoint : 'https://endpoint.fake'
39
- }
40
- envs ( {
41
- _ : [ 'add' , envName ] ,
42
- ...dataTopdate
43
- } )
44
-
45
- const [ key , config ] = set . mock . calls [ 1 ]
46
-
47
- expect ( key ) . toBe ( `envs.${ envName } ` )
48
-
49
- const output = {
50
- ...fromEnvsAddCmd ,
51
- ...dataTopdate
52
- }
32
+ // With --api-token only
33
+ envs ( {
34
+ _ : [ 'add' , 'env2' ] ,
35
+ 'api-token' : fromEnvsAddCmd [ 'api-token' ]
36
+ } )
53
37
54
- // @ts -ignore
55
- output . apiToken = fromEnvsAddCmd [ 'api-token' ]
56
- delete output [ 'api-token' ]
57
- expect ( config ) . toStrictEqual ( output )
58
- } ) ;
59
- } )
38
+ expect ( set ) . toHaveBeenCalledTimes ( 2 )
39
+ expect ( set . mock . calls [ 1 ] [ 0 ] ) . toBe ( `envs.env2` )
40
+ expect ( set . mock . calls [ 1 ] [ 1 ] ) . toStrictEqual ( makeOutput ( { 'api-token' : fromEnvsAddCmd [ 'api-token' ] } ) )
41
+ } ) ;
0 commit comments