Add tests
This commit is contained in:
parent
c15a917e00
commit
d9c921e101
|
@ -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" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue