42 lines
1.8 KiB
TypeScript
42 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
|
||
import { CreateBankAccountFormValidation, CreateWithdrawalRequestFormValidation } from '@/validation/withdrawal'
|
||
|
||
describe('financial form validation', () => {
|
||
it('normalizes and validates Iranian IBAN values', () => {
|
||
const result = CreateBankAccountFormValidation(false).parse({
|
||
iban: 'ir12 3456 7890 1234 5678 9012 34',
|
||
nationalCode: '',
|
||
})
|
||
|
||
expect(result.iban).toBe('IR123456789012345678901234')
|
||
})
|
||
|
||
it.each(['IR123', 'DE123456789012345678901234', 'IR12345678901234567890123A'])('rejects an invalid IBAN: %s', (iban) => {
|
||
expect(CreateBankAccountFormValidation(false).safeParse({ iban, nationalCode: '' }).success).toBe(false)
|
||
})
|
||
|
||
it('normalizes Persian digits for IBAN and nationalCode', () => {
|
||
const result = CreateBankAccountFormValidation(true).parse({
|
||
iban: 'ir۱۲ ۳۴۵۶ ۷۸۹۰ ۱۲۳۴ ۵۶۷۸ ۹۰۱۲ ۳۴',
|
||
nationalCode: '۰۰۱۲۳۴۵۶۷۸',
|
||
})
|
||
|
||
expect(result.iban).toBe('IR123456789012345678901234')
|
||
expect(result.nationalCode).toBe('0012345678')
|
||
})
|
||
|
||
it('requires nationalCode when identity is not verified', () => {
|
||
expect(CreateBankAccountFormValidation(true).safeParse({ iban: 'IR123456789012345678901234' }).success).toBe(false)
|
||
expect(
|
||
CreateBankAccountFormValidation(true).safeParse({ iban: 'IR123456789012345678901234', nationalCode: '0012345678' }).success
|
||
).toBe(true)
|
||
})
|
||
|
||
it('accepts only positive integer withdrawal amounts', () => {
|
||
expect(CreateWithdrawalRequestFormValidation.safeParse({ bankAccountId: 'bank-1', amount: '100000' }).success).toBe(true)
|
||
expect(CreateWithdrawalRequestFormValidation.safeParse({ bankAccountId: 'bank-1', amount: '0' }).success).toBe(false)
|
||
expect(CreateWithdrawalRequestFormValidation.safeParse({ bankAccountId: 'bank-1', amount: '12.5' }).success).toBe(false)
|
||
})
|
||
})
|