Skip to content

Commit

Permalink
2734/allow support to apend abap filter types (#2735)
Browse files Browse the repository at this point in the history
* tbi(inq-common): add support to read additional service types

* tbi(inq-common): add changeset

* tbi(inq-common): cleanup code

* tbi(inq-common): update readme
  • Loading branch information
longieirl authored Jan 8, 2025
1 parent 25b9191 commit 40ba546
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-ducks-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/inquirer-common': patch
---

Add support to read additional ABAP service types
29 changes: 29 additions & 0 deletions packages/inquirer-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

Commonly used shared functionality that supports prompting. Currently used by inquirer modules for example `@sap-ux/ui5-application-inquirer`, `@sap-ux/ui5-library-inquirer`. For example, choice searching and UI5 choice grouping. Add functionality that may be used by multiple prompting modules to prompte re-use.

## Extending ABAP Service Offerings

The default list of ABAP service name types can be extended to allow customised ABAP service plans to be shown during the Cloud Foundry ABAP environment flow.

Supported list of technical service name types;

```TypeScript
[
AbapEnvType.ABAP,
AbapEnvType.ABAP_TRIAL,
AbapEnvType.ABAP_CANARY,
AbapEnvType.ABAP_OEM,
AbapEnvType.ABAP_OEM_CANARY,
AbapEnvType.ABAP_HAAS,
AbapEnvType.ABAP_STAGING,
AbapEnvType.ABAP_INTERNAL_STAGING
]
```

Configure the `ABAPEnvServiceTypes` environment variable with either a single or comma separated list, to update the existing list;

```bash
# Single
export ABAPEnvServiceTypes=abap-staging
# Multiple
export ABAPEnvServiceTypes=abap-staging,abap-internal
```



## License

Expand Down
9 changes: 8 additions & 1 deletion packages/inquirer-common/src/prompts/cf-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export async function getCFAbapInstanceChoices(
AbapEnvType.ABAP_STAGING,
AbapEnvType.ABAP_INTERNAL_STAGING
];
const serviceInstanceInfo: ServiceInstanceInfo[] = await getServicesInstances(filteredInstances);
// Load additional ABAP service types to extend the filtered instance list
const envFilteredInstances = process.env.ABAPEnvServiceTypes
? process.env.ABAPEnvServiceTypes.split(',').map((item) => item.trim())
: [];
const serviceInstanceInfo: ServiceInstanceInfo[] = await getServicesInstances([
...filteredInstances,
...envFilteredInstances
]);
if (serviceInstanceInfo.length > 0) {
serviceInstanceInfo.forEach((service) => {
choices.push({ name: service['label'], value: service });
Expand Down
17 changes: 16 additions & 1 deletion packages/inquirer-common/test/unit/prompts/cf-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { initI18nInquirerCommon, t } from '../../../src/i18n';
import { getCFAbapInstanceChoices } from '../../../src/prompts/cf-helper';

let cfAbapServices: ServiceInstanceInfo[] = [];

jest.mock('@sap/cf-tools', () => ({
...jest.requireActual('@sap/cf-tools'),
apiGetServicesInstancesFilteredByType: jest.fn().mockImplementation(() => cfAbapServices)
}));

describe('cf-helper', () => {
beforeEach(() => {
jest.clearAllMocks();
});

beforeAll(async () => {
await initI18nInquirerCommon();
});
Expand All @@ -37,4 +40,16 @@ describe('cf-helper', () => {
expect(await getCFAbapInstanceChoices(errorHandler)).toEqual([]);
expect(logErrorMsgsSpy).toHaveBeenCalledWith(ERROR_TYPE.NO_ABAP_ENVS, t('errors.abapEnvsCFDiscoveryFailed'));
});

test('should append ABAP service types when loading ABAP instances', async () => {
// Reset
cfAbapServices = [];
// Pass instances
process.env.ABAPEnvServiceTypes = 'TestInternal, internal';
expect(await getCFAbapInstanceChoices(new ErrorHandler())).toEqual([]);
expect(apiGetServicesInstancesFilteredByType).toBeCalledWith(
expect.arrayContaining(['TestInternal', 'internal'])
);
delete process.env.ABAPEnvServiceTypes;
});
});

0 comments on commit 40ba546

Please sign in to comment.