admin/validation/withdrawal.test.ts
2026-09-05 16:04:36 +03:30

42 lines
1.8 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 { 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)
})
})