newStaffLDB-API (#48)
Merge newStaffLDB-API into main. Ready to deploy Reviewed-on: #48
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
|
||||
import { removeNonNumeric } from "../../src/utils/sanitizer.utils";
|
||||
import { removeNonAlpha } from "../../src/utils/sanitizer.utils";
|
||||
import { removeNonAlphanumeric } from "../../src/utils/sanitizer.utils";
|
||||
|
||||
describe("Sanitize Email", () => {
|
||||
const inputs = [
|
||||
@@ -9,6 +11,7 @@ describe("Sanitize Email", () => {
|
||||
"I%Have{Special}%Characters@example.com",
|
||||
"Basic.address@example.com",
|
||||
`"very.(),:;<>[]\".VERY.\"very\ \"very\".unusual"@example.com`,
|
||||
"THIS_EMAIL_CONTAINS_CAPITALISED_DOMAIN@EXAMPLE.COM",
|
||||
];
|
||||
const expectedOutput = "example.com";
|
||||
for (const addr of inputs) {
|
||||
@@ -29,3 +32,31 @@ describe("Remove non-numeric", () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Remove non-Alpha", () => {
|
||||
const inputs = ["DROP/*comment*/sampletable", "10; DROP TABLE members /*"];
|
||||
const outputs = ["DROPcommentsampletable", "DROPTABLEmembers"];
|
||||
for (const key in inputs) {
|
||||
const input = inputs[key];
|
||||
const desired = outputs[key];
|
||||
test(`Should return with only letters: ${key}`, () => {
|
||||
expect(removeNonAlpha(input)).toEqual(desired);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Remove non-alphanumeric", () => {
|
||||
const inputs = [
|
||||
"DROP/*comment*/sampletable",
|
||||
"10; DROP TABLE members /*",
|
||||
"1F44",
|
||||
];
|
||||
const outputs = ["DROPcommentsampletable", "10DROPTABLEmembers", "1F44"];
|
||||
for (const key in inputs) {
|
||||
const input = inputs[key];
|
||||
const desired = outputs[key];
|
||||
test(`Should return with only alphanumeric: ${key}`, () => {
|
||||
expect(removeNonAlphanumeric(input)).toEqual(desired);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
17
test/utils/timeConvert.utils.test.ts
Normal file
17
test/utils/timeConvert.utils.test.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { jsUnix, unixLocal } from "../../src/utils/timeConvert.utils";
|
||||
|
||||
describe("Time Conversion", () => {
|
||||
test("Should return unix time (seconds)", () => {
|
||||
const now = new Date();
|
||||
const nowJs = now.getTime();
|
||||
const nowUnix = Math.floor(now.getTime() / 1000);
|
||||
expect(jsUnix(nowJs)).toEqual(nowUnix);
|
||||
});
|
||||
|
||||
test("Should return locale date string", () => {
|
||||
const now = new Date();
|
||||
const nowUnix = Math.floor(now.getTime() / 1000);
|
||||
const result = now.toLocaleString();
|
||||
expect(unixLocal(nowUnix)).toEqual(result);
|
||||
});
|
||||
});
|
||||
@@ -53,4 +53,51 @@ export const inputs: any[] = [
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
GetBoardResult: {
|
||||
generatedAt: "2023-08-01T20:37:05.559123+01:00",
|
||||
locationName: "Railway Station",
|
||||
crs: "RLY",
|
||||
stationManager: "Network Rail",
|
||||
stationManagerCode: "RT",
|
||||
isTruncated: "true",
|
||||
trainServices: {
|
||||
service: [
|
||||
{
|
||||
rid: "202308017159276",
|
||||
uid: "G59276",
|
||||
trainid: "1M83",
|
||||
sdd: "2023-08-01",
|
||||
operator: "CrossCountry",
|
||||
operatorCode: "XC",
|
||||
sta: "2023-08-01T20:24:00",
|
||||
ata: "2023-08-01T20:27:22",
|
||||
arrivalType: "Actual",
|
||||
std: "2023-08-01T20:35:00",
|
||||
etd: "2023-08-01T20:35:00",
|
||||
departureType: "Estimated",
|
||||
departureSource: "Darwin",
|
||||
platform: "5",
|
||||
length: "10",
|
||||
origin: {
|
||||
location: {
|
||||
locationName: "Plymouth",
|
||||
crs: "PLY",
|
||||
tiploc: "PLYMTH",
|
||||
},
|
||||
},
|
||||
destination: {
|
||||
location: {
|
||||
locationName: "Birmingham New Street",
|
||||
crs: "BHM",
|
||||
tiploc: "BHAMNWS",
|
||||
},
|
||||
},
|
||||
category: "XX",
|
||||
activities: "T",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -26,7 +26,40 @@ export const outputs: StaffLdb[] = [
|
||||
ata: expect.any(Date),
|
||||
arrivalType: "Actual",
|
||||
std: expect.any(Date),
|
||||
etd: expect.any(Date),
|
||||
etd: "RT",
|
||||
departureType: "Estimated",
|
||||
platform: "5",
|
||||
length: 10,
|
||||
origin: [
|
||||
{
|
||||
tiploc: "PLYMTH",
|
||||
},
|
||||
],
|
||||
destination: [
|
||||
{
|
||||
tiploc: "BHAMNWS",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
busServices: [],
|
||||
ferryServices: [],
|
||||
},
|
||||
{
|
||||
generatedAt: expect.any(Date),
|
||||
locationName: "Railway Station",
|
||||
stationManagerCode: "RT",
|
||||
trainServices: [
|
||||
{
|
||||
rid: "202308017159276",
|
||||
uid: "G59276",
|
||||
trainid: "1M83",
|
||||
operatorCode: "XC",
|
||||
sta: expect.any(Date),
|
||||
ata: expect.any(Date),
|
||||
arrivalType: "Actual",
|
||||
std: expect.any(Date),
|
||||
etd: "RT",
|
||||
departureType: "Estimated",
|
||||
platform: "5",
|
||||
length: 10,
|
||||
|
||||
Reference in New Issue
Block a user