Skip to content

Commit d5676bd

Browse files
committed
CL-2062 | +Harshi | Fix skip environment variables option with --variable-type flag
1 parent 1f3dc69 commit d5676bd

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/adapters/base-class.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,45 @@ describe('BaseClass', () => {
189189
expect(printAllVariablesMock).toHaveBeenCalled();
190190
expect(baseClass.envVariables).toEqual(expectedEnv);
191191
});
192+
193+
it('should handle variableType passed as string from command line flag', async () => {
194+
baseClass = new BaseClass({
195+
log: logMock,
196+
exit: exitMock,
197+
config: {
198+
variableType: 'Skip adding environment variables',
199+
variablePreparationTypeOptions: config.variablePreparationTypeOptions,
200+
},
201+
} as any);
202+
203+
await baseClass.handleEnvImportFlow();
204+
205+
expect(baseClass.envVariables).toEqual([]);
206+
expect(logMock).toHaveBeenCalledWith('Skipped adding environment variables.', 'info');
207+
expect(exitMock).not.toHaveBeenCalled();
208+
});
209+
210+
it('should handle variableType string and not trigger "cannot be combined" error', async () => {
211+
baseClass = new BaseClass({
212+
log: logMock,
213+
exit: exitMock,
214+
config: {
215+
variableType: 'Import variables from a stack',
216+
variablePreparationTypeOptions: config.variablePreparationTypeOptions,
217+
},
218+
} as any);
219+
220+
const importEnvFromStackMock = jest.spyOn(baseClass, 'importEnvFromStack').mockResolvedValueOnce();
221+
222+
await baseClass.handleEnvImportFlow();
223+
224+
expect(importEnvFromStackMock).toHaveBeenCalled();
225+
expect(exitMock).not.toHaveBeenCalled();
226+
expect(logMock).not.toHaveBeenCalledWith(
227+
expect.stringContaining("cannot be combined"),
228+
'error',
229+
);
230+
});
192231
});
193232

194233
describe('importVariableFromLocalConfig', () => {

src/adapters/base-class.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ export default class BaseClass {
504504
* @memberof BaseClass
505505
*/
506506
async handleEnvImportFlow(): Promise<void> {
507-
const variablePreparationType =
507+
let variablePreparationType: string | string[] =
508508
this.config.variableType ||
509509
(await ux.inquire({
510510
type: 'checkbox',
@@ -514,6 +514,10 @@ export default class BaseClass {
514514
message: 'Import variables from a stack and/or manually add custom variables to the list',
515515
}));
516516

517+
if (typeof variablePreparationType === 'string') {
518+
variablePreparationType = [variablePreparationType];
519+
}
520+
517521
if (variablePreparationType.length === 0) {
518522
this.log('Please select at least one option by pressing <space>, then press <enter> to proceed.', 'error');
519523
this.exit(1);

0 commit comments

Comments
 (0)