Skip to content

Commit

Permalink
fix(abap-deploy-config-inquirer ): add more tests around scp setter m…
Browse files Browse the repository at this point in the history
…ethod
  • Loading branch information
longieirl committed Sep 17, 2024
1 parent 0e0aa15 commit b244201
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '../../types';
import type { InputQuestion, ListQuestion, ConfirmQuestion, YUIQuestion } from '@sap-ux/inquirer-common';
import type { Question } from 'inquirer';
import { TargetSystemType } from '../../types';

/**
* Returns the destination prompt.
Expand Down Expand Up @@ -173,7 +174,14 @@ function getScpPrompt(backendTarget?: BackendTarget): Question<AbapDeployConfigA
prompts.push({
when: (answers: AbapDeployConfigAnswersInternal): boolean => {
const scpChoice = answers[abapDeployConfigInternalPromptNames.scp];
PromptState.abapDeployConfig.scp ||= scpChoice === true; // Keep this updated, will only reset to false if scp is not already true.
const targetChoice = answers[abapDeployConfigInternalPromptNames.targetSystem];
// scpChoice by default is true so only update state if target system is a URL
if (scpChoice && targetChoice === TargetSystemType.Url) {
PromptState.abapDeployConfig.scp = true;
} else if (targetChoice === TargetSystemType.Url) {
// Needs to be reset when user is toggling between scp and non-scp
PromptState.abapDeployConfig.scp = false;
}
return false;
},
name: abapDeployConfigInternalPromptNames.scpSetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ describe('getAbapTargetPrompts', () => {
})
).toBe(false);
expect(updateDestinationPromptStateSpy).toHaveBeenCalledWith('mockDest1', mockDestinations);
} else {
throw new Error('Destination setter prompt not found');
}
});

Expand Down Expand Up @@ -272,6 +274,8 @@ describe('getAbapTargetPrompts', () => {
})
).toBe(false);
expect(validateTargetSystemUrlCliSpy).toBeCalledTimes(1);
} else {
throw new Error('Target system setter prompt not found');
}
});

Expand Down Expand Up @@ -307,6 +311,9 @@ describe('getAbapTargetPrompts', () => {
backendTarget: { abapTarget: { scp: true } as UrlAbapTarget }
});
const scpPrompt = abapTargetPrompts.find((prompt) => prompt.name === abapDeployConfigInternalPromptNames.scp);
const scpSetterPrompt = abapTargetPrompts.find(
(prompt) => prompt.name === abapDeployConfigInternalPromptNames.scpSetter
);

if (scpPrompt) {
expect(
Expand All @@ -320,6 +327,30 @@ describe('getAbapTargetPrompts', () => {
} else {
throw new Error('Scp prompt not found');
}

if (scpSetterPrompt) {
PromptState.resetAbapDeployConfig();
expect(PromptState.abapDeployConfig.scp).toBeUndefined();
expect(
(scpSetterPrompt.when as Function)({
targetSystem: TargetSystemType.Url,
url: 'https://mock.target1.url.com',
scp: true
})
).toBe(false);
// Lets toggle the question
expect(
(scpSetterPrompt.when as Function)({
targetSystem: TargetSystemType.Url,
url: 'https://mock.target1.url.com',
scp: false
})
).toBe(false);
expect(PromptState.abapDeployConfig.scp).toBe(false);
} else {
throw new Error('Scp setter prompt not found');
}
PromptState.resetAbapDeployConfig();
});

test('should return expected values from client choice prompt methods', async () => {
Expand Down

0 comments on commit b244201

Please sign in to comment.