24 lines
808 B
TypeScript
24 lines
808 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { formatCard, normalizeCard, validCard } from './card'
|
|
|
|
describe('card utilities', () => {
|
|
it('normalizes Persian and Arabic digits with common separators', () => {
|
|
expect(normalizeCard('۶۰۳۷ ٩٩۷۵-۱۲۳۴ ۵۶۷۸')).toBe('6037997512345678')
|
|
})
|
|
|
|
it('keeps unexpected characters so validation can report them', () => {
|
|
expect(normalizeCard('6037 ABC 1234')).toBe('6037ABC1234')
|
|
})
|
|
|
|
it('accepts only sixteen ASCII digits', () => {
|
|
expect(validCard('6037997512345678')).toBe(true)
|
|
expect(validCard('603799751234567')).toBe(false)
|
|
expect(validCard('603799ABC2345678')).toBe(false)
|
|
})
|
|
|
|
it('groups a normalized card for display', () => {
|
|
expect(formatCard('6037997512345678')).toBe('6037 9975 1234 5678')
|
|
})
|
|
})
|