Add tests

This commit is contained in:
Adria Navarro 2024-01-02 12:56:08 +01:00
parent c15a917e00
commit d9c921e101
2 changed files with 21 additions and 1 deletions

View File

@ -3,7 +3,7 @@ const MIN_LENGTH = 8
export function validatePassword( export function validatePassword(
password: string password: string
): { valid: true } | { valid: false; error: string } { ): { valid: true } | { valid: false; error: string } {
if (password?.length < MIN_LENGTH) { if (!password || password.length < MIN_LENGTH) {
return { valid: false, error: "Password invalid. Minimum eight characters" } return { valid: false, error: "Password invalid. Minimum eight characters" }
} }

View File

@ -0,0 +1,20 @@
import { validatePassword } from "../auth"
describe("auth", () => {
describe("validatePassword", () => {
it("a valid password returns successful", () => {
expect(validatePassword("password")).toEqual({ valid: true })
})
it.each([
["undefined", undefined],
["null", null],
["empty", ""],
])("%s returns unsuccessful", (_, password) => {
expect(validatePassword(password as string)).toEqual({
valid: false,
error: "Password invalid. Minimum eight characters",
})
})
})
})