From ef44a9ccfab8039e03c70cc1e265f2ad339c9866 Mon Sep 17 00:00:00 2001 From: mmilko01 Date: Wed, 8 Jan 2025 17:01:27 +0200 Subject: [PATCH] feat: add connection successful message in system selection prompt --- .../sap-system/system-selection/questions.ts | 11 +++++- .../odata-service-inquirer.i18n.json | 3 +- packages/odata-service-inquirer/src/types.ts | 5 +++ .../system-selection/questions.test.ts | 37 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) 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 5aff1bd817..395e04c93e 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 @@ -188,12 +188,21 @@ export async function getSystemConnectionQuestions( if (promptOptions?.systemSelection?.useAutoComplete && (selectedSystem as ListChoiceOptions).value) { selectedSystemAnswer = (selectedSystem as ListChoiceOptions).value; } - // TODO: Show message when connection is successful return ( validateSystemSelection(selectedSystemAnswer, connectionValidator, requiredOdataVersion) ?? false ); }, additionalMessages: async (selectedSystem: SystemSelectionAnswerType) => { + // Show message if connection to selected system is successful and showConnectionSuccessMessage is enabled + if ( + promptOptions?.systemSelection?.showConnectionSuccessMessage && + (connectionValidator.validity.authenticated || connectionValidator.validity.authRequired === false) + ) { + return { + message: t('prompts.systemSelection.connectionSuccessMessage'), + severity: Severity.information + }; + } // Backend systems credentials may need to be updated if ( selectedSystem.type === 'backendSystem' && diff --git a/packages/odata-service-inquirer/src/translations/odata-service-inquirer.i18n.json b/packages/odata-service-inquirer/src/translations/odata-service-inquirer.i18n.json index f259fa4189..58a75fa4e5 100644 --- a/packages/odata-service-inquirer/src/translations/odata-service-inquirer.i18n.json +++ b/packages/odata-service-inquirer/src/translations/odata-service-inquirer.i18n.json @@ -103,7 +103,8 @@ "newSystemChoiceLabel": "New system", "hint": "Select a system configuration", "message": "System", - "authenticationFailedUpdateCredentials": "Authentication failed. Please try updating the credentials." + "authenticationFailedUpdateCredentials": "Authentication failed. Please try updating the credentials.", + "connectionSuccessMessage": "Connection successful" }, "abapOnBTPType": { "message": "ABAP environment definition source", diff --git a/packages/odata-service-inquirer/src/types.ts b/packages/odata-service-inquirer/src/types.ts index 37c7a332c1..19c7f6e8ae 100644 --- a/packages/odata-service-inquirer/src/types.ts +++ b/packages/odata-service-inquirer/src/types.ts @@ -268,6 +268,11 @@ export type SystemSelectionPromptOptions = { * this option will not be applied and the full list of choices will be presented to the user. */ onlyShowDefaultChoice?: boolean; + + /** + * Shows a message when the connection to the system is successful. + */ + showConnectionSuccessMessage?: boolean; }; export type MetadataPromptOptions = { 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 21de01b1f9..fe546409f2 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 @@ -630,4 +630,41 @@ describe('Test system selection prompts', () => { ); expect(serviceSelectionPrompt).toBeDefined(); }); + + test('Should show connestion success message when showConnectionSuccessMessage is provided as true and connections is successful', async () => { + const connectValidator = new ConnectionValidator(); + connectValidator.validity.authRequired = false; + connectValidator.validity.authenticated = true; + const systemSelectionQuestions = await getSystemConnectionQuestions(connectValidator, { + [promptNames.systemSelection]: { showConnectionSuccessMessage: true } + }); + const systemSelectionPrompt = systemSelectionQuestions.find( + (question) => question.name === promptNames.systemSelection + ); + expect((systemSelectionPrompt as ListQuestion).additionalMessages).toBeDefined(); + const additionalMessages = await (systemSelectionPrompt as ListQuestion).additionalMessages?.({ + type: 'backendSystem', + system: backendSystemBasic + } as SystemSelectionAnswerType); + expect(additionalMessages).toMatchObject({ + message: t('prompts.systemSelection.connectionSuccessMessage'), + severity: 2 + }); + }); + + test('Should not show connestion success message when showConnectionSuccessMessage is not provided and connections is successful', async () => { + const connectValidator = new ConnectionValidator(); + connectValidator.validity.authRequired = false; + connectValidator.validity.authenticated = true; + const systemSelectionQuestions = await getSystemConnectionQuestions(connectValidator); + const systemSelectionPrompt = systemSelectionQuestions.find( + (question) => question.name === promptNames.systemSelection + ); + expect((systemSelectionPrompt as ListQuestion).additionalMessages).toBeDefined(); + const additionalMessages = await (systemSelectionPrompt as ListQuestion).additionalMessages?.({ + type: 'backendSystem', + system: backendSystemBasic + } as SystemSelectionAnswerType); + expect(additionalMessages).not.toBeDefined(); + }); });