Files
baiyue-firstleg/scripts/admin-test-env-modules/merchant-qualification-fixture-contract.test.mjs
T

100 lines
6.1 KiB
JavaScript
Raw Normal View History

2026-08-13 16:14:54 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { qualificationCreditCode } from './merchant-qualification-fixture.mjs'
2026-08-13 16:14:54 +08:00
const acceptance = readFileSync(new URL('../admin-test-env-acceptance.mjs', import.meta.url), 'utf8')
const fixture = readFileSync(new URL('./merchant-qualification-fixture.mjs', import.meta.url), 'utf8')
2026-08-26 11:10:42 +08:00
const orders = readFileSync(new URL('./orders.mjs', import.meta.url), 'utf8')
2026-08-13 16:14:54 +08:00
test('credit codes distinguish repeated CUSTOMER-B and SIGNED-B fixtures using the complete marker', () => {
const customerId = '2100000000000000001'
const values = []
for (const ending of ['CUSTOMER-B', 'SIGNED-B']) {
const firstMarker = `ADMIN-API-20260930121500000-${ending}`
const secondMarker = `ADMIN-API-20260930121600000-${ending}`
const first = qualificationCreditCode(firstMarker, customerId)
const second = qualificationCreditCode(secondMarker, customerId)
assert.notEqual(first, second, `时间不同但后缀同为 ${ending} 必须生成不同代码`)
assert.equal(qualificationCreditCode(firstMarker, customerId), first)
for (const value of [first, second]) assert.match(value, /^91440300[0-9A-F]{10}$/)
values.push(first, second)
}
assert.equal(new Set(values).size, values.length)
assert.match(fixture, /unifiedSocialCreditCode = qualificationCreditCode\(context\.marker, tenantId\)/)
})
test('a new real customer under the same marker receives a distinct stable code', () => {
const marker = 'ADMIN-API-20260930121500000-CUSTOMER-B'
assert.notEqual(qualificationCreditCode(marker, '2100000000000000001'),
qualificationCreditCode(marker, '2100000000000000002'))
assert.throws(() => qualificationCreditCode('', '2100000000000000001'), /完整批次标识/)
assert.throws(() => qualificationCreditCode(marker, ''), /真实客户编号/)
})
2026-08-13 16:14:54 +08:00
test('默认全量验收先准备已审核商户再运行订单链路', () => {
2026-08-24 20:14:40 +08:00
const modules = acceptance.match(/const CONFIGURED_MODULES = \[([^\n]+)\]/)?.[1] || ''
2026-08-13 16:14:54 +08:00
assert.match(modules, /^'merchant-qualification-fixture', 'customers'/)
assert.ok(modules.indexOf("'merchant-qualification-fixture'") < modules.indexOf("'orders'"))
2026-08-24 20:14:40 +08:00
assert.match(acceptance, /DEFAULT_MODULES\s*=\s*normalizeModuleOrder\(CONFIGURED_MODULES\)/)
2026-08-13 16:14:54 +08:00
})
test('商户夹具通过正式 File 和 IAM 审核流程建立下单资格', () => {
assert.match(fixture, /files\/qualifications\/\$\{encodeURIComponent\(tenantId\)\}\/required-package/)
assert.match(fixture, /required-package\?unifiedSocialCreditCode=\$\{encodeURIComponent\(unifiedSocialCreditCode\)\}/)
assert.doesNotMatch(fixture, /packageForm\.append\('unifiedSocialCreditCode'/)
2026-08-13 16:14:54 +08:00
assert.match(fixture, /iam\/tenants\/\$\{encodeURIComponent\(tenantId\)\}\/submit-review/)
assert.match(fixture, /iam\/tenants\/\$\{encodeURIComponent\(tenantId\)\}\/dimension-initialization/)
assert.match(fixture, /status === 'READY'/)
assert.match(fixture, /setTimeout\(resolve, 500\)/)
2026-08-13 16:14:54 +08:00
assert.match(fixture, /iam\/reviews\/\$\{encodeURIComponent\(review\.id\)\}\/approve/)
assert.match(fixture, /item\.status === 'APPROVED'/)
assert.match(fixture, /MERCHANT_TEST_USERNAME/)
assert.match(fixture, /MERCHANT_TEST_PASSWORD/)
2026-08-26 11:10:42 +08:00
assert.match(fixture, /context\.options\?\.customerName/)
assert.match(fixture, /tenantName/)
assert.match(fixture, /expectedProcurementPrefix: customerName \? null : 'QLYSXDKH'/)
2026-09-04 16:06:47 +08:00
assert.match(acceptance, /administrator-phone-availability\?phone=/)
assert.match(acceptance, /attempt < 100/)
assert.doesNotMatch(acceptance, /phoneSequence % 10/)
2026-08-13 16:14:54 +08:00
assert.doesNotMatch(fixture, /internal\/iam|UPDATE\s+iam_|INSERT\s+INTO\s+iam_/i)
})
2026-08-26 11:10:42 +08:00
test('批量待分柜参数固定同一客户并限制为订单测量链', () => {
assert.match(acceptance, /--customer-name <name>/)
assert.match(acceptance, /--merchant-username <name>/)
assert.match(acceptance, /--origin-warehouse-name <name>/)
assert.match(acceptance, /--channel-name <name>/)
assert.match(acceptance, /--wait-split-count <n>/)
assert.match(acceptance, /--order-profile-mode <mode>/)
assert.match(acceptance, /merchant-username和merchant-password必须同时提供/)
assert.match(acceptance, /modules\.splice\(fixtureIndex, 1\)/)
assert.match(acceptance, /wait-split-count必须是1-100的整数/)
2026-09-04 15:19:45 +08:00
assert.match(acceptance, /fixtureModules = new Set\(\['merchant-qualification-fixture', 'orders', 'inbound-measurement',[\s\S]{0,180}'coload-groups'[\s\S]{0,180}'firstleg-container-fee-allocation'/)
assert.match(acceptance, /批量WAIT_SPLIT只允许执行WAIT_SPLIT造数、同柜组与柜次跨客户分摊模块/)
2026-08-26 11:10:42 +08:00
assert.match(acceptance, /createAdditionalWaitSplitFixtures/)
2026-08-26 17:09:02 +08:00
assert.match(acceptance, /orderBlockingFailure[\s\S]*step\.deploymentBlocker/)
assert.match(acceptance, /measurementBlockingFailure[\s\S]*step\.deploymentBlocker/)
assert.doesNotMatch(acceptance, /this\.modules\.at\(-1\)\?\.success !== true/)
assert.match(acceptance, /measurement\.processStatus === expectedProcessStatus/)
assert.match(acceptance, /prepareDropshipManualCount \? 'WAIT_PALLETIZE' : 'WAIT_SPLIT'/)
2026-08-26 11:10:42 +08:00
assert.match(acceptance, /measurement\.finalStatus === 'APPROVED'/)
assert.match(acceptance, /waitSplitVariant\(sequence\)/)
assert.match(acceptance, /packageCountPerSku/)
assert.match(acceptance, /grossWeightPerPalletKg/)
assert.match(acceptance, /randomizedOrderProfile\(sequence\)/)
assert.match(acceptance, /\['PRIVATE', 'STANDARD'\]/)
assert.match(acceptance, /ONE_CLICK_DROPSHIP/)
assert.match(acceptance, /destinationWarehouseCode: order\.destinationWarehouseCode/)
assert.match(acceptance, /channelName: order\.channelName/)
assert.match(acceptance, /pricingTaxMode: order\.pricingTaxMode/)
assert.match(orders, /customerId: profile\.id/)
assert.match(orders, /customerName: companyName/)
assert.match(orders, /\['FBA', 'OVERSEAS', 'PRIVATE'\]\.includes/)
assert.match(orders, /destinationType === 'PRIVATE'/)
assert.match(orders, /PRIVATE_ADDRESS/)
assert.match(orders, /eligible\.length < 1/)
2026-08-26 17:50:56 +08:00
assert.match(orders, /Client 查询发货客户候选', partnerResponse, '', CONTRACT_OPTIONS/)
2026-08-26 11:10:42 +08:00
assert.doesNotMatch(orders, /customerName: master\.partner\?\.partnerName/)
})