fix: align ticket data booking contracts

This commit is contained in:
zoujing committed 2026-07-30 16:41:30 +08:00
1 parent 85a61e6342
commit 80cbf49812
3 files changed
+118 -42

No files matched your search

+62 -3
View File
@@ -62,13 +62,13 @@ test('provides coherent default visitor ticket data', async () => {
assert.deepEqual(INSURANCE, { name: '出行意外险', price: 5, description: '最高10万元意外保障' })
assert.deepEqual(REFUND_REASONS, ['行程有变,无法按计划出行', '重复购买', '选错日期或票种', '其他原因'])
assert.deepEqual(INITIAL_TRAVELERS, [
{ id: 'traveler-lin-xiao', name: '林晓', idType: '身份证', idNumber: '110101199001020010', phone: '13800138000' }, { id: 'traveler-zhou-ning', name: '周宁', idType: '身份证', idNumber: '110101196001020010', phone: '13900139000' },
{ id: 'traveler-lin-xiao', name: '林晓', idType: '身份证', idNumber: '110101199001020010', phone: '13800138000' }, { id: 'traveler-zhou-ning', name: '周宁', idType: '身份证', idNumber: '110101196001020017', phone: '13900139000' },
])
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 }],
id: 'adult', name: '成人门票+观光车', shortTitle: '成人门票+观光车', category: '景点门票', description: '荔波小七孔景区成人入园门票。', salePrice: 160, marketPrice: 170, stock: 120, sold: 2386, status: 'on_sale', highlights: ['实名预约入园', '覆盖核心景区'], ageRule: null, 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 }],
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)
@@ -83,6 +83,65 @@ test('provides coherent default visitor ticket data', async () => {
}
})
test('honors each product reservation requirement flag when validating bookings', async () => {
const { PRODUCTS } = await import('./data.js')
const boat = PRODUCTS.find(({ id }) => id === 'boat')
const boatDraft = {
...createBookingDraft(boat),
visitDate: '2026-08-01',
contactName: '林晓',
phone: '13800138000',
}
assert.equal(validateBooking({ product: boat, draft: boatDraft, travelers: [] }), '')
const noRequirements = {
...boat,
reservation: {
...boat.reservation,
requiresDate: false,
requiresTimeSlot: false,
realNameRequired: false,
contactPhoneRequired: false,
},
}
assert.equal(validateBooking({ product: noRequirements, draft: createBookingDraft(noRequirements), travelers: [] }), '')
const timeRequired = { ...noRequirements, reservation: { ...noRequirements.reservation, requiresTimeSlot: true } }
assert.equal(validateBooking({ product: timeRequired, draft: createBookingDraft(timeRequired), travelers: [] }), '请选择使用场次')
const contactRequired = { ...noRequirements, reservation: { ...noRequirements.reservation, contactPhoneRequired: true } }
assert.equal(validateBooking({ product: contactRequired, draft: createBookingDraft(contactRequired), travelers: [] }), '请填写正确的联系人和手机号')
})
test('keeps ticket source prototypes, valid traveler IDs, and entitlement allocations aligned', async () => {
const { INITIAL_TRAVELERS, PRODUCTS } = await import('./data.js')
const productsById = new Map(PRODUCTS.map((product) => [product.id, product]))
assert.equal(productsById.get('adult').ageRule, null)
assert.deepEqual(productsById.get('adult').name, '成人门票+观光车')
assert.deepEqual(productsById.get('elderly').name, '老年人门票+观光车')
assert.deepEqual(productsById.get('minor').name, '未成年门票+观光车')
assert.deepEqual(productsById.get('free').name, '免门票+观光车实名预约')
assert.deepEqual(productsById.get('classic').name, '门票+观光车+鸳鸯湖游船')
assert.deepEqual(productsById.get('boat').name, '鸳鸯湖游船票')
assert.deepEqual(productsById.get('day-tour').name, '荔波小七孔精品一日游')
assert.deepEqual(productsById.get('guide').name, '小七孔精品讲解服务')
assert.deepEqual(productsById.get('direct-bus').name, '贵阳往返小七孔直通车')
assert.deepEqual(productsById.get('elderly').reservation.idTypes, ['身份证'])
assert.deepEqual(productsById.get('minor').reservation.idTypes, ['身份证'])
assert.ok(PRODUCTS.filter((product) => product.ageRule).every((product) => product.reservation.idTypes.length === 1 && product.reservation.idTypes[0] === '身份证'))
assert.ok(productsById.get('direct-bus').included.every((item) => item.includes('往返')))
assert.match(productsById.get('direct-bus').detail, /往返/)
assert.match(productsById.get('direct-bus').purchaseNotice, /往返/)
assert.deepEqual(productsById.get('adult').entitlements.map(({ name, fulfillment, refundAllocation }) => [name, fulfillment, refundAllocation]), [['成人门票', 'third_party', 120], ['观光车票', 'third_party', 40]])
assert.deepEqual(productsById.get('elderly').entitlements.map(({ refundAllocation }) => refundAllocation), [60, 40])
assert.deepEqual(productsById.get('minor').entitlements.map(({ refundAllocation }) => refundAllocation), [60, 40])
assert.deepEqual(productsById.get('free').entitlements.map(({ refundAllocation }) => refundAllocation), [0, 40])
assert.deepEqual(productsById.get('classic').entitlements.map(({ name, fulfillment, refundAllocation }) => [name, fulfillment, refundAllocation]), [['成人门票+观光车', 'third_party', 160], ['鸳鸯湖游船', 'self', 28]])
assert.ok(PRODUCTS.every((product) => product.entitlements.every((entitlement) => Number.isFinite(entitlement.quantity) && entitlement.quantity > 0 && Number.isFinite(entitlement.refundAllocation)) && product.entitlements.reduce((total, entitlement) => total + entitlement.refundAllocation, 0) === product.salePrice))
assert.deepEqual(INITIAL_TRAVELERS[1], { id: 'traveler-zhou-ning', name: '周宁', idType: '身份证', idNumber: '110101196001020017', phone: '13900139000' })
})
const adultProduct = {
id: 'adult',
name: '成人票',