backend/test/utils/sanitizer.utils.test.ts
Fred Boniface 9ab6741243 Additional tests
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-08-01 23:09:20 +01:00

32 lines
1009 B
TypeScript

import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
import { removeNonNumeric } from "../../src/utils/sanitizer.utils";
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"
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']
for (const key in inputs) {
const input = inputs[key];
const desired = expectedOutputs[key];
test(`Should return only numbers: ${key}`, () => {
expect(removeNonNumeric(input)).toEqual(desired);
})
}
})