Skip to content

Commit

Permalink
fix(abap-deploy-config-inquirer ): further cleanup based on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
longieirl committed Sep 17, 2024
1 parent 0fdd6b4 commit 0e0aa15
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
17 changes: 9 additions & 8 deletions packages/abap-deploy-config-inquirer/src/prompts/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,29 @@ export function showScpQuestion(previousAnswers: AbapDeployConfigAnswersInternal
}

/**
* Client condition to determine if the client question should be shown.
* Client condition to determine if the client question should be shown. Validates the SCP confirmation and project configuration properties.
*
* @param scp - is SCP system
* @param isS4HanaCloudSystem - is S/4 HANA Cloud system
* @returns boolean
*/
function showClientCondition(scp?: boolean, isS4HanaCloudSystem?: boolean): boolean {
return Boolean(!isAppStudio() && !scp && !isS4HanaCloudSystem);
function showClientCondition(scp?: boolean): boolean {
return Boolean(
!isAppStudio() && !PromptState.abapDeployConfig?.isS4HC && !scp && !PromptState.abapDeployConfig?.scp
);
}

/**
* Determines if the client choice question should be shown.
*
* @param scp - SCP
* @param previousAnswers - previous answers
* @param client - client
* @returns boolean
*/
export function showClientChoiceQuestion(scp?: boolean, client?: string): boolean {
export function showClientChoiceQuestion(previousAnswers?: AbapDeployConfigAnswersInternal, client?: string): boolean {
if (PromptState.isYUI || !client) {
return false;
}
return showClientCondition(scp, PromptState.abapDeployConfig?.isS4HC);
return showClientCondition(previousAnswers?.scp) && previousAnswers?.targetSystem === TargetSystemType.Url;
}

/**
Expand All @@ -83,7 +84,7 @@ export function showClientChoiceQuestion(scp?: boolean, client?: string): boolea
* @returns boolean
*/
export function showClientQuestion(previousAnswers?: AbapDeployConfigAnswersInternal): boolean {
const clientCondition = showClientCondition(previousAnswers?.scp, PromptState.abapDeployConfig?.isS4HC);
const clientCondition = showClientCondition(previousAnswers?.scp);
const isTargetUrl = previousAnswers?.targetSystem === TargetSystemType.Url;
const showCli = !PromptState.isYUI
? previousAnswers?.clientChoice === ClientChoiceValue.New || isTargetUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function getClientChoicePrompt(
const prompts: (ListQuestion<AbapDeployConfigAnswersInternal> | Question)[] = [
{
when: (previousAnswers: AbapDeployConfigAnswersInternal): boolean =>
showClientChoiceQuestion(previousAnswers?.scp, backendTarget?.abapTarget?.client),
showClientChoiceQuestion(previousAnswers, backendTarget?.abapTarget?.client),
type: 'list',
name: abapDeployConfigInternalPromptNames.clientChoice,
message: t('prompts.target.clientChoice.message'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,31 @@ describe('Test abap deploy config inquirer conditions', () => {
mockIsAppStudio.mockReturnValueOnce(false);
PromptState.isYUI = false;
PromptState.abapDeployConfig.isS4HC = false;
expect(showClientChoiceQuestion(false, '100')).toBe(true);
expect(
showClientChoiceQuestion({ scp: false, targetSystem: TargetSystemType.Url, url: '', package: '' }, '100')
).toBe(true);
PromptState.resetAbapDeployConfig();
// Should not show client choice question if SCP is enabled
PromptState.abapDeployConfig.isS4HC = false;
PromptState.abapDeployConfig.scp = true;
expect(
showClientChoiceQuestion({ scp: false, targetSystem: TargetSystemType.Url, url: '', package: '' }, '100')
).toBe(false);
PromptState.resetAbapDeployConfig();
// Should not show client choice question if target system is not a URL
PromptState.abapDeployConfig.isS4HC = false;
PromptState.abapDeployConfig.scp = true;
expect(showClientChoiceQuestion({ scp: true, url: '', package: '' }, '100')).toBe(false);
PromptState.resetAbapDeployConfig();
});

test('should not show client choice question', () => {
mockIsAppStudio.mockReturnValueOnce(false);
PromptState.isYUI = false;
PromptState.abapDeployConfig.isS4HC = true;
expect(showClientChoiceQuestion(true, undefined)).toBe(false);
expect(
showClientChoiceQuestion({ scp: true, targetSystem: TargetSystemType.Url, url: '', package: '' }, undefined)
).toBe(false);
PromptState.resetAbapDeployConfig();
});

Expand Down

0 comments on commit 0e0aa15

Please sign in to comment.