Skip to content

Commit

Permalink
Fix: Reset connection when selecting new system type
Browse files Browse the repository at this point in the history
  • Loading branch information
IainSAP committed Dec 19, 2024
1 parent 112d29a commit add38bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ async function validateSystemSelection(
requiredOdataVersion?: OdataVersion
): Promise<ValidationResult> {
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;
Expand All @@ -88,9 +90,6 @@ async function validateSystemSelection(
connectionValidator,
requiredOdataVersion
);
} else if (systemSelection.type === 'cfAbapEnvService') {
// Reset previous selections connection state
connectionValidator.resetConnectionState(true);
}
return connectValResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit add38bb

Please sign in to comment.