@@ -32,6 +32,99 @@ describe('BaseClass', () => {
3232 config : config . variablePreparationTypeOptions ,
3333 } as any ) ;
3434 } ) ;
35+
36+ it ( 'should handle string variableType by converting to array - Import variables from a stack' , async ( ) => {
37+ baseClass = new BaseClass ( {
38+ log : logMock ,
39+ exit : exitMock ,
40+ config : {
41+ variableType : 'Import variables from a stack' ,
42+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
43+ } ,
44+ } as any ) ;
45+
46+ const importEnvFromStackMock = jest . spyOn ( baseClass , 'importEnvFromStack' ) . mockResolvedValueOnce ( ) ;
47+
48+ await baseClass . handleEnvImportFlow ( ) ;
49+
50+ expect ( importEnvFromStackMock ) . toHaveBeenCalled ( ) ;
51+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
52+ } ) ;
53+
54+ it ( 'should handle string variableType by converting to array - Manually add custom variables to the list' , async ( ) => {
55+ baseClass = new BaseClass ( {
56+ log : logMock ,
57+ exit : exitMock ,
58+ config : {
59+ variableType : 'Manually add custom variables to the list' ,
60+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
61+ } ,
62+ } as any ) ;
63+
64+ const promptForEnvValuesMock = jest . spyOn ( baseClass , 'promptForEnvValues' ) . mockResolvedValueOnce ( ) ;
65+
66+ await baseClass . handleEnvImportFlow ( ) ;
67+
68+ expect ( promptForEnvValuesMock ) . toHaveBeenCalled ( ) ;
69+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
70+ } ) ;
71+
72+ it ( 'should handle string variableType by converting to array - Import variables from the .env.local file' , async ( ) => {
73+ baseClass = new BaseClass ( {
74+ log : logMock ,
75+ exit : exitMock ,
76+ config : {
77+ variableType : 'Import variables from the .env.local file' ,
78+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
79+ } ,
80+ } as any ) ;
81+
82+ const importVariableFromLocalConfigMock = jest
83+ . spyOn ( baseClass , 'importVariableFromLocalConfig' )
84+ . mockResolvedValueOnce ( ) ;
85+
86+ await baseClass . handleEnvImportFlow ( ) ;
87+
88+ expect ( importVariableFromLocalConfigMock ) . toHaveBeenCalled ( ) ;
89+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
90+ } ) ;
91+
92+ it ( 'should handle string variableType by converting to array - Skip adding environment variables' , async ( ) => {
93+ baseClass = new BaseClass ( {
94+ log : logMock ,
95+ exit : exitMock ,
96+ config : {
97+ variableType : 'Skip adding environment variables' ,
98+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
99+ } ,
100+ } as any ) ;
101+
102+ await baseClass . handleEnvImportFlow ( ) ;
103+
104+ expect ( baseClass . envVariables ) . toEqual ( [ ] ) ;
105+ expect ( logMock ) . toHaveBeenCalledWith ( 'Skipped adding environment variables.' , 'info' ) ;
106+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
107+ } ) ;
108+
109+ it ( 'should fail if string to array conversion is removed' , async ( ) => {
110+ baseClass = new BaseClass ( {
111+ log : logMock ,
112+ exit : exitMock ,
113+ config : {
114+ variableType : 'Skip adding environment variables' ,
115+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
116+ } ,
117+ } as any ) ;
118+
119+ await baseClass . handleEnvImportFlow ( ) ;
120+
121+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
122+ expect ( logMock ) . not . toHaveBeenCalledWith (
123+ "The 'Skip adding environment variables' option cannot be combined with other environment variable options. Please choose either 'Skip adding environment variables' or one or more of the other available options." ,
124+ 'error' ,
125+ ) ;
126+ } ) ;
127+
35128 it ( 'should exit if no options are selected' , async ( ) => {
36129 ( ux . inquire as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
37130
@@ -162,7 +255,7 @@ describe('BaseClass', () => {
162255 'Import variables from the .env.local file' ,
163256 ] ) ;
164257
165- await baseClass . handleEnvImportFlow ( ) ;
258+ await baseClass . handleEnvImportFlow ( ) ;
166259
167260 expect ( importEnvFromStackMock ) . toHaveBeenCalled ( ) ;
168261 expect ( promptForEnvValuesMock ) . toHaveBeenCalled ( ) ;
0 commit comments