diff --git a/packages/odata-service-inquirer/src/prompts/datasources/sap-system/system-selection/questions.ts b/packages/odata-service-inquirer/src/prompts/datasources/sap-system/system-selection/questions.ts index 6cbc26a044..712fb92ceb 100644 --- a/packages/odata-service-inquirer/src/prompts/datasources/sap-system/system-selection/questions.ts +++ b/packages/odata-service-inquirer/src/prompts/datasources/sap-system/system-selection/questions.ts @@ -64,7 +64,9 @@ async function validateSystemSelection( requiredOdataVersion?: OdataVersion ): Promise { PromptState.reset(); - if (systemSelection.type === 'newSystemChoice') { + if (systemSelection.type === 'newSystemChoice' || systemSelection.type === 'cfAbapEnvService') { + // Reset the connection state + connectionValidator.resetConnectionState(true); return true; } let connectValResult: ValidationResult = false; @@ -88,9 +90,6 @@ async function validateSystemSelection( connectionValidator, requiredOdataVersion ); - } else if (systemSelection.type === 'cfAbapEnvService') { - // Reset previous selections connection state - connectionValidator.resetConnectionState(true); } return connectValResult; } diff --git a/packages/odata-service-inquirer/test/unit/prompts/sap-system/system-selection/questions.test.ts b/packages/odata-service-inquirer/test/unit/prompts/sap-system/system-selection/questions.test.ts index ef8ac7990b..21de01b1f9 100644 --- a/packages/odata-service-inquirer/test/unit/prompts/sap-system/system-selection/questions.test.ts +++ b/packages/odata-service-inquirer/test/unit/prompts/sap-system/system-selection/questions.test.ts @@ -318,18 +318,29 @@ describe('Test system selection prompts', () => { ); }); - test('Should reset the connection state when the source system `cfAbapEnvService`', async () => { + test('Should reset the connection state when the source system `cfAbapEnvService` or `newSystemChoice`', async () => { const connectValidator = new ConnectionValidator(); (getPromptHostEnvironment as jest.Mock).mockReturnValue(hostEnvironment.cli); mockIsAppStudio = true; - const systemConnectionQuestions = await getSystemConnectionQuestions(connectValidator); - const systemSelectionPrompt = systemConnectionQuestions[0] as ListQuestion; + let systemConnectionQuestions = await getSystemConnectionQuestions(connectValidator); + let systemSelectionPrompt = systemConnectionQuestions[0] as ListQuestion; expect( await systemSelectionPrompt.validate?.({ type: 'cfAbapEnvService', system: 'cfAbapEnvService' } as SystemSelectionAnswerType) - ).toBe(false); + ).toBe(true); + expect(resetConnectionState).toHaveBeenCalled(); + + mockIsAppStudio = false; + systemConnectionQuestions = await getSystemConnectionQuestions(connectValidator); + systemSelectionPrompt = systemConnectionQuestions[0] as ListQuestion; + expect( + await systemSelectionPrompt.validate?.({ + type: 'newSystemChoice', + system: '!@£*&937newSystem*X~qy^' + } as SystemSelectionAnswerType) + ).toBe(true); expect(resetConnectionState).toHaveBeenCalled(); });