同步飞飞核销券状态
This commit is contained in:
@@ -62,7 +62,11 @@ export async function attachKuaishouIndustryVoucherToTask(
|
||||
) {
|
||||
const now = normalizeTimestampIso(options.now || new Date().toISOString())
|
||||
const context = parseTaskContext(task)
|
||||
const nextVoucherContext = buildVoucherContext(voucher, context.kuaishouIndustryVoucher, now)
|
||||
const nextVoucherContext = buildKuaishouIndustryVoucherContext(
|
||||
voucher,
|
||||
context.kuaishouIndustryVoucher,
|
||||
now,
|
||||
)
|
||||
const nextContext: JsonObject = {
|
||||
...context,
|
||||
kuaishouIndustryVoucher: nextVoucherContext,
|
||||
@@ -121,7 +125,7 @@ function resolveTaskForVoucher(voucher: KuaishouIndustryVoucherRow, tasks: TaskR
|
||||
return tasks[unitIndex - 1] || null
|
||||
}
|
||||
|
||||
function buildVoucherContext(
|
||||
export function buildKuaishouIndustryVoucherContext(
|
||||
voucher: KuaishouIndustryVoucherRow,
|
||||
existingValue: unknown,
|
||||
now: string,
|
||||
|
||||
@@ -2,6 +2,7 @@ import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { generateKuaishouIndustryVoucherCode } from '../../../repositories/kuaishou-industry-voucher-repo.js'
|
||||
import { buildKuaishouIndustryVoucherContext } from './voucher-binding-service.js'
|
||||
import { resolveKuaishouIndustryVoucherValidity } from './voucher-service.js'
|
||||
|
||||
test('generateKuaishouIndustryVoucherCode creates non-numeric stable voucher code', () => {
|
||||
@@ -57,3 +58,27 @@ test('resolveKuaishouIndustryVoucherValidity prefers actual certificate time ran
|
||||
assert.equal(validity.validStartTime, 1000)
|
||||
assert.equal(validity.validEndTime, 5000)
|
||||
})
|
||||
|
||||
test('buildKuaishouIndustryVoucherContext maps consumed voucher state', () => {
|
||||
const context = buildKuaishouIndustryVoucherContext(
|
||||
{
|
||||
oid: '2618800481389561',
|
||||
voucher_code: 'KSV15K821FDHPMTX1ST',
|
||||
token: 'ticket-token',
|
||||
unit_index: 1,
|
||||
status: 'CONSUMED',
|
||||
valid_start_time: 1783427213868,
|
||||
valid_end_time: 1786019213868,
|
||||
consumed_at: '2026-07-07T12:36:54.626Z',
|
||||
} as any,
|
||||
{
|
||||
verifiedAt: '2026-07-07T12:26:58.421Z',
|
||||
},
|
||||
'2026-07-07T12:36:54.626Z',
|
||||
)
|
||||
|
||||
assert.equal(context.status, 'CONSUMED')
|
||||
assert.equal(context.consumedAt, '2026-07-07T12:36:54.626Z')
|
||||
assert.equal(context.voucherCode, 'KSV15K821FDHPMTX1ST')
|
||||
assert.equal(context.verifiedAt, '2026-07-07T12:26:58.421Z')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user