fix(claim): 统一所有买家领取链接为 H5 订单号格式

This commit is contained in:
yml2213
2026-11-02 22:11:22 +08:00
parent 3989b0a649
commit 4dc2f5ca90
38 changed files with 298 additions and 362 deletions
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildConfiguredClaimUrl,
buildOrderClaimUrl,
pickOrderItemClaimTask,
resolveClaimTokenExpiration,
} from './claim-service.js'
@@ -18,26 +18,40 @@ test('领取链接保留正整数小时的限时配置能力', () => {
)
})
test('配置化领取链接只拼传入基址(去尾斜杠),不读全局 claimBaseUrl', () => {
test('所有来源统一生成 /h5/<订单号> 领取链接', () => {
const orderNo = '6919156612984680391'
assert.equal(
buildConfiguredClaimUrl('https://x.ngrok-free.app/#/claim', 'AbC123'),
'https://x.ngrok-free.app/#/claim/AbC123',
buildOrderClaimUrl(orderNo, 'https://x.ngrok-free.app/#/claim'),
`https://x.ngrok-free.app/h5/${orderNo}`,
)
assert.equal(
buildConfiguredClaimUrl('https://x.ngrok-free.app/claim/', 'AbC123'),
'https://x.ngrok-free.app/claim/AbC123',
buildOrderClaimUrl(orderNo, 'https://x.ngrok-free.app/claim/'),
`https://x.ngrok-free.app/h5/${orderNo}`,
)
assert.equal(
buildConfiguredClaimUrl('https://x.ngrok-free.app', 'AbC123'),
'https://x.ngrok-free.app/AbC123',
buildOrderClaimUrl(orderNo, 'https://x.ngrok-free.app/custom'),
`https://x.ngrok-free.app/custom/h5/${orderNo}`,
)
assert.equal(
buildOrderClaimUrl(orderNo, 'https://x.ngrok-free.app/h5///'),
`https://x.ngrok-free.app/h5/${orderNo}`,
)
assert.equal(
buildOrderClaimUrl(orderNo, 'https://x.ngrok-free.app/h5/old-token'),
`https://x.ngrok-free.app/h5/${orderNo}`,
)
assert.equal(
buildOrderClaimUrl(orderNo, 'https://x.ngrok-free.app/claim/old-token'),
`https://x.ngrok-free.app/h5/${orderNo}`,
)
})
test('配置化领取链接基址/token 缺失返回空串(由调用方决定不发链接、不发消息)', () => {
assert.equal(buildConfiguredClaimUrl('', 'AbC123'), '')
assert.equal(buildConfiguredClaimUrl(undefined, 'AbC123'), '')
assert.equal(buildConfiguredClaimUrl('https://x/claim', ''), '')
assert.equal(buildConfiguredClaimUrl('https://x/claim', null), '')
test('订单号或领取基址缺失/无效时返回空串', () => {
assert.equal(buildOrderClaimUrl('', 'https://x/claim'), '')
assert.equal(buildOrderClaimUrl(null, 'https://x/claim'), '')
assert.equal(buildOrderClaimUrl('6919156612984680391', ''), '')
assert.equal(buildOrderClaimUrl('6919156612984680391', 'not-a-url'), '')
})
test('pickOrderItemClaimTask 取该订单项 task id 最小且带 token 的单元', () => {