优化
This commit is contained in:
@@ -129,6 +129,18 @@ function accountCustomerId(value) { return id(value?.customerId ?? value?.tenant
|
||||
function hasWalletField(value) {
|
||||
return value && typeof value === 'object' && ['balance', 'recharge', 'prepayment'].some((field) => Object.hasOwn(value, field))
|
||||
}
|
||||
function accountInformationComplete(value) {
|
||||
return ['customerCode', 'customerName', 'contactName', 'contactPhone', 'status', 'lastChangedAt']
|
||||
.every((field) => present(value?.[field]))
|
||||
&& ['outstandingReceivable', 'pendingBilling', 'receivedInPeriod', 'outstandingPayable']
|
||||
.every((field) => Number.isFinite(Number(value?.[field])))
|
||||
}
|
||||
function ledgerInformationComplete(value) {
|
||||
return ['ledgerId', 'occurredAt', 'businessType', 'documentType', 'documentId', 'documentNo', 'operatorName']
|
||||
.every((field) => present(value?.[field]))
|
||||
&& ['receivableChange', 'payableChange', 'outstandingReceivableAfter']
|
||||
.every((field) => Number.isFinite(Number(value?.[field])))
|
||||
}
|
||||
async function verifyCustomerAccountAndLedger(context, fixture) {
|
||||
const customerId = id(fixture.customerId)
|
||||
const accountResponse = await context.request('GET',
|
||||
@@ -138,6 +150,9 @@ async function verifyCustomerAccountAndLedger(context, fixture) {
|
||||
context.assert(MODULE, '客户账户列表包含本轮 marker 客户且不暴露钱包字段', accountResponse,
|
||||
Boolean(account) && !accounts.some(hasWalletField),
|
||||
`customerId=${customerId}, accountCount=${accounts.length}, requestId=${accountResponse.requestId ?? 'null'}, traceId=${accountResponse.traceId ?? 'null'}`, OPTIONS)
|
||||
context.assert(MODULE, '客户账户基本信息、四项金额和最近变动时间完整', accountResponse,
|
||||
accountInformationComplete(account),
|
||||
`customerId=${customerId}, customerCode=${account?.customerCode ?? 'missing'}, contact=${account?.contactName ?? 'missing'}/${account?.contactPhone ?? 'missing'}, lastChangedAt=${account?.lastChangedAt ?? 'missing'}`, OPTIONS)
|
||||
const ledgerResponse = await context.request('GET', `${BASE}/accounts/${encodeURIComponent(customerId)}/ledger?page=1&pageSize=200`)
|
||||
const ledger = accountRows(ledgerResponse)
|
||||
const rowsForCustomer = ledger.filter((item) => {
|
||||
@@ -155,6 +170,10 @@ async function verifyCustomerAccountAndLedger(context, fixture) {
|
||||
context.assert(MODULE, '客户账户流水仅属于本轮客户并包含账单/收款或结算流水', ledgerResponse,
|
||||
rowsForCustomer.length === ledger.length && containsRoundTrip,
|
||||
`customerId=${customerId}, ledgerCount=${ledger.length}, requestId=${ledgerResponse.requestId ?? 'null'}, traceId=${ledgerResponse.traceId ?? 'null'}`, OPTIONS)
|
||||
const incompleteLedger = rowsForCustomer.filter((item) => !ledgerInformationComplete(item))
|
||||
context.assert(MODULE, '客户账户流水时间、业务类型、关联单据、金额和操作人完整', ledgerResponse,
|
||||
rowsForCustomer.length > 0 && incompleteLedger.length === 0,
|
||||
`customerId=${customerId}, ledgerCount=${rowsForCustomer.length}, incomplete=${incompleteLedger.length}`, OPTIONS)
|
||||
fixture.root.accountReadback = { account: account || null, accountDiagnostic: diagnostic(accountResponse),
|
||||
ledgerCount: ledger.length, ledgerDiagnostic: diagnostic(ledgerResponse) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user