@tbox.cn/app-module-parking 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import {
6
6
  resolveParkingQueryPort,
7
7
  resolveParkingVehiclePort,
8
8
  serverModule
9
- } from "../chunk-J3M7F6YT.js";
9
+ } from "../chunk-VH3J7FEI.js";
10
10
  export {
11
11
  InMemoryParkingService,
12
12
  inMemoryParking,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-module-parking",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "type": "module",
5
5
  "description": "商圈停车模块:计费支付、车辆寻车、缴费记录与开票(codegen 源)。",
6
6
  "exports": {
@@ -18,10 +18,10 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@tbox.cn/app-contracts": "0.12.0",
22
- "@tbox.cn/app-contracts-mall": "0.12.0",
23
- "@tbox.cn/app-agent-sdk-client": "0.1.0",
24
- "@tbox.cn/app-agent-sdk-server": "0.1.0"
21
+ "@tbox.cn/app-contracts": "0.12.3",
22
+ "@tbox.cn/app-contracts-mall": "0.12.3",
23
+ "@tbox.cn/app-agent-sdk-client": "0.1.3",
24
+ "@tbox.cn/app-agent-sdk-server": "0.1.4"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "3.25.76",
@@ -7,6 +7,7 @@
7
7
  import { useEffect, useState } from 'react';
8
8
  import { Car, Check, CheckCircle, Clock, CurrencyCircleDollar, ShieldCheck, Sparkle } from '@phosphor-icons/react';
9
9
  import { callCapability, markSelfRendering, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
10
+ import { TBOX_NOTICE_EVENT_NAME } from '@tbox.cn/app-contracts';
10
11
  import type { ParkingPaymentCardData } from '@tbox.cn/app-contracts-mall';
11
12
 
12
13
  /** 重算超时兜底(ms):避免重算失败时勾选被永久锁死 */
@@ -45,6 +46,19 @@ export function ParkingPaymentCard(props: {
45
46
  >();
46
47
  const confirmToken = actionTokens?.['parking.confirm-payment'];
47
48
 
49
+ // 动作失败复位:服务端 confirm-payment 失败时发 tbox:notice(非 card-update)——
50
+ // 否则 submitting 无复位路径(对齐车辆管理卡同款防守),按钮永久卡"支付处理中…"。
51
+ // payOpening 不在此复位:宿主效果链自带 .finally 兜底
52
+ useEffect(() => {
53
+ const onNotice = (e: Event) => {
54
+ const n = (e as CustomEvent).detail as { surfaceId?: string } | undefined;
55
+ if (n?.surfaceId && n.surfaceId !== cardId) return;
56
+ setSubmitting(false);
57
+ };
58
+ window.addEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
59
+ return () => window.removeEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
60
+ }, [cardId]);
61
+
48
62
  // 壳侧 openParkingPay/openParkingUnpaidOrder 回执 data 形态(厂商协议)
49
63
  type PayResult = {
50
64
  payStatus?: 'success' | 'fail' | 'unpaid' | 'cancelled' | 'none';
@@ -366,6 +366,8 @@ export function createParkingActions(
366
366
  }
367
367
 
368
368
  // PAYING 持久化(悬挂收口锚点,V2)
369
+ // quoteProjection:报价投影随建单快照(对齐 entryAt 同模式——PAID 原卡翻转
370
+ // 要重灌终态卡数据,而 W4 报价缓存仅 UNPAID 态可见、届时不可达)
369
371
  await persistPaymentOperation(state, {
370
372
  paymentRef,
371
373
  providerPaymentRef,
@@ -382,6 +384,12 @@ export function createParkingActions(
382
384
  ...(payOrderFlowId ? { payOrderFlowId } : {}),
383
385
  status: 'PAYING',
384
386
  createdAt: new Date().toISOString(),
387
+ quoteProjection: {
388
+ totalCents: quote.totalCents,
389
+ discountCents: quote.discountCents,
390
+ revision: quote.revision,
391
+ feeItems: quote.feeItems,
392
+ },
385
393
  });
386
394
 
387
395
  // step2:payment effect(dispatcher 补签 → client tradePay,R1 orderInfo 内联)
@@ -467,6 +475,20 @@ export function createParkingActions(
467
475
  const current = settled ?? op;
468
476
 
469
477
  if (current.status === 'PAID') {
478
+ // PAID 原卡翻转(host-effect-card-anchor D2 出/刷二分):经 dispatcher 签名锚定
479
+ // 原地回写发起报价卡——成功回执新卡冗余(历史凭证由缴费记录卡兜底)。
480
+ // 投影缺失(存量 PAYING 单、旧版本发起)降级出新回执卡,零回归。
481
+ if (current.quoteProjection) {
482
+ return {
483
+ update: {
484
+ data: settledPaymentCardData(
485
+ { ...current, ...current.quoteProjection },
486
+ { state: 'paid', text: '已完成支付,请在 15 分钟内离场,超时将重新计费' },
487
+ ),
488
+ },
489
+ text: '停车费支付成功',
490
+ };
491
+ }
470
492
  return {
471
493
  card: paymentResultCard({
472
494
  paymentRef,
@@ -661,7 +683,8 @@ export function createParkingActions(
661
683
  vehicleRef?: string;
662
684
  };
663
685
  const s = await serviceOf(reqCtx, resolveParkingVehiclePort);
664
- if (!s || !plateNo) return { text: '解绑失败:缺少车牌或车辆引用' };
686
+ // 与下方 matched 双路匹配同构:车牌或引用任一在场即放行(卡片按钮路径只传 vehicleRef)
687
+ if (!s || (!plateNo && !vehicleRef)) return { text: '解绑失败:缺少车牌或车辆引用' };
665
688
  // 列表匹配与刷新走 query 槽;解绑写走 vehicle 槽(双槽动作,方法分属)
666
689
  const query = await resolveParkingQueryPort(reqCtx as RequestContext, ctx);
667
690
  const { bound } = await query.listVehicles(s.q);
@@ -1,14 +1,14 @@
1
- /** parking 卡 meta 聚合(015 S5:5 卡;key 约定 = meta.cardType) */
1
+ /** parking 卡 meta 聚合(015 S5:5 卡;key 约定 = meta.cardType;书序与 CardMeta.order 预览序位一致) */
2
+ import parkingVehicleManagement from './parking-vehicle-management/meta';
3
+ import parkingInfo from './parking-info/meta';
2
4
  import parkingPayment from './parking-payment/meta';
3
5
  import parkingPaymentResult from './parking-payment-result/meta';
4
6
  import parkingPaymentRecords from './parking-payment-records/meta';
5
- import parkingVehicleManagement from './parking-vehicle-management/meta';
6
- import parkingInfo from './parking-info/meta';
7
7
 
8
8
  export const parkingCards = {
9
+ 'parking-vehicle-management': parkingVehicleManagement,
10
+ 'parking-info': parkingInfo,
9
11
  'parking-payment': parkingPayment,
10
12
  'parking-payment-result': parkingPaymentResult,
11
13
  'parking-payment-records': parkingPaymentRecords,
12
- 'parking-vehicle-management': parkingVehicleManagement,
13
- 'parking-info': parkingInfo,
14
14
  } as const;
@@ -14,6 +14,7 @@ const meta: CardMeta<typeof parkingInfoCardDataSchema> = {
14
14
  },
15
15
  samples,
16
16
  schemaVersion: 1,
17
+ order: 2,
17
18
  };
18
19
 
19
20
  export default meta;
@@ -24,6 +24,7 @@ const meta: CardMeta<typeof parkingPaymentCardDataSchema> = {
24
24
  },
25
25
  samples,
26
26
  schemaVersion: 1,
27
+ order: 3,
27
28
  };
28
29
 
29
30
  export default meta;
@@ -6,6 +6,9 @@
6
6
  * - 视觉等价的输入合并一格、note 列全(沉默会员态三格合一就是这个原因);
7
7
  * - 覆盖基准是组件真正读的 data 分支(settlement 终态/优惠矩阵/互斥/零费用/令牌缺席),
8
8
  * 不是 sampleData 的形状;
9
+ * - 预览只保留五格附加样本(加服务端合成的「初始态」共六格):零费用/长时长/支付完成/
10
+ * 三类优惠混合/未入会有券;其余 hidden: true,真源保留且 shape/schema 质量检查仍全量巡走;
11
+ * 恢复展示 = 移除标记;
9
12
  * - 样本即契约:data 必须 dataSchema 校验通过且无 shape 外键(tests/samples.test.ts 双断言)。
10
13
  */
11
14
  import type { CardSample } from '@tbox.cn/app-contracts';
@@ -68,6 +71,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
68
71
  label: '标准形态',
69
72
  note: 'hero meta「入场 · 已停」+ summary 已停时长 + 页脚 caveats 齐全,其余格子的基线',
70
73
  group: BASIC,
74
+ hidden: true,
71
75
  data: {
72
76
  ...BASE, quoteRef: 'b_std', membership: MEMBER_ACTIVE,
73
77
  payableText: '15.00 元', appliedBenefits: [], selectableBenefits: [],
@@ -108,6 +112,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
108
112
  label: '历史卡',
109
113
  note: 'isHistory——hero 右上出「历史报价」(当前卡不出这个角标),全部动作禁用',
110
114
  group: BASIC,
115
+ hidden: true,
111
116
  data: {
112
117
  ...BASE, quoteRef: 'b_hist', entryAtText: '08-13 09:10',
113
118
  membership: MEMBER_ACTIVE,
@@ -120,6 +125,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
120
125
  label: '授权已过期',
121
126
  note: 'confirmToken 缺席(单次令牌已消费/超时)→ 按钮置灰 + 红字说明。此前画廊恒喂令牌,这一态从没渲染过',
122
127
  group: BASIC,
128
+ hidden: true,
123
129
  data: {
124
130
  ...BASE, quoteRef: 'b_notoken', membership: MEMBER_ACTIVE,
125
131
  payableText: '15.00 元', appliedBenefits: [], selectableBenefits: [POINTS_BENEFIT],
@@ -130,6 +136,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
130
136
  label: '终态·支付处理中',
131
137
  note: 'settlement.paying——confirm-payment 原地写入,按钮恒置灰、优惠区不再可改',
132
138
  group: BASIC,
139
+ hidden: true,
133
140
  data: {
134
141
  ...BASE, quoteRef: 'b_paying', membership: MEMBER_ACTIVE,
135
142
  discountText: '5.75 元', payableText: '9.25 元',
@@ -152,6 +159,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
152
159
  label: '终态·支付未完成',
153
160
  note: 'settlement.failed——需重新查询报价',
154
161
  group: BASIC,
162
+ hidden: true,
155
163
  data: {
156
164
  ...BASE, quoteRef: 'b_failed', membership: MEMBER_ACTIVE,
157
165
  payableText: '15.00 元',
@@ -168,6 +176,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
168
176
  label: '已入会·无任何优惠',
169
177
  note: 'selectableBenefits 空 → 优惠区整块不渲染',
170
178
  group: MATRIX,
179
+ hidden: true,
171
180
  data: {
172
181
  ...BASE, quoteRef: 'm_none', membership: MEMBER_ACTIVE,
173
182
  payableText: '15.00 元', appliedBenefits: [], selectableBenefits: [],
@@ -177,6 +186,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
177
186
  label: '已入会·只有券',
178
187
  note: '券已 autoSelected 生效 → 按钮报 9.00 元(与「当前应付」同源)',
179
188
  group: MATRIX,
189
+ hidden: true,
180
190
  data: {
181
191
  ...BASE, quoteRef: 'm_coupon', membership: MEMBER_ACTIVE,
182
192
  discountText: '6.00 元', payableText: '9.00 元',
@@ -188,6 +198,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
188
198
  label: '已入会·只有等级权益',
189
199
  note: '唯一优惠是自动生效的等级权益 → 优惠区无可勾项、整块不渲染,减免只在费用明细现身',
190
200
  group: MATRIX,
201
+ hidden: true,
191
202
  data: {
192
203
  ...BASE, quoteRef: 'm_level', membership: MEMBER_ACTIVE,
193
204
  discountText: '0.75 元', payableText: '14.25 元',
@@ -198,6 +209,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
198
209
  label: '已入会·只有积分',
199
210
  note: '积分未勾 → 按钮仍报 15.00 元,勾上才 reprice。paymentOptions 的 exact 与 requires_reprice 两态卡上无差别(客户端已不读该字段),故不再各占一格',
200
211
  group: MATRIX,
212
+ hidden: true,
201
213
  data: {
202
214
  ...BASE, quoteRef: 'm_points', membership: MEMBER_ACTIVE,
203
215
  payableText: '15.00 元', appliedBenefits: [], selectableBenefits: [POINTS_BENEFIT],
@@ -211,6 +223,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
211
223
  label: '已入会·券 + 积分可叠加',
212
224
  note: '两类都无 exclusiveWithKinds → 默认可叠加,勾选互不影响',
213
225
  group: MATRIX,
226
+ hidden: true,
214
227
  data: {
215
228
  ...BASE, quoteRef: 'm_stack', membership: MEMBER_ACTIVE,
216
229
  discountText: '6.00 元', payableText: '9.00 元',
@@ -222,6 +235,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
222
235
  label: '已入会·券与积分互斥',
223
236
  note: '券标 exclusiveWithKinds:[points]——勾任一方都会撤下另一方(判定双向)。互斥在勾选前完全不可见:两项外观与可叠加的一模一样,description 也没被渲染',
224
237
  group: MATRIX,
238
+ hidden: true,
225
239
  data: {
226
240
  ...BASE, quoteRef: 'm_conflict', membership: MEMBER_ACTIVE,
227
241
  payableText: '15.00 元', appliedBenefits: [],
@@ -246,6 +260,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
246
260
  label: '等级权益·需用户选择',
247
261
  note: 'discount + autoSelected=false——厂商要求用户主动选,故仍留在勾选区,不走自动生效那条路',
248
262
  group: MATRIX,
263
+ hidden: true,
249
264
  data: {
250
265
  ...BASE, quoteRef: 'm_level_opt', membership: MEMBER_ACTIVE,
251
266
  payableText: '15.00 元', appliedBenefits: [],
@@ -259,6 +274,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
259
274
  label: '⚠ 已入会·积分不足',
260
275
  note: 'availablePoints < requiredPoints → 服务端撤掉 points 入口,但积分项仍在优惠区可勾。勾了会重算失败,卡上没有一处说明「积分不够」',
261
276
  group: MATRIX,
277
+ hidden: true,
262
278
  data: {
263
279
  ...BASE, quoteRef: 'm_insufficient',
264
280
  membership: { state: 'active', availablePoints: 120 },
@@ -282,6 +298,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
282
298
  label: '未入会·无优惠',
283
299
  note: '最朴素的未入会态:只有引导条',
284
300
  group: MATRIX,
301
+ hidden: true,
285
302
  data: {
286
303
  ...BASE, quoteRef: 'm_ne',
287
304
  membership: { state: 'not_enrolled' },
@@ -292,6 +309,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
292
309
  label: '未登录',
293
310
  note: 'unauthenticated——同一条引导换成「去登录」',
294
311
  group: MATRIX,
312
+ hidden: true,
295
313
  data: {
296
314
  ...BASE, quoteRef: 'm_anon', durationText: '3 小时 05 分', entryAtText: undefined,
297
315
  membership: { state: 'unauthenticated' },
@@ -302,6 +320,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
302
320
  label: '⚠ 会员态沉默',
303
321
  note: 'unknown / closed / unavailable 三态渲染完全相同——组件只认 not_enrolled 与 unauthenticated,这三个既无积分入口也无任何说明,与「已入会但商场无积分权益」无法区分。三格合一,差异只在 data',
304
322
  group: MATRIX,
323
+ hidden: true,
305
324
  data: {
306
325
  ...BASE, quoteRef: 'm_silent',
307
326
  membership: { state: 'closed' },
@@ -27,6 +27,7 @@ const meta: CardMeta<typeof parkingPaymentRecordsCardDataSchema> = {
27
27
  samples,
28
28
  schemaVersion: 2,
29
29
  migrate: (oldData) => oldData as Record<string, unknown>,
30
+ order: 5,
30
31
  };
31
32
 
32
33
  export default meta;
@@ -70,6 +70,7 @@ export const samples: CardSample<ParkingPaymentRecordsCardData>[] = [
70
70
  message: RECORD_DETAIL_MESSAGE,
71
71
  },
72
72
  isHistory: true,
73
+ hidden: true,
73
74
  },
74
75
  {
75
76
  label: '授权已过期',
@@ -82,5 +83,6 @@ export const samples: CardSample<ParkingPaymentRecordsCardData>[] = [
82
83
  total: 1, hasMore: false, caveats: ['仅展示近 6 个月缴费记录'],
83
84
  },
84
85
  noTokens: true,
86
+ hidden: true,
85
87
  },
86
88
  ];
@@ -16,6 +16,7 @@ const meta: CardMeta<typeof parkingPaymentResultCardDataSchema> = {
16
16
  },
17
17
  samples,
18
18
  schemaVersion: 1,
19
+ order: 4,
19
20
  };
20
21
 
21
22
  export default meta;
@@ -36,6 +36,7 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
36
36
  { label: '缴费时间', value: '今天 18:02' },
37
37
  ],
38
38
  },
39
+ hidden: true,
39
40
  },
40
41
  {
41
42
  label: '厂商确认中',
@@ -50,6 +51,7 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
50
51
  { label: '缴费时间', value: '今天 10:31' },
51
52
  ],
52
53
  },
54
+ hidden: true,
53
55
  },
54
56
  {
55
57
  label: '极简·无金额无明细',
@@ -59,6 +61,7 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
59
61
  paymentRef: 'PO55667788', plateNo: '浙A12345', status: 'UNKNOWN',
60
62
  message: '支付结果确认中,稍后可在缴费记录中核对', retryable: true,
61
63
  },
64
+ hidden: true,
62
65
  },
63
66
  {
64
67
  label: '授权已过期',
@@ -70,6 +73,7 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
70
73
  details: [{ label: '车牌', value: '浙A12345' }],
71
74
  },
72
75
  noTokens: true,
76
+ hidden: true,
73
77
  },
74
78
  {
75
79
  label: '历史卡',
@@ -80,5 +84,6 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
80
84
  amountText: '9.25 元', message: '支付结果确认中', retryable: true,
81
85
  },
82
86
  isHistory: true,
87
+ hidden: true,
83
88
  },
84
89
  ];
@@ -15,6 +15,7 @@ const meta: CardMeta<typeof parkingVehicleManagementCardDataSchema> = {
15
15
  },
16
16
  samples,
17
17
  schemaVersion: 1,
18
+ order: 1,
18
19
  };
19
20
 
20
21
  export default meta;
@@ -60,6 +60,7 @@ export const samples: CardSample<ParkingVehicleManagementCardData>[] = [
60
60
  membership: { state: 'not_enrolled' },
61
61
  },
62
62
  isHistory: true,
63
+ hidden: true,
63
64
  },
64
65
  {
65
66
  label: '授权已过期',
@@ -69,5 +70,6 @@ export const samples: CardSample<ParkingVehicleManagementCardData>[] = [
69
70
  bound: [{ vehicleRef: 'v_1', plateNo: '浙A12345', parked: true }],
70
71
  },
71
72
  noTokens: true,
73
+ hidden: true,
72
74
  },
73
75
  ];
@@ -218,6 +218,32 @@ describe('parking × dispatcher 集成回归锁(reqCtx 注入语义)', () =>
218
218
  ).toHaveLength(0);
219
219
  });
220
220
 
221
+ it('解绑客户端真实路径:formData 只传 vehicleRef(卡片按钮 vehicleAction 契约)', async () => {
222
+ const { sessions, grants, dispatcher, svc } = buildHarness();
223
+ const session = sessions.bootstrap(makeReqCtx());
224
+ const bound = await svc.api.bindVehicle({} as never, '苏E11111');
225
+ const emitted: unknown[] = [];
226
+ const result = await dispatcher.dispatch({
227
+ token: await grants.issue({
228
+ moduleId: 'parking',
229
+ actionId: 'parking.unbind-vehicle',
230
+ cardType: 'parking-vehicle-management',
231
+ sessionId: session.sessionId,
232
+ scope: { miniAppId: 'app', mallId: 'mall-1' },
233
+ singleUse: true,
234
+ cardId: 'card_v1',
235
+ }),
236
+ actionId: 'parking.unbind-vehicle',
237
+ sessionId: session.sessionId,
238
+ surfaceId: 'card_v1',
239
+ ctx: makeReqCtx(),
240
+ formData: { vehicleRef: bound.vehicleRef },
241
+ emit: (e) => emitted.push(e),
242
+ });
243
+ expect(result.text).toBe('解绑成功');
244
+ expect(svc.bound).toHaveLength(0);
245
+ });
246
+
221
247
  it('入参非法 → INPUT_INVALID 且令牌可重试(统一护栏在模块链路生效)', async () => {
222
248
  const { sessions, grants, dispatcher } = buildHarness();
223
249
  const session = sessions.bootstrap(makeReqCtx());
@@ -418,3 +418,90 @@ describe('P1:confirm-payment 签名空串防御', () => {
418
418
  expect((await loadPaymentOperation(state, paymentRef!))?.quoteRef).toBe('q_2');
419
419
  });
420
420
  });
421
+
422
+ describe('D2/D3:PAID 原卡翻转(host-effect-card-anchor)', () => {
423
+ /** 三步链 fake 服务:建单 → 签名 → 上报后 reconcile 收口 */
424
+ const makeThreeStepService = (
425
+ reconcileResult: 'PAID' | 'CANCELLED' | 'PAYING',
426
+ ): ParkingService &
427
+ Record<'uploadResult' | 'reconcile', ReturnType<typeof vi.fn>> =>
428
+ ({
429
+ createOrder: async () => ({ payOrderId: 'PO1234567890', paymentRef: 'p_3step' }),
430
+ getOrderInfo: async () => ({ channel: '50', payableFeeCents: 1425 }),
431
+ getPaymentSign: async () => ({ orderInfo: 'sign_3step' }),
432
+ uploadResult: vi.fn(async () => undefined),
433
+ reconcile: vi.fn(async () => reconcileResult),
434
+ }) as never;
435
+
436
+ const makeReqCtx = () =>
437
+ ({
438
+ identity: { userId: 'u_1', source: 'local' },
439
+ attributes: { mall: { miniAppId: 'app', mallId: 'mall-1' } },
440
+ }) as never;
441
+
442
+ const setupConfirm = async (reconcileResult: 'PAID' | 'CANCELLED' | 'PAYING') => {
443
+ const state = createInMemoryStateStore();
444
+ mockAllSlots(makeThreeStepService(reconcileResult));
445
+ await cacheQuote(state, makeQuote(), owner);
446
+ const actions = createParkingActions({ state } as never);
447
+ const confirmed = await actions.confirmPayment.execute!(
448
+ { quoteRef: 'q_1', revision: '1' },
449
+ makeReqCtx(),
450
+ );
451
+ const paymentRef = (confirmed.effects?.[0] as { paymentRef?: string } | undefined)!
452
+ .paymentRef!;
453
+ return { state, actions, confirmed, paymentRef };
454
+ };
455
+
456
+ it('T5 全链路:confirm 快照投影 → PAID → update 原卡翻转,出新卡为零', async () => {
457
+ const { state, actions, confirmed, paymentRef } = await setupConfirm('PAID');
458
+ // step1 断言:quoteProjection 随建单快照落库(对齐 entryAt 同模式)
459
+ const op = await loadPaymentOperation(state, paymentRef);
460
+ expect(op?.quoteProjection).toEqual({
461
+ totalCents: 1500,
462
+ discountCents: 75,
463
+ revision: 1,
464
+ feeItems: [{ name: '停车费', amountCents: 1500 }],
465
+ });
466
+ // confirm 既出 update(paying 态原卡)又出 effect——翻转语义由 step3 完成
467
+ expect((confirmed.update?.data as { settlement?: { state?: string } }).settlement)
468
+ .toMatchObject({ state: 'paying' });
469
+ // step3:宿主回传 success → reconcile PAID → 原卡翻转 paid(不出新卡)
470
+ const reported = await actions.reportPaymentResult.execute!(
471
+ { status: 'success', paymentRef },
472
+ makeReqCtx(),
473
+ );
474
+ expect(reported.card).toBeUndefined();
475
+ const data = reported.update?.data as Record<string, unknown> & {
476
+ settlement: { state: string; text: string };
477
+ };
478
+ expect(data.settlement.state).toBe('paid');
479
+ expect(data.settlement.text).toContain('已完成支付');
480
+ expect(data.quoteRef).toBe('q_1');
481
+ expect(data.plateNo).toBe('浙A12345');
482
+ expect(data.totalText).toBe('15.00 元');
483
+ // 服务端 discountText 原样正值(负号归一是客户端 formatDiscountText 的展示职责)
484
+ expect(data.discountText).toBe('0.75 元');
485
+ expect(data.payableText).toBe('14.25 元');
486
+ expect(data.feeItems).toEqual([{ name: '停车费', amountText: '15.00 元' }]);
487
+ expect(data.selectableBenefits).toEqual([]);
488
+ expect(data.revision).toBe(1);
489
+ expect(reported.text).toBe('停车费支付成功');
490
+ });
491
+
492
+ it('T6 降级链:无投影 op(存量 PAYING 单)→ PAID 仍出新回执卡(零回归)', async () => {
493
+ // 直接持久化旧形态 op(无 quoteProjection),绕过 confirm 建单
494
+ const state = createInMemoryStateStore();
495
+ mockAllSlots(makeThreeStepService('PAID'));
496
+ await persistPaymentOperation(state, makeOp());
497
+ const actions = createParkingActions({ state } as never);
498
+ const reported = await actions.reportPaymentResult.execute!(
499
+ { status: 'success', paymentRef: 'p_1' },
500
+ makeReqCtx(),
501
+ );
502
+ expect(reported.update).toBeUndefined();
503
+ expect(reported.card?.cardType).toBe('parking-payment-result');
504
+ expect((reported.card?.data as { status?: string }).status).toBe('PAID');
505
+ expect(reported.text).toBe('停车费支付成功');
506
+ });
507
+ });
@@ -36,9 +36,39 @@ describe('parking samples 双断言(样本即契约)', () => {
36
36
  expect(resultMeta.samples).toHaveLength(6);
37
37
  });
38
38
 
39
- it('变体标志在场:isHistory 与 noTokens 样本均存在(预览页考察载体)', () => {
39
+ it('历史与授权失效样本保留质量检查但不进入 Preview', () => {
40
40
  const all: CardSample[] = metas.flatMap((m) => (m.samples ?? []) as CardSample[]);
41
- expect(all.some((s) => s.isHistory)).toBe(true);
42
- expect(all.some((s) => s.noTokens)).toBe(true);
41
+ const histories = all.filter((sample) => sample.isHistory === true);
42
+ const noTokens = all.filter((sample) => sample.noTokens === true);
43
+ expect(histories.length).toBeGreaterThan(0);
44
+ expect(noTokens.length).toBeGreaterThan(0);
45
+ expect(histories.every((sample) => sample.hidden === true)).toBe(true);
46
+ expect(noTokens.every((sample) => sample.hidden === true)).toBe(true);
47
+ });
48
+
49
+ it('支付回执负向、过程与降级样本不进入 Preview', () => {
50
+ const hiddenLabels = new Set(
51
+ (resultMeta.samples ?? []).filter((sample) => sample.hidden === true).map((sample) => sample.label),
52
+ );
53
+ expect(hiddenLabels).toEqual(new Set([
54
+ '支付取消',
55
+ '厂商确认中',
56
+ '极简·无金额无明细',
57
+ '授权已过期',
58
+ '历史卡',
59
+ ]));
60
+ });
61
+
62
+ it('停车缴费 Preview 只保留五个互补的附加样本', () => {
63
+ const visibleLabels = (paymentMeta.samples ?? [])
64
+ .filter((sample) => sample.hidden !== true)
65
+ .map((sample) => sample.label);
66
+ expect(visibleLabels).toEqual([
67
+ '零费用',
68
+ '多费项·跨日长时长',
69
+ '终态·已完成支付',
70
+ '已入会·三类混合',
71
+ '未入会·有券',
72
+ ]);
43
73
  });
44
74
  });