@@ -125,6 +125,120 @@ describe('BaseClass', () => {
125125 ) ;
126126 } ) ;
127127
128+ it ( 'should handle two options: Import from stack and Manually add variables' , async ( ) => {
129+ baseClass = new BaseClass ( {
130+ log : logMock ,
131+ exit : exitMock ,
132+ config : {
133+ variableType : [ 'Import variables from a stack' , 'Manually add custom variables to the list' ] ,
134+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
135+ } ,
136+ } as any ) ;
137+
138+ const importEnvFromStackMock = jest . spyOn ( baseClass , 'importEnvFromStack' ) . mockResolvedValueOnce ( ) ;
139+ const promptForEnvValuesMock = jest . spyOn ( baseClass , 'promptForEnvValues' ) . mockResolvedValueOnce ( ) ;
140+
141+ await baseClass . handleEnvImportFlow ( ) ;
142+
143+ expect ( importEnvFromStackMock ) . toHaveBeenCalled ( ) ;
144+ expect ( promptForEnvValuesMock ) . toHaveBeenCalled ( ) ;
145+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
146+ } ) ;
147+
148+ it ( 'should handle two options: Import from stack and Import from .env.local' , async ( ) => {
149+ baseClass = new BaseClass ( {
150+ log : logMock ,
151+ exit : exitMock ,
152+ config : {
153+ variableType : [ 'Import variables from a stack' , 'Import variables from the .env.local file' ] ,
154+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
155+ } ,
156+ } as any ) ;
157+
158+ const importEnvFromStackMock = jest . spyOn ( baseClass , 'importEnvFromStack' ) . mockResolvedValueOnce ( ) ;
159+ const importVariableFromLocalConfigMock = jest
160+ . spyOn ( baseClass , 'importVariableFromLocalConfig' )
161+ . mockResolvedValueOnce ( ) ;
162+
163+ await baseClass . handleEnvImportFlow ( ) ;
164+
165+ expect ( importEnvFromStackMock ) . toHaveBeenCalled ( ) ;
166+ expect ( importVariableFromLocalConfigMock ) . toHaveBeenCalled ( ) ;
167+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
168+ } ) ;
169+
170+ it ( 'should handle two options: Manually add and Import from .env.local' , async ( ) => {
171+ baseClass = new BaseClass ( {
172+ log : logMock ,
173+ exit : exitMock ,
174+ config : {
175+ variableType : [ 'Manually add custom variables to the list' , 'Import variables from the .env.local file' ] ,
176+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
177+ } ,
178+ } as any ) ;
179+
180+ const promptForEnvValuesMock = jest . spyOn ( baseClass , 'promptForEnvValues' ) . mockResolvedValueOnce ( ) ;
181+ const importVariableFromLocalConfigMock = jest
182+ . spyOn ( baseClass , 'importVariableFromLocalConfig' )
183+ . mockResolvedValueOnce ( ) ;
184+
185+ await baseClass . handleEnvImportFlow ( ) ;
186+
187+ expect ( promptForEnvValuesMock ) . toHaveBeenCalled ( ) ;
188+ expect ( importVariableFromLocalConfigMock ) . toHaveBeenCalled ( ) ;
189+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
190+ } ) ;
191+
192+ it ( 'should handle all three options: Import from stack, Manually add, and Import from .env.local' , async ( ) => {
193+ baseClass = new BaseClass ( {
194+ log : logMock ,
195+ exit : exitMock ,
196+ config : {
197+ variableType : [
198+ 'Import variables from a stack' ,
199+ 'Manually add custom variables to the list' ,
200+ 'Import variables from the .env.local file' ,
201+ ] ,
202+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
203+ } ,
204+ } as any ) ;
205+
206+ const importEnvFromStackMock = jest . spyOn ( baseClass , 'importEnvFromStack' ) . mockResolvedValueOnce ( ) ;
207+ const promptForEnvValuesMock = jest . spyOn ( baseClass , 'promptForEnvValues' ) . mockResolvedValueOnce ( ) ;
208+ const importVariableFromLocalConfigMock = jest
209+ . spyOn ( baseClass , 'importVariableFromLocalConfig' )
210+ . mockResolvedValueOnce ( ) ;
211+
212+ await baseClass . handleEnvImportFlow ( ) ;
213+
214+ expect ( importEnvFromStackMock ) . toHaveBeenCalled ( ) ;
215+ expect ( promptForEnvValuesMock ) . toHaveBeenCalled ( ) ;
216+ expect ( importVariableFromLocalConfigMock ) . toHaveBeenCalled ( ) ;
217+ expect ( exitMock ) . not . toHaveBeenCalled ( ) ;
218+ } ) ;
219+
220+ it ( 'should fail when Skip is combined with other options' , async ( ) => {
221+ baseClass = new BaseClass ( {
222+ log : logMock ,
223+ exit : exitMock ,
224+ config : {
225+ variableType : [ 'Skip adding environment variables' , 'Import variables from a stack' ] ,
226+ variablePreparationTypeOptions : config . variablePreparationTypeOptions ,
227+ } ,
228+ } as any ) ;
229+
230+ const importEnvFromStackMock = jest . spyOn ( baseClass , 'importEnvFromStack' ) . mockResolvedValueOnce ( undefined ) ;
231+
232+ await baseClass . handleEnvImportFlow ( ) ;
233+
234+ expect ( logMock ) . toHaveBeenCalledWith (
235+ "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." ,
236+ 'error' ,
237+ ) ;
238+ expect ( exitMock ) . toHaveBeenCalledWith ( 1 ) ;
239+ expect ( importEnvFromStackMock ) . toHaveBeenCalled ( ) ;
240+ } ) ;
241+
128242 it ( 'should exit if no options are selected' , async ( ) => {
129243 ( ux . inquire as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
130244
0 commit comments