diff --git a/src/utils/sanitizer.utils.ts b/src/utils/sanitizer.utils.ts index 458998d..da4136b 100644 --- a/src/utils/sanitizer.utils.ts +++ b/src/utils/sanitizer.utils.ts @@ -22,13 +22,13 @@ function cleanNrcc(input: string) { // Remove newlines and then

tags from in export function removeNewlineAndPTag(input: string): string { const regex = /[\n\r]|<\/?p[^>]*>/g; - return input.replace(regex, (match) => { + return input.replace(regex, function(match) { if (match === "\n" || match === "\r") { return ""; } else { return ""; } - }) + }); } async function getDomainFromEmail(mail: string) { // Needs testing diff --git a/src/utils/translators/ldb/staffStation.ts b/src/utils/translators/ldb/staffStation.ts index 34d45a3..f282ac0 100644 --- a/src/utils/translators/ldb/staffStation.ts +++ b/src/utils/translators/ldb/staffStation.ts @@ -13,7 +13,7 @@ export function transform(input: any): StaffLdb | null { generatedAt: transformDateTime(data?.generatedAt) || new Date(), locationName: data?.locationName || "Not Found", stationManagerCode: data?.stationManagerCode || "UK", - nrccMessages: transformNrcc(data?.nrccMessages), + nrccMessages: transformNrcc(data?.nrccMessages) || undefined, trainServices: transformTrainServices(data?.trainServices), busServices: transformTrainServices(data?.busServices), ferryServices: transformTrainServices(data?.ferryServices) @@ -32,7 +32,7 @@ function transformDateTime(input: string): Date { function transformNrcc(input: any): NrccMessage[] { let output: NrccMessage[] = [] if (!Array.isArray(input?.message)) { - input.message = [input.message] + input.message = [input?.message] } for (const item of input?.message) { let message: NrccMessage = { diff --git a/test/utils/sanitizer.utils.test.ts b/test/utils/sanitizer.utils.test.ts new file mode 100644 index 0000000..d506cbd --- /dev/null +++ b/test/utils/sanitizer.utils.test.ts @@ -0,0 +1,9 @@ +import { removeNewlineAndPTag } from "../../src/utils/sanitizer.utils"; + +describe('sanitizer', () => { + test('Should remove /\n and

/

elements', () => { + const input = "\n

This is a string

"; + const expectedOutput = "This is a string" + expect(removeNewlineAndPTag(input)).toEqual(expectedOutput); + }); +}); \ No newline at end of file diff --git a/test/utils/translators/ldb/staffStation.utils.test.ts b/test/utils/translators/ldb/staffStation.utils.test.ts index e2c492e..1ee6409 100644 --- a/test/utils/translators/ldb/staffStation.utils.test.ts +++ b/test/utils/translators/ldb/staffStation.utils.test.ts @@ -1,7 +1,7 @@ import { transform } from "../../../../src/utils/translators/ldb/staffStation"; -import { inputs } from "./stationInputs.test.data"; -import { outputs } from "./stationOutputs.test.data"; +import { inputs } from "./stationInputs"; +import { outputs } from "./stationOutputs"; describe('transform', () => { test('Should return null for empty input', () => { diff --git a/test/utils/translators/ldb/stationInputs.test.data.ts b/test/utils/translators/ldb/stationInputs.ts similarity index 100% rename from test/utils/translators/ldb/stationInputs.test.data.ts rename to test/utils/translators/ldb/stationInputs.ts diff --git a/test/utils/translators/ldb/stationOutputs.test.data.ts b/test/utils/translators/ldb/stationOutputs.ts similarity index 100% rename from test/utils/translators/ldb/stationOutputs.test.data.ts rename to test/utils/translators/ldb/stationOutputs.ts