From 80a80ea609c18b0bfaefd4d98596fc0c4e89d998 Mon Sep 17 00:00:00 2001 From: i057546 Date: Fri, 20 Sep 2024 13:50:44 +0100 Subject: [PATCH] Fixes ampersand escaping --- .../datasources/metadata-file/validators.ts | 4 +-- .../metadata-file/fixtures/validatorTest.xml | 28 +++++++++++++++++++ .../prompts/metadata-file/validators.test.ts | 12 ++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 packages/odata-service-inquirer/test/unit/prompts/metadata-file/fixtures/validatorTest.xml create mode 100644 packages/odata-service-inquirer/test/unit/prompts/metadata-file/validators.test.ts diff --git a/packages/odata-service-inquirer/src/prompts/datasources/metadata-file/validators.ts b/packages/odata-service-inquirer/src/prompts/datasources/metadata-file/validators.ts index 995036ff97..a10ab1416f 100644 --- a/packages/odata-service-inquirer/src/prompts/datasources/metadata-file/validators.ts +++ b/packages/odata-service-inquirer/src/prompts/datasources/metadata-file/validators.ts @@ -27,8 +27,8 @@ export const validateMetadataFile = async ( } try { - const metadata = await readFile(path, 'utf-8'); - metadata.replace(/ & /g, ' & '); + let metadata = await readFile(path, 'utf-8'); + metadata = metadata.replace(/ & /g, ' & '); const { validationMsg, version } = validateODataVersion(metadata, odataVersion); if (validationMsg) { return validationMsg; diff --git a/packages/odata-service-inquirer/test/unit/prompts/metadata-file/fixtures/validatorTest.xml b/packages/odata-service-inquirer/test/unit/prompts/metadata-file/fixtures/validatorTest.xml new file mode 100644 index 0000000000..fbce877b39 --- /dev/null +++ b/packages/odata-service-inquirer/test/unit/prompts/metadata-file/fixtures/validatorTest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/odata-service-inquirer/test/unit/prompts/metadata-file/validators.test.ts b/packages/odata-service-inquirer/test/unit/prompts/metadata-file/validators.test.ts new file mode 100644 index 0000000000..ab8b20b68f --- /dev/null +++ b/packages/odata-service-inquirer/test/unit/prompts/metadata-file/validators.test.ts @@ -0,0 +1,12 @@ +import path from 'path'; +import { validateMetadataFile } from '../../../../src/prompts/datasources/metadata-file/validators'; + +describe('metadata valiadtors', () => { + test('validateMetadataFile', async () => { + const testXmlPath = path.join(__dirname, 'fixtures/validatorTest.xml'); + expect(await validateMetadataFile(testXmlPath)).toMatchObject({ + version: '2', + metadata: expect.stringContaining('Terms & Conditions') //Ensure that the & is replaced with & + }); + }); +});