Run prettier

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface
2023-08-26 00:38:26 +01:00
parent c7b1c547b0
commit 31f104f51b
74 changed files with 520386 additions and 1121 deletions

View File

@@ -1,9 +1,9 @@
import { removeNewlineAndPTag } from "../../src/utils/newSanitizer";
describe('newSanitizer', () => {
test('Should remove /\n and <p>/</p> elements', () => {
describe("newSanitizer", () => {
test("Should remove /\n and <p>/</p> elements", () => {
const input = "\n<p>This is a string</p>";
const expectedOutput = "This is a string"
const expectedOutput = "This is a string";
expect(removeNewlineAndPTag(input)).toEqual(expectedOutput);
});
});
});

View File

@@ -1,31 +1,31 @@
import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
import { removeNonNumeric } from "../../src/utils/sanitizer.utils";
describe('Sanitize Email', () => {
describe("Sanitize Email", () => {
const inputs = [
"this+is+an-_email@example.com",
'"unusual email"@example.com',
"(brackets)addr@example.com",
"I%Have{Special}%Characters@example.com",
"Basic.address@example.com",
`"very.(),:;<>[]\".VERY.\"very\ \"very\".unusual"@example.com`
]
const expectedOutput = "example.com"
`"very.(),:;<>[]\".VERY.\"very\ \"very\".unusual"@example.com`,
];
const expectedOutput = "example.com";
for (const addr of inputs) {
test(`Should return only domain: ${addr}`, () => {
expect(getDomainFromEmail(addr)).toEqual(expectedOutput);
})
});
}
});
describe('Remove non-numeric', () => {
const inputs = ['abc123','<%43)($£@:}jfkd4']
const expectedOutputs = ['123','434']
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);
})
});
}
})
});

View File

@@ -1,45 +1,43 @@
import {
transform,
calculateLength
} from "../../../../src/utils/translators/ldb/staffStation";
import {
transform,
calculateLength,
} from "../../../../src/utils/translators/ldb/staffStation";
import { inputs } from "./stationInputs";
import { outputs } from "./stationOutputs";
import { noLength as serviceNoLength } from "./trainServiceInputs";
import { trainServices } from "./trainServiceInputs";
describe('transform', () => {
test('Should return null for empty input', () => {
describe("transform", () => {
test("Should return null for empty input", () => {
const input = {};
expect(transform(input)).toBeNull();
});
for (const testNo in inputs) {
test(`Should correctly transform data ${testNo}`, () => {
const input = inputs[testNo]
const expectedOutput = outputs[testNo]
const input = inputs[testNo];
const expectedOutput = outputs[testNo];
expect(transform(input)).toEqual(expectedOutput);
});
}
});
// Write test for calculateLength(input: TrainServices): number | undefined
describe('calculateLength', () => {
test('Should return ubdefined for no length', () => {
describe("calculateLength", () => {
test("Should return ubdefined for no length", () => {
const input = serviceNoLength;
expect(calculateLength(input)).toBeUndefined();
});
for (const testNo in trainServices) {
test(`Should correctly calculate ${testNo}`, () => {
const input = trainServices[testNo]
const expectedOutput = 4
const input = trainServices[testNo];
const expectedOutput = 4;
expect(calculateLength(input)).toEqual(expectedOutput);
});
}
});
});

View File

@@ -1,19 +1,19 @@
export const inputs: any[] = [
{
GetBoardResult: {
generatedAt: '2023-08-01T20:37:05.559123+01:00',
locationName: 'Railway Station',
crs: 'RLY',
stationManager: 'Network Rail',
stationManagerCode: 'RT',
generatedAt: "2023-08-01T20:37:05.559123+01:00",
locationName: "Railway Station",
crs: "RLY",
stationManager: "Network Rail",
stationManagerCode: "RT",
nrccMessages: {
message: {
severity: "minor",
xhtmlMessage: '\n<p>Minor Alert</p>',
type: "station"
}
xhtmlMessage: "\n<p>Minor Alert</p>",
type: "station",
},
},
isTruncated: 'true',
isTruncated: "true",
trainServices: {
service: [
{
@@ -36,21 +36,21 @@ export const inputs: any[] = [
location: {
locationName: "Plymouth",
crs: "PLY",
tiploc: "PLYMTH"
}
tiploc: "PLYMTH",
},
},
destination: {
location: {
locationName: "Birmingham New Street",
crs: "BHM",
tiploc: "BHAMNWS"
}
tiploc: "BHAMNWS",
},
},
category: "XX",
activities: "T",
}
]
}
}
},
],
},
},
},
]
];

