Add additional test for sanitizer

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-09-28 20:02:58 +01:00
parent ee2cf6e7d5
commit 51baee45a3

View File

@ -1,5 +1,7 @@
import { getDomainFromEmail } from "../../src/utils/sanitizer.utils"; import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
import { removeNonNumeric } 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", () => { describe("Sanitize Email", () => {
const inputs = [ const inputs = [
@ -30,3 +32,27 @@ 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);
})
}
})