Additional tests
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
2d2fdbb8db
commit
9ab6741243
@ -63,12 +63,12 @@ function transformTrainServices(input: any): TrainServices[] {
|
|||||||
uid: service?.uid,
|
uid: service?.uid,
|
||||||
trainid: service?.trainid,
|
trainid: service?.trainid,
|
||||||
operatorCode: service?.operatorCode || 'UK',
|
operatorCode: service?.operatorCode || 'UK',
|
||||||
platform: service?.platform || '',
|
platform: service?.platform || '-',
|
||||||
platformIsHidden: service?.platformIsHidden || '',
|
platformIsHidden: service?.platformIsHidden,
|
||||||
serviceIsSupressed: service?.serviceIsSupressed || '',
|
serviceIsSupressed: service?.serviceIsSupressed,
|
||||||
origin: transformLocation(service?.origin),
|
origin: transformLocation(service?.origin),
|
||||||
destination: transformLocation(service?.destination),
|
destination: transformLocation(service?.destination),
|
||||||
isCancelled: service?.isCancelled || '',
|
isCancelled: service?.isCancelled,
|
||||||
cancelReason: service?.cancelReason,
|
cancelReason: service?.cancelReason,
|
||||||
delayReason: service?.delayReason,
|
delayReason: service?.delayReason,
|
||||||
arrivalType: service?.arrivalType,
|
arrivalType: service?.arrivalType,
|
||||||
@ -80,6 +80,7 @@ function transformTrainServices(input: any): TrainServices[] {
|
|||||||
etd: transformUnspecifiedDateTime(service?.etd),
|
etd: transformUnspecifiedDateTime(service?.etd),
|
||||||
atd: transformUnspecifiedDateTime(service?.atd),
|
atd: transformUnspecifiedDateTime(service?.atd),
|
||||||
}
|
}
|
||||||
|
Object.keys(trainService).forEach(key => trainService[key] === undefined && delete trainService[key]);
|
||||||
output.push(trainService)
|
output.push(trainService)
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
@ -101,8 +102,11 @@ function transformLocation(input: any): ServiceLocation[] {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformUnspecifiedDateTime(input: string): Date {
|
function transformUnspecifiedDateTime(input: string): Date | undefined {
|
||||||
console.debug(`staffStation.transformUnspecifiedDateTime running`)
|
console.debug(`staffStation.transformUnspecifiedDateTime running`)
|
||||||
|
if (!input) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
const date = tz(input, "Europe/London");
|
const date = tz(input, "Europe/London");
|
||||||
return date.toDate()
|
return date.toDate()
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
|
import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
|
||||||
|
import { removeNonNumeric } from "../../src/utils/sanitizer.utils";
|
||||||
|
|
||||||
describe('Sanitize Email', () => {
|
describe('Sanitize Email', () => {
|
||||||
const inputs = [
|
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);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ -13,7 +13,7 @@ export const outputs: any[] = [
|
|||||||
{
|
{
|
||||||
rid: "202308017159276",
|
rid: "202308017159276",
|
||||||
uid: "G59276",
|
uid: "G59276",
|
||||||
trainuid: "1M83",
|
trainid: "1M83",
|
||||||
operatorCode: "XC",
|
operatorCode: "XC",
|
||||||
sta: expect.any(Date),
|
sta: expect.any(Date),
|
||||||
ata: expect.any(Date),
|
ata: expect.any(Date),
|
||||||
|
Loading…
Reference in New Issue
Block a user