-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #976 from Klantinteractie-Servicesysteem/pc-554-di…
…gitale-adressen-opslaan-conform-validatieregels-ok2 Pc 554 digitale adressen opslaan conform validatieregels ok2
- Loading branch information
Showing
3 changed files
with
140 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import { parseDutchDate, parseBsn } from "@/helpers/validation"; | ||
import { | ||
parseDutchDate, | ||
parseBsn, | ||
TELEFOON_PATTERN, | ||
EMAIL_PATTERN, | ||
} from "@/helpers/validation"; | ||
|
||
describe("parseDutchDate", () => { | ||
test("should allow dd/MM/yyyy", async () => { | ||
|
@@ -52,7 +56,7 @@ describe("parseDutchDate", () => { | |
expect(parsed).toBeInstanceOf(Error); | ||
const error = parsed as Error; | ||
expect(error.message).toBe( | ||
"Voer een valide datum in, bijvoorbeeld 17-09-2022 of 17092022." | ||
"Voer een valide datum in, bijvoorbeeld 17-09-2022 of 17092022.", | ||
); | ||
}); | ||
|
||
|
@@ -61,7 +65,7 @@ describe("parseDutchDate", () => { | |
expect(parsed).toBeInstanceOf(Error); | ||
const error = parsed as Error; | ||
expect(error.message).toBe( | ||
"Voer een valide datum in, bijvoorbeeld 17-09-2022 of 17092022." | ||
"Voer een valide datum in, bijvoorbeeld 17-09-2022 of 17092022.", | ||
); | ||
}); | ||
}); | ||
|
@@ -84,3 +88,76 @@ describe("parseBsn", () => { | |
expect(parsedError.message).toBe("Voer een BSN in van negen cijfers."); | ||
}); | ||
}); | ||
|
||
describe("TELEFOON_PATTERN", () => { | ||
test("validates phone numbers correctly", () => { | ||
const testCases = [ | ||
{ number: "+31612345678", isValid: true }, | ||
{ number: "+441134960000", isValid: true }, | ||
{ number: "+12065550100", isValid: true }, | ||
{ number: "0612345678", isValid: true }, | ||
{ number: "09001234567", isValid: true }, | ||
{ number: "1400", isValid: true }, | ||
{ number: "14012", isValid: true }, | ||
{ number: "14079", isValid: true }, | ||
{ number: "0695azerty", isValid: false }, | ||
{ number: "azerty0545", isValid: false }, | ||
{ number: "@4566544++8", isValid: false }, | ||
{ number: "onetwothreefour", isValid: false }, | ||
{ number: "020 753 0523", isValid: false }, | ||
{ number: "+311234", isValid: false }, | ||
{ number: "0800852", isValid: false }, | ||
{ number: "080085285212", isValid: false }, | ||
]; | ||
|
||
testCases.forEach(({ number, isValid }) => | ||
expect(TELEFOON_PATTERN.test(number)).toBe(isValid), | ||
); | ||
}); | ||
}); | ||
|
||
describe("EMAIL_PATTERN", () => { | ||
test("validates email addresses correctly", () => { | ||
const testCases = [ | ||
{ email: "[email protected]", isValid: true }, | ||
{ email: "[email protected]", isValid: true }, | ||
{ email: "[email protected]", isValid: true }, | ||
{ email: "[email protected]", isValid: true }, | ||
{ email: `example@atm.${"a".repeat(63)}`, isValid: true }, | ||
{ email: `example@${"a".repeat(63)}.atm`, isValid: true }, | ||
{ | ||
email: `example@${"a".repeat(63)}.${"b".repeat(10)}.atm`, | ||
isValid: true, | ||
}, | ||
{ email: `example@atm.${"a".repeat(64)}`, isValid: false }, | ||
{ | ||
email: `example@${"b".repeat(64)}.atm.${"a".repeat(63)}.atm`, | ||
isValid: false, | ||
}, | ||
{ email: "", isValid: false }, | ||
{ email: "abc", isValid: false }, | ||
{ email: "abc@", isValid: false }, | ||
{ email: "abc@bar", isValid: false }, | ||
{ email: "a @x.cz", isValid: false }, | ||
{ email: "[email protected]", isValid: false }, | ||
{ email: `"test@test"@example.com`, isValid: false }, | ||
{ email: "something@@somewhere.com", isValid: false }, | ||
{ email: "[email protected]", isValid: false }, | ||
{ email: "[email protected]", isValid: false }, | ||
{ email: "[email protected]", isValid: false }, | ||
{ email: "[email protected]", isValid: false }, | ||
{ email: "[email protected]", isValid: false }, | ||
{ email: "[email protected]", isValid: false }, | ||
{ email: `[email protected]\n\n<script src="x.js">`, isValid: false }, | ||
{ email: "[email protected].", isValid: false }, | ||
{ email: `example@${"a".repeat(63)}.us`, isValid: true }, | ||
{ email: `example@${"a".repeat(64)}.us`, isValid: false }, | ||
{ email: "[email protected]\n", isValid: false }, | ||
{ email: "a\[email protected]", isValid: false }, | ||
]; | ||
|
||
testCases.forEach(({ email, isValid }) => | ||
expect(EMAIL_PATTERN.test(email)).toBe(isValid), | ||
); | ||
}); | ||
}); |