diff --git a/src/utils/translators/ldb/staffStation.ts b/src/utils/translators/ldb/staffStation.ts index 5647542..b9f26af 100644 --- a/src/utils/translators/ldb/staffStation.ts +++ b/src/utils/translators/ldb/staffStation.ts @@ -63,12 +63,12 @@ function transformTrainServices(input: any): TrainServices[] { uid: service?.uid, trainid: service?.trainid, operatorCode: service?.operatorCode || 'UK', - platform: service?.platform || '', - platformIsHidden: service?.platformIsHidden || '', - serviceIsSupressed: service?.serviceIsSupressed || '', + platform: service?.platform || '-', + platformIsHidden: service?.platformIsHidden, + serviceIsSupressed: service?.serviceIsSupressed, origin: transformLocation(service?.origin), destination: transformLocation(service?.destination), - isCancelled: service?.isCancelled || '', + isCancelled: service?.isCancelled, cancelReason: service?.cancelReason, delayReason: service?.delayReason, arrivalType: service?.arrivalType, @@ -80,6 +80,7 @@ function transformTrainServices(input: any): TrainServices[] { etd: transformUnspecifiedDateTime(service?.etd), atd: transformUnspecifiedDateTime(service?.atd), } + Object.keys(trainService).forEach(key => trainService[key] === undefined && delete trainService[key]); output.push(trainService) } return output @@ -101,8 +102,11 @@ function transformLocation(input: any): ServiceLocation[] { return output } -function transformUnspecifiedDateTime(input: string): Date { +function transformUnspecifiedDateTime(input: string): Date | undefined { console.debug(`staffStation.transformUnspecifiedDateTime running`) + if (!input) { + return undefined + } const date = tz(input, "Europe/London"); return date.toDate() } \ No newline at end of file diff --git a/test/utils/sanitizer.utils.test.ts b/test/utils/sanitizer.utils.test.ts index f7c80ce..a749f19 100644 --- a/test/utils/sanitizer.utils.test.ts +++ b/test/utils/sanitizer.utils.test.ts @@ -1,4 +1,5 @@ import { getDomainFromEmail } from "../../src/utils/sanitizer.utils"; +import { removeNonNumeric } from "../../src/utils/sanitizer.utils"; describe('Sanitize Email', () => { const inputs = [ @@ -16,3 +17,15 @@ describe('Sanitize Email', () => { }) } }); + +describe('Remove non-numeric', () => { + const inputs = ['abc123','<%43)($£@:}jfkd4'] + const expectedOutputs = ['123','434'] + for (const key in inputs) { + const input = inputs[key]; + const desired = expectedOutputs[key]; + test(`Should return only numbers: ${key}`, () => { + expect(removeNonNumeric(input)).toEqual(desired); + }) + } +}) diff --git a/test/utils/translators/ldb/stationOutputs.ts b/test/utils/translators/ldb/stationOutputs.ts index 2c0a146..a4c36f8 100644 --- a/test/utils/translators/ldb/stationOutputs.ts +++ b/test/utils/translators/ldb/stationOutputs.ts @@ -13,7 +13,7 @@ export const outputs: any[] = [ { rid: "202308017159276", uid: "G59276", - trainuid: "1M83", + trainid: "1M83", operatorCode: "XC", sta: expect.any(Date), ata: expect.any(Date),