Files
zkxw/web-admin/src/utils/oa-receive-account-value.test.ts
T

137 lines
3.9 KiB
TypeScript

import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
ACCOUNT_TYPE_LABEL,
formatReceiveAccountDisplay,
formatReceiveAccountLine,
isReceiveAccountSnapshot,
normalizeReceiveAccountModelValue,
optionLabelFromRow,
snapshotFromRow,
type ReceiveAccountSnapshot
} from './oa-receive-account-value'
const alipay: ReceiveAccountSnapshot = {
id: '1',
accountType: 'alipay',
accountName: '张三',
accountNo: '13800138000',
bankName: '',
bankProvince: '',
bankCity: '',
bankBranch: '',
remark: '日常'
}
const personal: ReceiveAccountSnapshot = {
id: '2',
accountType: 'personal',
accountName: '李四',
accountNo: '6222',
bankName: '工行',
bankProvince: '安徽省',
bankCity: '合肥市',
bankBranch: '长江中路支行',
remark: ''
}
describe('oa-receive-account-value', () => {
it('type labels', () => {
assert.equal(ACCOUNT_TYPE_LABEL.alipay, '支付宝')
assert.equal(ACCOUNT_TYPE_LABEL.personal, '个人银行卡')
assert.equal(ACCOUNT_TYPE_LABEL.corporate, '对公银行账户')
})
it('isReceiveAccountSnapshot', () => {
assert.equal(isReceiveAccountSnapshot(alipay), true)
assert.equal(isReceiveAccountSnapshot({ id: '1' }), false)
})
it('normalize always array', () => {
assert.deepEqual(normalizeReceiveAccountModelValue(null), [])
assert.deepEqual(normalizeReceiveAccountModelValue(alipay), [alipay])
assert.deepEqual(normalizeReceiveAccountModelValue([alipay, personal]), [alipay, personal])
})
it('format line alipay omits bank', () => {
const line = formatReceiveAccountLine(alipay)
assert.ok(line.includes('支付宝'))
assert.ok(line.includes('张三'))
assert.ok(!line.includes('工行'))
assert.ok(line.includes('日常'))
})
it('format line personal full', () => {
const line = formatReceiveAccountLine(personal)
assert.ok(line.includes('个人银行卡'))
assert.ok(line.includes('安徽省 / 合肥市'))
assert.ok(line.includes('长江中路支行'))
})
it('format display multiline', () => {
const text = formatReceiveAccountDisplay([alipay, personal])
assert.ok(text.includes('\n'))
})
it('format line personal province only', () => {
const line = formatReceiveAccountLine({
...personal,
bankCity: ''
})
assert.ok(line.includes('安徽省'))
assert.ok(!line.includes(' / '))
})
it('format line personal city only', () => {
const line = formatReceiveAccountLine({
...personal,
bankProvince: ''
})
assert.ok(line.includes('合肥市'))
assert.ok(!line.includes(' / '))
})
it('optionLabelFromRow minimal row', () => {
assert.equal(
optionLabelFromRow({
accountType: 'alipay',
accountName: '张三',
accountNo: '13800138000'
}),
'支付宝 · 张三 · 13800138000'
)
})
it('optionLabelFromRow unknown type falls back to raw type', () => {
assert.equal(
optionLabelFromRow({
accountType: 'other',
accountName: '王五',
accountNo: '9999'
}),
'other · 王五 · 9999'
)
})
it('snapshotFromRow maps and trims fields', () => {
assert.deepEqual(
snapshotFromRow({
id: ' 10 ',
accountType: 'corporate',
accountName: ' 公司 ',
accountNo: ' 123 ',
bankName: '建行',
bankProvince: '北京',
bankCity: '北京',
bankBranch: '分行',
remark: '备注'
}),
{
id: '10',
accountType: 'corporate',
accountName: '公司',
accountNo: '123',
bankName: '建行',
bankProvince: '北京',
bankCity: '北京',
bankBranch: '分行',
remark: '备注'
}
)
})
it('snapshotFromRow defaults invalid type to personal', () => {
const snap = snapshotFromRow({ id: '1', accountType: 'invalid' })
assert.equal(snap.accountType, 'personal')
})
})