诚实性修复: API限流Retry-After(wait=60s)+断言 / purge定时接线(04:00 cron+actor+测试) / Channel表单校验(ref+rules+validate) / README PG数字513
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
required,
|
||||
positiveAmount,
|
||||
nonEmptyArray,
|
||||
shopId,
|
||||
voucherBalanced,
|
||||
voucherEntryErrors,
|
||||
} from '../src/utils/validate.js'
|
||||
|
||||
test('required rejects blank', () => {
|
||||
assert.equal(required(''), false)
|
||||
assert.equal(required(' '), false)
|
||||
assert.equal(required(null), false)
|
||||
assert.equal(required(undefined), false)
|
||||
assert.equal(required('x'), true)
|
||||
})
|
||||
|
||||
test('positiveAmount', () => {
|
||||
assert.equal(positiveAmount(0), false)
|
||||
assert.equal(positiveAmount(-1), false)
|
||||
assert.equal(positiveAmount('abc'), false)
|
||||
assert.equal(positiveAmount(0.01), true)
|
||||
})
|
||||
|
||||
test('nonEmptyArray', () => {
|
||||
assert.equal(nonEmptyArray([]), false)
|
||||
assert.equal(nonEmptyArray('x'), false)
|
||||
assert.equal(nonEmptyArray([1]), true)
|
||||
})
|
||||
|
||||
test('shopId', () => {
|
||||
assert.equal(shopId(''), false)
|
||||
assert.equal(shopId('shop-001'), true)
|
||||
})
|
||||
|
||||
test('voucherBalanced happy path', () => {
|
||||
const entries = [
|
||||
{ account_code: '1002', debit: 100, credit: 0 },
|
||||
{ account_code: '6001', debit: 0, credit: 100 },
|
||||
]
|
||||
assert.equal(voucherBalanced(entries), true)
|
||||
assert.deepEqual(voucherEntryErrors(entries), [])
|
||||
})
|
||||
|
||||
test('voucherBalanced rejects imbalance', () => {
|
||||
const entries = [
|
||||
{ account_code: '1002', debit: 100, credit: 0 },
|
||||
{ account_code: '6001', debit: 0, credit: 90 },
|
||||
]
|
||||
assert.equal(voucherBalanced(entries), false)
|
||||
assert.ok(voucherEntryErrors(entries).some((m) => m.includes('不平衡')))
|
||||
})
|
||||
|
||||
test('voucher entries reject missing code and double-side', () => {
|
||||
const entries = [
|
||||
{ account_code: '', debit: 50, credit: 0 },
|
||||
{ account_code: '6001', debit: 10, credit: 10 },
|
||||
]
|
||||
const errors = voucherEntryErrors(entries)
|
||||
assert.ok(errors.some((m) => m.includes('科目编码')))
|
||||
assert.ok(errors.some((m) => m.includes('不能同时')))
|
||||
})
|
||||
|
||||
test('voucher entries reject all-zero row', () => {
|
||||
const errors = voucherEntryErrors([{ account_code: '1002', debit: 0, credit: 0 }])
|
||||
assert.ok(errors.some((m) => m.includes('至少填一边')))
|
||||
})
|
||||
Reference in New Issue
Block a user