2026-08-13 11:57:33 +08:00
import test from 'node:test'
import assert from 'node:assert/strict'
2026-10-03 06:26:33 +08:00
import { verifyRevokedSessions } from './system.mjs'
2026-08-13 11:57:33 +08:00
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
2026-10-03 06:26:33 +08:00
test ( '撤销检查逐会话核对Access和Refresh且403不能冒充会话失效' , async () => {
const records = [], calls = []
const context = {
assert : ( _module , name , _response , passed , evidence ) => records . push ({ name , passed , evidence }),
request : async ( method , path , body , token ) => {
calls . push ({ method , path , body , token })
return { http : path . endsWith ( '/refresh' ) ? 200 : 401 , body : { code : 'A0401' } }
},
}
await verifyRevokedSessions ( context , '密码重置' , [{ accessToken : 'a-1' , refreshToken : 'r-1' },
{ accessToken : 'a-2' , refreshToken : 'r-2' }])
assert . equal ( calls . length , 4 )
assert . ok ( records . every ( row => row . passed ))
assert . ok ( records . every ( row => ! /a-1|r-1|a-2|r-2/ . test ( row . evidence )))
assert . equal ( calls [ 1 ]. token , '' )
context . request = async () => ({ http : 403 , body : { code : 'A0403' } })
await verifyRevokedSessions ( context , '停用' , [{ accessToken : 'a' , refreshToken : 'r' }])
assert . equal ( records . at ( - 2 ). passed , false )
assert . equal ( records . at ( - 1 ). passed , false )
await assert . rejects ( verifyRevokedSessions ( context , '缺失' , [{}]), /完整 Access\/Refresh/ )
})
2026-08-13 11:57:33 +08:00
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)
})
2026-09-29 19:48:34 +08:00
test ( 'system后刷新统一Token且受限海外权限只接受403语义' , () => {
2026-08-25 16:40:48 +08:00
assert . match ( acceptance , /module === 'system' && laterOverseasModule/ )
assert . match ( acceptance , /refreshSession\('system模块权限与角色变更完成'\)/ )
2026-09-29 19:48:34 +08:00
assert . match ( acceptance , /system后新admin统一Token只读探针可用/ )
assert . match ( acceptance , /Date\.now\(\) \+ 120_000 >= this\.expiresAt/ )
2026-08-25 16:40:48 +08:00
assert . match ( system , /缺少canonical海外订单权限必须403/ )
assert . match ( system , /denied\.http === 403 \|\| \['403', 'A0403'\]\.includes/ )
assert . doesNotMatch ( system , /A0401[^\r\n]{0,120}(必须403|includes)/ )
})
2026-08-13 11:57:33 +08:00
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' ))
2026-08-24 20:14:40 +08:00
for ( const marker of [ 'actual_sailing_at' , 'actual_warehouse_arrival_at' , 'CANCELLED' , 'NOT EXISTS' , '20\\*=1' , '40\\*=2' , '45\\*=2.25' , '2.25' , 'unknown' ]) assert . match ( transitStatisticsTest , new RegExp ( marker , 'i' ))
2026-08-13 12:22:31 +08:00
assert . match ( orderStatisticsTest , /tenant_id|tenantSubmittedStatistics/ )
assert . match ( financeStatisticsTest , /customerId|customer_id/ )
assert . match ( transitStatisticsTest , /customerId|customer_id/ )
})