2026-08-13 11:57:33 +08:00
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const here = path . dirname ( fileURLToPath ( import . meta . url ))
const acceptance = fs . readFileSync ( path . join ( here , '..' , 'admin-test-env-acceptance.mjs' ), 'utf8' )
const system = fs . readFileSync ( path . join ( here , 'system.mjs' ), 'utf8' )
2026-08-13 12:22:31 +08:00
const operatingStatistics = fs . readFileSync ( path . join ( here , 'customer-operating-statistics.mjs' ), 'utf8' )
const repositoryRoot = path . join ( here , '..' , '..' )
const orderStatisticsTest = fs . readFileSync ( path . join ( repositoryRoot , 'order' , 'src' , 'test' , 'java' , 'com' , 'baiyue' , 'order' , 'service' , 'TenantOrderStatisticsServiceTest.java' ), 'utf8' )
+ fs . readFileSync ( path . join ( repositoryRoot , 'order' , 'src' , 'test' , 'java' , 'com' , 'baiyue' , 'order' , 'repository' , 'TenantOrderStatisticsSqlContractTest.java' ), 'utf8' )
const financeStatisticsTest = fs . readFileSync ( path . join ( repositoryRoot , 'finance' , 'src' , 'test' , 'java' , 'com' , 'baiyue' , 'finance' , 'CustomerAccountSummaryBehaviorTest.java' ), 'utf8' )
const transitStatisticsTest = fs . readFileSync ( path . join ( repositoryRoot , 'firstleg' , 'src' , 'test' , 'java' , 'com' , 'baiyue' , 'firstleg' , 'customerstatistics' , 'CustomerTransitStatisticsServiceTest.java' ), 'utf8' )
+ fs . readFileSync ( path . join ( repositoryRoot , 'firstleg' , 'src' , 'test' , 'java' , 'com' , 'baiyue' , 'firstleg' , 'customerstatistics' , 'CustomerTransitStatisticsContractTest.java' ), 'utf8' )
2026-08-13 11:57:33 +08:00
test ( '客户验收覆盖审核资质上传、回查和鉴权下载' , () => {
assert . match ( acceptance , /files\/qualifications\/\$\{tenantId\}\/required-package/ )
assert . match ( acceptance , /BUSINESS_LICENSE/ )
assert . match ( acceptance , /LEGAL_PERSON_ID/ )
assert . match ( acceptance , /requestBinary\('GET', `\/api\/platform\/v1\/files\/qualifications\/\$\{tenantId\}/ )
assert . match ( acceptance , /downloadResponse\.bytes\.length > 0/ )
})
test ( '系统验收覆盖后端四种权限资源类型并清理测试资源' , () => {
for ( const type of [ 'BUTTON' , 'MENU' , 'PAGE' , 'API' ]) assert . match ( system , new RegExp ( `type: ' ${ type } '` ))
assert . match ( system , /created\?\.permissionType === definition\.type/ )
assert . match ( system , /created\?\.httpMethod/ )
assert . match ( system , /DELETE.*permissions\/\$\{additionalPermissionId\}/s)
})
test ( '客户验收覆盖客户维度操作日志列表和详情快照' , () => {
assert . match ( acceptance , /audit\/logs\?accountId=\$\{tenantId\}&eventType=PLATFORM_TENANT_UPDATE&resourceType=TENANT&resourceId=\$\{tenantId\}/ )
assert . match ( acceptance , /PLATFORM_TENANT_UPDATE/ )
assert . match ( acceptance , /audit\/logs\/\$\{customerAuditRow\.id\}/ )
assert . match ( acceptance , /JSON\.parse\(auditDetail\[field\]\)/ )
assert . match ( acceptance , /snapshotsAreRedacted/ )
2026-08-13 16:58:17 +08:00
assert . match ( acceptance , /eventAccountId=.*expectedAccountId=/ )
assert . match ( acceptance , /event=not-delivered, editRequestId=/ )
})
test ( '客户资质场景使用独立社会信用代码命名空间' , () => {
assert . match ( acceptance , /unifiedSocialCreditCode', `91440301/ )
assert . doesNotMatch ( operatingStatistics , /unifiedSocialCreditCode/ )
2026-08-13 11:57:33 +08:00
})
2026-08-13 12:22:31 +08:00
test ( '客户详情经营统计模块登记三项独立正式接口与精度字段' , () => {
assert . match ( acceptance , /'customer-operating-statistics'/ )
assert . match ( operatingStatistics , /orders\/first-leg\/tenant-statistics\?tenantId=/ )
assert . match ( operatingStatistics , /customer-accounts\/\$\{encodeURIComponent\(customerId\)\}\/summary/ )
assert . match ( operatingStatistics , /container-transit-summary/ )
for ( const field of [ 'currentMonthSubmittedOrders' , 'outstandingReceivable' , 'totalTeu' , 'unknownContainerCount' ]) {
assert . match ( operatingStatistics , new RegExp ( field ))
}
})
test ( '后端统计契约测试覆盖客户详情已确认边界口径' , () => {
for ( const marker of [ "order_role = 'master'" , 'submitted_at is not null' , 'monthstart' , 'nextmonthstart' , 'doesNotContain\\\("status ="\\\)' ]) assert . match ( orderStatisticsTest , new RegExp ( marker , 'i' ))
for ( const marker of [ 'VOIDED' , 'totalReceivable' , 'receivedAmount' , 'outstandingReceivable' ]) assert . match ( financeStatisticsTest , new RegExp ( marker , 'i' ))
for ( const marker of [ 'actual_sailing_at' , 'actual_warehouse_arrival_at' , 'CANCELLED' , 'FAILED' , '20\\*=1' , '40\\*=2' , '45\\*=2.25' , '2.25' , 'unknown' ]) assert . match ( transitStatisticsTest , new RegExp ( marker , 'i' ))
assert . match ( orderStatisticsTest , /tenant_id|tenantSubmittedStatistics/ )
assert . match ( financeStatisticsTest , /customerId|customer_id/ )
assert . match ( transitStatisticsTest , /customerId|customer_id/ )
})