Skip to content

Commit

Permalink
feat: add connection successful message in system selection prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilko01 committed Jan 8, 2025
1 parent 59b3ce9 commit ef44a9c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions packages/odata-service-inquirer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit ef44a9c

Please sign in to comment.