admin/validation/auth.test.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

80 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest'
import { CheckOtpFormValidation, CompleteProfileFormValidation, SendOtpFormValidation } from '@/validation/auth'
describe('authentication validation', () => {
it.each(['09123456789', '989123456789', '+989123456789', '۰۹۱۲۳۴۵۶۷۸۹'])('accepts a valid Iranian mobile: %s', (mobile) => {
expect(SendOtpFormValidation.safeParse({ mobile }).success).toBe(true)
})
it.each(['', '09123', '08123456789', '091234567890'])('rejects an invalid Iranian mobile: %s', (mobile) => {
expect(SendOtpFormValidation.safeParse({ mobile }).success).toBe(false)
})
it('rejects non-string mobile and OTP input', () => {
expect(SendOtpFormValidation.safeParse({ mobile: 9123456789 }).success).toBe(false)
expect(CheckOtpFormValidation.safeParse({ code: 1234 }).success).toBe(false)
})
it('normalizes Persian OTP digits and requires exactly four digits', () => {
expect(CheckOtpFormValidation.parse({ code: '۱۲۳۴' })).toEqual({ code: '1234' })
expect(CheckOtpFormValidation.safeParse({ code: '123' }).success).toBe(false)
expect(CheckOtpFormValidation.safeParse({ code: '12345' }).success).toBe(false)
expect(CheckOtpFormValidation.safeParse({ code: '123a' }).success).toBe(false)
})
it('trims profile names and restricts gender to supported values', () => {
expect(
CompleteProfileFormValidation.parse({
firstName: ' علی ',
lastName: ' رضایی ',
gender: 'male',
dateOfBirth: '1991-03-21',
cityId: '1',
})
).toEqual({
firstName: 'علی',
lastName: 'رضایی',
gender: 'male',
dateOfBirth: '1991-03-21',
cityId: '1',
})
expect(
CompleteProfileFormValidation.safeParse({
firstName: 'علی',
lastName: 'رضایی',
gender: 'unknown',
dateOfBirth: '1991-03-21',
cityId: '1',
}).success
).toBe(false)
})
it('requires a city while completing the profile', () => {
expect(
CompleteProfileFormValidation.safeParse({
firstName: 'علی',
lastName: 'رضایی',
gender: 'male',
dateOfBirth: '1991-03-21',
cityId: '',
}).success
).toBe(false)
})
it('requires a date of birth in Jalali years 13301395', () => {
expect(
CompleteProfileFormValidation.safeParse({ firstName: 'علی', lastName: 'رضایی', gender: 'male', dateOfBirth: '', cityId: '1' }).success
).toBe(false)
expect(
CompleteProfileFormValidation.safeParse({
firstName: 'علی',
lastName: 'رضایی',
gender: 'male',
dateOfBirth: '2018-01-01',
cityId: '1',
}).success
).toBe(false)
})
})