This commit is contained in:
2026-08-26 11:10:42 +08:00
parent 15421db421
commit cf5d603a21
35 changed files with 664 additions and 435 deletions
@@ -30,10 +30,10 @@ function blocker(context, name, response, evidence, category) {
})
}
async function waitForSources(context, sourceFeeIds) {
async function waitForSources(context, customerId, sourceFeeIds) {
let pool = []
for (let attempt = 0; attempt < 30; attempt += 1) {
const response = await context.request('GET', `${BASE}/fee-pool?customerId=10001&direction=ALL`)
const response = await context.request('GET', `${BASE}/fee-pool?customerId=${encodeURIComponent(customerId)}&direction=ALL`)
pool = rows(data(response)).concat(rows(data(response)?.items))
const visible = new Set(pool.map((item) => id(item.sourceId)))
if (sourceFeeIds.every((sourceId) => visible.has(sourceId))) return pool
@@ -80,10 +80,11 @@ async function createExtraPayable(context, fixture, index) {
unitPrice: 90 + index * 10, amount: 90 + index * 10, currency: 'CNY',
supplierId, remark: `${MARKER}-AP-${index}` }
const basePath = `/api/platform/v1/inbounds/${inboundId}/fee-details`
const createdResponse = await write(context, 'POST', `${basePath}?accountId=10001`, body, `extra-payable-${index}`)
const customerId = id(fixture.customerId)
const createdResponse = await write(context, 'POST', `${basePath}?accountId=${encodeURIComponent(customerId)}`, body, `extra-payable-${index}`)
const created = data(createdResponse)
if (!ok(createdResponse) || !created?.id) return null
const approveResponse = await write(context, 'POST', `${basePath}/${created.id}/approve?accountId=10001`, undefined, `extra-payable-${index}-approve`)
const approveResponse = await write(context, 'POST', `${basePath}/${created.id}/approve?accountId=${encodeURIComponent(customerId)}`, undefined, `extra-payable-${index}-approve`)
record(context, `创建第 ${index} 条额外应付来源`, approveResponse, ok(approveResponse),
`sourceFeeId=${created.id}, inboundId=${inboundId}, supplierId=${supplierId}`)
return { sourceFeeId: id(created.id), direction: 'PAYABLE', businessDate: body.businessDate,
@@ -91,7 +92,7 @@ async function createExtraPayable(context, fixture, index) {
}
async function createStatement(context, source, role, targetStatus) {
const body = { customerId: '10001', currency: 'CNY', generationMode: 'SELECTED',
const body = { customerId: id(source.customerId), currency: 'CNY', generationMode: 'SELECTED',
feeSourceIds: [source.feeSourceId], periodStart: source.businessDate, periodEnd: source.businessDate,
remark: `${MARKER}-${role}` }
const response = await write(context, 'POST', `${BASE}/statements`, body, `statement-${role}-create`)
@@ -120,7 +121,7 @@ async function createAr(context, statement, role) {
async function receive(context, fixture, settlement, amount, role) {
const response = await write(context, 'POST', `${BASE}/receipts`, {
customerId: 10001, receivedDate: new Date().toISOString().slice(0, 10), amount, currency: 'CNY',
customerId: id(fixture.customerId), receivedDate: new Date().toISOString().slice(0, 10), amount, currency: 'CNY',
paymentMethod: 'BANK_TRANSFER', voucherFileIds: [fixture.voucherFileId], remark: `${MARKER}-${role}`,
allocations: [{ billId: Number(settlement.reconciliationStatementId), amount }],
}, `receipt-${role}`)
@@ -130,7 +131,7 @@ async function receive(context, fixture, settlement, amount, role) {
async function createAp(context, fixture, source, role) {
const response = await write(context, 'POST', `${BASE}/payable-settlements`, {
customerId: 10001, supplierId: id(source.supplierId), feeSourceIds: [Number(source.feeSourceId)],
customerId: id(fixture.customerId), supplierId: id(source.supplierId), feeSourceIds: [Number(source.feeSourceId)],
dueDate: new Date().toISOString().slice(0, 10), currency: 'CNY',
}, `ap-${role}-${source.feeSourceId}-${source.supplierId}-create`)
const value = data(response)
@@ -165,8 +166,9 @@ async function recoverExistingDemo(context, reportPath) {
const report = JSON.parse(await readFile(reportPath, 'utf8'))
const fixture = report?.createdResources?.financeFullFixtures
const matrix = structuredClone(report?.createdResources?.financeDemo ?? {})
if (fixture?.marker !== matrix.runMarker || matrix.marker !== MARKER || matrix.customerId !== '10001') {
throw new Error('恢复报告不是 FIN-DEMO-20260812 / 客户 10001 的同一轮 fixture')
if (fixture?.marker !== matrix.runMarker || matrix.marker !== MARKER
|| !id(matrix.customerId) || id(matrix.customerId) !== id(fixture.customerId)) {
throw new Error('恢复报告不是 FIN-DEMO-20260812 同一轮动态客户 fixture')
}
context.marker = matrix.runMarker
await verifyUnfilteredLists(context)
@@ -189,7 +191,7 @@ async function recoverExistingDemo(context, reportPath) {
const role = roles[index]
const detail = await sourceDetail(context, payableIds[index])
const source = detail.value
if (!ok(detail.response) || source?.direction !== 'PAYABLE' || source?.customerId !== '10001'
if (!ok(detail.response) || source?.direction !== 'PAYABLE' || id(source?.customerId) !== id(matrix.customerId)
|| !id(source?.sourceFeeId)) {
blocker(context, `${role} 恢复来源属于本轮 fixture`, detail.response,
`feeSourceId=${payableIds[index]}, sourceFeeId=${source?.sourceFeeId ?? 'missing'}`,
@@ -276,9 +278,12 @@ export async function run(context) {
const producer = await import('./finance-full-fixtures.mjs')
await producer.run(context)
const fixture = context.createdResources.financeFullFixtures
if (!fixture || fixture.marker !== runMarker || fixture.customerId !== '10001') {
const qualificationFixture = context.context.merchantQualificationFixture
const customerId = id(fixture?.customerId)
if (!fixture || fixture.marker !== runMarker || !customerId
|| customerId !== id(qualificationFixture?.tenantId)) {
blocker(context, '取得演示企业真实 Finance fixture', null,
'finance-full-fixtures 未返回 marker=FIN-DEMO-20260812、customerId=10001 的独立资源,禁止借历史来源',
'finance-full-fixtures 未返回与 merchant-qualification-fixture 同客户的本轮独立资源,禁止借历史来源',
'missing-finance-demo-fixture')
return
}
@@ -289,10 +294,10 @@ export async function run(context) {
if (value) extraPayables.push(value)
}
const produced = [...fixture.feeSources.map((item) => ({ ...item, sourceFeeId: id(item.feeSourceId) })), ...extraPayables]
const pool = await waitForSources(context, produced.map((item) => item.sourceFeeId).filter(Boolean))
const pool = await waitForSources(context, customerId, produced.map((item) => item.sourceFeeId).filter(Boolean))
const poolBySource = new Map(pool.map((item) => [id(item.sourceId), item]))
const sources = produced.map((source) => ({ ...source,
feeSourceId: financeId(poolBySource.get(source.sourceFeeId)), marker: runMarker,
feeSourceId: financeId(poolBySource.get(source.sourceFeeId)), marker: runMarker, customerId,
supplierId: id(source.supplierId ?? fixture.supplier?.supplierId) }))
.filter((source) => source.feeSourceId)
const receivables = sources.filter((source) => source.direction === 'RECEIVABLE')
@@ -304,7 +309,8 @@ export async function run(context) {
return
}
const matrix = { marker: MARKER, runMarker, customerId: '10001', customerLabel: '一期演示企业 10001',
const matrix = { marker: MARKER, runMarker, customerId,
customerLabel: qualificationFixture?.tenantName || `动态验收客户 ${customerId}`,
feeSources: {}, statements: {}, receivableSettlements: {}, payableSettlements: {},
voucherFileId: id(fixture.voucherFileId), container: fixture.container, allocations: fixture.allocations }