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 1330–1395', () => { 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) }) })