View File

@@ -1,5 +1,9 @@
import type { StaffLdb, NrccMessage, TrainServices,
ServiceLocation } from '@owlboard/ts-types';
import type {
StaffLdb,
NrccMessage,
TrainServices,
ServiceLocation,
} from "@owlboard/ts-types";
export const outputs: StaffLdb[] = [
{
@@ -9,8 +13,8 @@ export const outputs: StaffLdb[] = [
nrccMessages: [
{
severity: "minor",
xhtmlMessage: "Minor Alert"
}
xhtmlMessage: "Minor Alert",
},
],
trainServices: [
{
@@ -28,17 +32,17 @@ export const outputs: StaffLdb[] = [
length: 10,
origin: [
{
tiploc: "PLYMTH"
}
tiploc: "PLYMTH",
},
],
destination: [
{
tiploc: "BHAMNWS"
}
]
}
tiploc: "BHAMNWS",
},
],
},
],
busServices: [],
ferryServices: []
ferryServices: [],
},
]
];

View File

@@ -1,41 +1,149 @@
import type { TrainServices } from "@owlboard/ts-types";
export const noLength: any = {
"rid": "202308058004480",
"uid": "P04480",
"trainid": "1A39",
"sdd": "2023-08-05",
"operator": "Great Western Railway",
"operatorCode": "GW",
"sta": "2023-08-05T21:51:00",
"eta": "2023-08-05T23:04:18",
"arrivalType": "Forecast",
"std": "2023-08-05T22:00:00",
"etd": "2023-08-05T23:05:18",
"departureType": "Forecast",
"departureSource": "Darwin",
"platform": "7",
"origin": {
"location": {
"locationName": "Penzance",
"crs": "PNZ",
"tiploc": "PENZNCE"
}
rid: "202308058004480",
uid: "P04480",
trainid: "1A39",
sdd: "2023-08-05",
operator: "Great Western Railway",
operatorCode: "GW",
sta: "2023-08-05T21:51:00",
eta: "2023-08-05T23:04:18",
arrivalType: "Forecast",
std: "2023-08-05T22:00:00",
etd: "2023-08-05T23:05:18",
departureType: "Forecast",
departureSource: "Darwin",
platform: "7",
origin: {
location: {
locationName: "Penzance",
crs: "PNZ",
tiploc: "PENZNCE",
},
},
"destination": {
"location": {
"locationName": "London Paddington",
"crs": "PAD",
"tiploc": "PADTON"
}
destination: {
location: {
locationName: "London Paddington",
crs: "PAD",
tiploc: "PADTON",
},
},
"delayReason": "887",
"category": "XX",
"activities": "T"
}
delayReason: "887",
category: "XX",
activities: "T",
};
export const trainServices: any[] = [
{"rid":"202308058005927","uid":"P05927","trainid":"2T53","sdd":"2023-08-05","operator":"Great Western Railway","operatorCode":"GW","sta":"2023-08-05T19:52:00","eta":"2023-08-05T19:52:00","arrivalType":"Forecast","std":"2023-08-05T19:56:00","etd":"2023-08-05T19:56:00","departureType":"Forecast","departureSource":"Darwin","platform":"2","formation":{"coaches":{"coach":[{"coachClass":"Standard"},{"coachClass":"Standard"},{"coachClass":"Standard"},{"coachClass":"Standard"}]}},"origin":{"location":{"locationName":"Worcester Foregate Street","crs":"WOF","tiploc":"WORCSFS"}},"destination":{"location":{"locationName":"Bristol Temple Meads","crs":"BRI","tiploc":"BRSTLTM","via":"via Gloucester"}},"category":"OO","activities":"T"},
{"rid":"202308057126314","uid":"G26314","trainid":"2V88","sdd":"2023-08-05","operator":"West Midlands Trains","operatorCode":"LM","sta":"2023-08-05T18:28:00","eta":"2023-08-05T18:28:00","arrivalType":"Forecast","std":"2023-08-05T18:33:00","etd":"2023-08-05T18:33:00","departureType":"Forecast","departureSource":"Darwin","platform":"2","formation":{"coaches":{"coach":[{"coachClass":"Standard"},{"coachClass":"Standard","toilet":"Accessible"},{"coachClass":"Standard"},{"coachClass":"Standard","toilet":"Accessible"}]}},"origin":{"location":{"locationName":"Dorridge","crs":"DDG","tiploc":"DORIDGE"}},"destination":{"location":{"locationName":"Worcester Foregate Street","crs":"WOF","tiploc":"WORCSFS"}},"category":"OO","activities":"T RM","length":"4"},
{"rid":"202308057126318","uid":"G26318","trainid":"2V96","sdd":"2023-08-05","operator":"West Midlands Trains","operatorCode":"LM","sta":"2023-08-05T19:28:00","eta":"2023-08-05T19:28:00","arrivalType":"Forecast","std":"2023-08-05T19:33:00","etd":"2023-08-05T19:33:00","departureType":"Forecast","departureSource":"Darwin","platform":"2","origin":{"location":{"locationName":"Dorridge","crs":"DDG","tiploc":"DORIDGE"}},"destination":{"location":{"locationName":"Worcester Foregate Street","crs":"WOF","tiploc":"WORCSFS"}},"category":"OO","activities":"T RM","length":"4"}
]
{
rid: "202308058005927",
uid: "P05927",
trainid: "2T53",
sdd: "2023-08-05",
operator: "Great Western Railway",
operatorCode: "GW",
sta: "2023-08-05T19:52:00",
eta: "2023-08-05T19:52:00",
arrivalType: "Forecast",
std: "2023-08-05T19:56:00",
etd: "2023-08-05T19:56:00",
departureType: "Forecast",
departureSource: "Darwin",
platform: "2",
formation: {
coaches: {
coach: [
{ coachClass: "Standard" },
{ coachClass: "Standard" },
{ coachClass: "Standard" },
{ coachClass: "Standard" },
],
},
},
origin: {
location: {
locationName: "Worcester Foregate Street",
crs: "WOF",
tiploc: "WORCSFS",
},
},
destination: {
location: {
locationName: "Bristol Temple Meads",
crs: "BRI",
tiploc: "BRSTLTM",
via: "via Gloucester",
},
},
category: "OO",
activities: "T",
},
{
rid: "202308057126314",
uid: "G26314",
trainid: "2V88",
sdd: "2023-08-05",
operator: "West Midlands Trains",
operatorCode: "LM",
sta: "2023-08-05T18:28:00",
eta: "2023-08-05T18:28:00",
arrivalType: "Forecast",
std: "2023-08-05T18:33:00",
etd: "2023-08-05T18:33:00",
departureType: "Forecast",
departureSource: "Darwin",
platform: "2",
formation: {
coaches: {
coach: [
{ coachClass: "Standard" },
{ coachClass: "Standard", toilet: "Accessible" },
{ coachClass: "Standard" },
{ coachClass: "Standard", toilet: "Accessible" },
],
},
},
origin: {
location: { locationName: "Dorridge", crs: "DDG", tiploc: "DORIDGE" },
},
destination: {
location: {
locationName: "Worcester Foregate Street",
crs: "WOF",
tiploc: "WORCSFS",
},
},
category: "OO",
activities: "T RM",
length: "4",
},
{
rid: "202308057126318",
uid: "G26318",
trainid: "2V96",
sdd: "2023-08-05",
operator: "West Midlands Trains",
operatorCode: "LM",
sta: "2023-08-05T19:28:00",
eta: "2023-08-05T19:28:00",
arrivalType: "Forecast",
std: "2023-08-05T19:33:00",
etd: "2023-08-05T19:33:00",
departureType: "Forecast",
departureSource: "Darwin",
platform: "2",
origin: {
location: { locationName: "Dorridge", crs: "DDG", tiploc: "DORIDGE" },
},
destination: {
location: {
locationName: "Worcester Foregate Street",
crs: "WOF",
tiploc: "WORCSFS",
},
},
category: "OO",
activities: "T RM",
length: "4",
},
];