Add max limit
This commit is contained in:
parent
e50cc35140
commit
5609db3545
|
@ -1,4 +1,5 @@
|
|||
const MIN_LENGTH = 8
|
||||
const MAX_LENGTH = 100
|
||||
|
||||
export function validatePassword(
|
||||
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 }
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { generator } from "../../../tests"
|
||||
import { validatePassword } from "../auth"
|
||||
|
||||
describe("auth", () => {
|
||||
|
@ -16,5 +17,15 @@ describe("auth", () => {
|
|||
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.",
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue