Add max limit

This commit is contained in:
Adria Navarro 2024-01-02 15:16:09 +01:00
parent e50cc35140
commit 5609db3545
2 changed files with 19 additions and 0 deletions

View File

@ -1,4 +1,5 @@
const MIN_LENGTH = 8 const MIN_LENGTH = 8
const MAX_LENGTH = 100
export function validatePassword( export function validatePassword(
password: string password: string
@ -10,5 +11,12 @@ export function validatePassword(
} }
} }
if (password.length > MAX_LENGTH) {
return {
valid: false,
error: "Password invalid. Maximum hundred characters.",
}
}
return { valid: true } return { valid: true }
} }

View File

@ -1,3 +1,4 @@
import { generator } from "../../../tests"
import { validatePassword } from "../auth" import { validatePassword } from "../auth"
describe("auth", () => { describe("auth", () => {
@ -16,5 +17,15 @@ describe("auth", () => {
error: "Password invalid. Minimum eight characters.", error: "Password invalid. Minimum eight characters.",
}) })
}) })
it.each([
generator.word({ length: 101 }),
generator.paragraph().substring(0, 101),
])("limit password length", password => {
expect(validatePassword(password as string)).toEqual({
valid: false,
error: "Password invalid. Maximum hundred characters.",
})
})
}) })
}) })