test: verify ticket order demo isolation

This commit is contained in:
2026-07-30 16:29:58 +08:00
parent a574b179d5
commit 85a61e6342

View File

@@ -17,8 +17,6 @@ import {
test('provides coherent default visitor ticket data', async () => {
const data = await import('./data.js')
const { AVAILABLE_DATES, GROUPS, INITIAL_TRAVELERS, INSURANCE, PLACEHOLDER_IMAGE, PRODUCTS, REFUND_REASONS, SCENIC_SPOT } = data
const productsBeforeOrders = structuredClone(PRODUCTS)
const travelersBeforeOrders = structuredClone(INITIAL_TRAVELERS)
const { INITIAL_ORDERS } = data
assert.equal(PLACEHOLDER_IMAGE, 'https://one-feel-bucket.oss-cn-guangzhou.aliyuncs.com/oneFeel/2082673896938569729.jpg')
@@ -66,13 +64,23 @@ test('provides coherent default visitor ticket data', async () => {
assert.deepEqual(INITIAL_TRAVELERS, [
{ id: 'traveler-lin-xiao', name: '林晓', idType: '身份证', idNumber: '110101199001020010', phone: '13800138000' }, { id: 'traveler-zhou-ning', name: '周宁', idType: '身份证', idNumber: '110101196001020010', phone: '13900139000' },
])
assert.deepEqual(PRODUCTS, productsBeforeOrders)
assert.deepEqual(INITIAL_TRAVELERS, travelersBeforeOrders)
assert.deepEqual(productsById.get('adult'), {
id: 'adult', name: '成人票', shortTitle: '成人门票', category: '景点门票', description: '荔波小七孔景区成人入园门票。', salePrice: 160, marketPrice: 170, stock: 120, sold: 2386, status: 'on_sale', highlights: ['实名预约入园', '覆盖核心景区'], ageRule: { min: 18, max: 59 }, included: ['成人景区门票', '景区观光车'], excluded: ['餐饮及个人消费'], detail: '凭本人有效证件在预约时段入园。', purchaseNotice: '请至少提前一天预约,订单当天不可退改。', images: [PLACEHOLDER_IMAGE], reservation: { requiresDate: true, advanceDays: 1, requiresTimeSlot: true, timeSlots: standardSlots, realNameRequired: true, idTypes: ['身份证', '护照', '港澳居民来往内地通行证'], maxQuantity: 5, contactPhoneRequired: true }, entitlements: [{ id: 'adult-ticket', name: '成人门票', fulfillment: 'third_party', quantity: 1, unit: '张', refundAllocation: 120 }, { id: 'shuttle', name: '观光车票', fulfillment: 'third_party', quantity: 1, unit: '张', refundAllocation: 40 }],
})
assert.deepEqual(productsById.get('classic'), {
id: 'classic', name: '经典联票', shortTitle: '门票+观光车', category: '门票+观光车', description: '景区成人门票与观光车组合套餐。', salePrice: 188, marketPrice: 210, stock: 90, sold: 184, status: 'on_sale', highlights: ['门票观光车联票', '比单买更优惠'], ageRule: { min: 18, max: 59 }, included: ['成人景区门票', '景区观光车', '竹筏体验'], excluded: ['餐饮及个人消费'], detail: '一次预约即可享受门票、观光车与竹筏体验。', purchaseNotice: '各权益可分别核销,未使用部分可按规则申请退款。', images: [PLACEHOLDER_IMAGE], reservation: { requiresDate: true, advanceDays: 1, requiresTimeSlot: true, timeSlots: standardSlots, realNameRequired: true, idTypes: ['身份证', '护照', '港澳居民来往内地通行证'], maxQuantity: 5, contactPhoneRequired: true }, entitlements: [{ id: 'classic-ticket-shuttle', name: '成人门票+观光车', fulfillment: 'third_party', quantity: 1, unit: '张', refundAllocation: 160 }, { id: 'classic-boat', name: '竹筏体验', fulfillment: 'self', quantity: 1, unit: '张', refundAllocation: 28 }],
})
assert.deepEqual(INITIAL_TRAVELERS[0], { id: 'traveler-lin-xiao', name: '林晓', idType: '身份证', idNumber: '110101199001020010', phone: '13800138000' })
assert.equal(INITIAL_ORDERS.length, 2)
assert.deepEqual(INITIAL_ORDERS.map(({ productId, visitDate, timeSlot, insurance, gateCredential, selfCredential, entitlements }) => ({ productId, visitDate, timeSlot, insurance, hasGateCredential: Boolean(gateCredential), hasSelfCredential: Boolean(selfCredential), fulfillment: entitlements.map(({ fulfillment }) => fulfillment) })), [
{ productId: 'adult', visitDate: '2026-08-01', timeSlot: '08:00—09:30', insurance: { name: '出行意外险', price: 5, quantity: 1, status: 'active' }, hasGateCredential: true, hasSelfCredential: false, fulfillment: ['third_party', 'third_party'] },
{ productId: 'classic', visitDate: '2026-08-02', timeSlot: '09:30—11:30', insurance: null, hasGateCredential: true, hasSelfCredential: true, fulfillment: ['third_party', 'self'] },
assert.deepEqual(INITIAL_ORDERS.map(({ productId, visitDate, timeSlot, quantity, travelers, insurance, gateCredential, selfCredential, entitlements }) => ({ productId, visitDate, timeSlot, quantity, travelers, insurance, hasGateCredential: Boolean(gateCredential), hasSelfCredential: Boolean(selfCredential), fulfillment: entitlements.map(({ fulfillment }) => fulfillment) })), [
{ productId: 'adult', visitDate: '2026-08-01', timeSlot: '08:00—09:30', quantity: 1, travelers: [{ id: 'traveler-lin-xiao', name: '林晓', idType: '身份证', idNumber: '110101199001020010', phone: '13800138000' }], insurance: { name: '出行意外险', price: 5, quantity: 1, status: 'active' }, hasGateCredential: true, hasSelfCredential: false, fulfillment: ['third_party', 'third_party'] },
{ productId: 'classic', visitDate: '2026-08-02', timeSlot: '09:30—11:30', quantity: 1, travelers: [{ id: 'traveler-lin-xiao', name: '林晓', idType: '身份证', idNumber: '110101199001020010', phone: '13800138000' }], insurance: null, hasGateCredential: true, hasSelfCredential: true, fulfillment: ['third_party', 'self'] },
])
for (const order of INITIAL_ORDERS) {
assert.notEqual(order.travelers[0], INITIAL_TRAVELERS[0])
const sourceProduct = productsById.get(order.productId)
for (const entitlement of order.entitlements) assert.notEqual(entitlement, sourceProduct.entitlements.find((source) => source.id === entitlement.sourceId))
}
})
const adultProduct = {