@tbox.cn/app-provider-mock 0.7.2 → 0.7.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.
package/README.md CHANGED
@@ -12,7 +12,8 @@ parking×3 / promotion×4 / shopping-guide×4 + mall.info,17 槽全 local:true
12
12
 
13
13
  2026-09-20 拆分([docs/plans/mock-provider-split/](../../docs/plans/mock-provider-split/)):
14
14
  本包**退役全部 config 面**——17 槽无 `configSchema`、无 `src/server/config.ts`,演示常量
15
- 冻结于各 impl(值 ≡ 0.4.0 缺省)。零配置 = 零行为变化。
15
+ 由各 impl 自持(多数域值 ≡ 0.4.0 缺省;parking 自 0.7.3 由 `parkedMinutes=162` 派生入场/费项)。
16
+ 零配置 = 零 `configSchema`(演示行为仍随包版本演进)。
16
17
 
17
18
  - **0.4.0 → 0.5.0 迁移指引**:此前通过 `integrations.json`(root/slot/module 任意层)配置过
18
19
  `cardName`/`feeCents`/`couponTitle` 等 33 字段的部署,升级后这些键**不再生效**(fail-soft
@@ -72,7 +72,8 @@ declare class MockMemberServiceImpl implements MockMemberService {
72
72
  * 演示位(parked 徽标与无线索查费扫描共用该语义)。写操作要求登录态(对齐真实厂商
73
73
  * 「无令牌不可写」),读操作匿名降级为空车队;无车辆线索查费扫描属人车队,空车队
74
74
  * 返回空(调用方引导绑定)。
75
- * 演示常量零配置冻结:CFG 值 ≡ 0.4.0 缺省(2026-09-20 拆分——config 消费随 provider-mocktest 迁出)。
75
+ * 演示常量零配置:CFG 自持(2026-09-20 拆分——config 消费随 provider-mocktest 迁出);
76
+ * 报价的入场时间/费项名/金额由同一 parkedMinutes 派生(禁止两源漂移)。
76
77
  */
77
78
 
78
79
  type MockParkingService = ParkingQueryPort & ParkingPaymentPort & ParkingVehiclePort;
@@ -88,6 +89,7 @@ declare class MockParkingServiceImpl implements MockParkingService {
88
89
  * 等级权益会退化成一个可勾选项,积分入口则从不出现。
89
90
  */
90
91
  private benefits;
92
+ /** entryAt 可由 reprice 传入以复用原报价锚点;新报价默认取演示入场时刻 */
91
93
  private quote;
92
94
  queryFee(q: ParkingQueryContext, input: {
93
95
  plateNo?: string;
@@ -148,24 +148,40 @@ var MockMemberServiceImpl = class {
148
148
  var now = () => (/* @__PURE__ */ new Date()).toISOString();
149
149
  var CFG2 = {
150
150
  parkName: "\u793A\u4F8B\u505C\u8F66\u573A",
151
- feeName: "\u505C\u8F66\u8D39\uFF083 \u5C0F\u65F6\uFF09",
152
- feeCents: 1500,
151
+ parkedMinutes: 162,
152
+ hourlyRateCents: 500,
153
+ dailyCapCents: 6e3,
153
154
  remainingSpaces: 128,
154
- firstHourRate: "\u514D\u8D39",
155
+ firstHourRate: "5.00 \u5143/\u5C0F\u65F6",
155
156
  memberBenefitEnabled: true,
156
- memberBenefitDiscountCents: 75,
157
157
  pointsBenefitEnabled: true,
158
158
  invoiceEnabled: true,
159
159
  vehicleFloor: "B1",
160
160
  vehicleZone: "A \u533A",
161
161
  vehicleSpaceNo: "A-128"
162
162
  };
163
+ function billedHours(minutes) {
164
+ return Math.max(1, Math.ceil(minutes / 60));
165
+ }
166
+ function demoFee() {
167
+ const hours = billedHours(CFG2.parkedMinutes);
168
+ return {
169
+ name: `\u505C\u8F66\u8D39\uFF08${hours} \u5C0F\u65F6\uFF09`,
170
+ amountCents: Math.min(hours * CFG2.hourlyRateCents, CFG2.dailyCapCents)
171
+ };
172
+ }
173
+ function demoEntryAt() {
174
+ return new Date(Date.now() - CFG2.parkedMinutes * 6e4).toISOString();
175
+ }
163
176
  var MAX_BOUND_VEHICLES = 3;
164
177
  var mockParkingState = {
165
- vehicles: /* @__PURE__ */ new Map()
178
+ vehicles: /* @__PURE__ */ new Map(),
179
+ /** quoteRef → 车牌/入场时间(reprice 跨请求复用同一辆车的报价锚点) */
180
+ quotes: /* @__PURE__ */ new Map()
166
181
  };
167
182
  function __resetMockParkingState() {
168
183
  mockParkingState.vehicles.clear();
184
+ mockParkingState.quotes.clear();
169
185
  }
170
186
  var MockParkingServiceImpl = class {
171
187
  records;
@@ -175,7 +191,7 @@ var MockParkingServiceImpl = class {
175
191
  {
176
192
  recordRef: "demo:record:1",
177
193
  plateNo: "demo-plate",
178
- amountCents: CFG2.feeCents,
194
+ amountCents: demoFee().amountCents,
179
195
  paidAt: now(),
180
196
  status: "PAID",
181
197
  parkName: CFG2.parkName,
@@ -191,24 +207,30 @@ var MockParkingServiceImpl = class {
191
207
  */
192
208
  benefits() {
193
209
  const benefits = [];
210
+ const feeCents = demoFee().amountCents;
211
+ const memberDiscountCents = Math.round(feeCents * 0.05);
194
212
  if (CFG2.memberBenefitEnabled) {
195
- benefits.push({ benefitRef: "demo:benefit:member-discount", title: "\u4F1A\u5458 95 \u6298", description: "mock \u6F14\u793A\u6743\u76CA", kind: "discount", autoSelected: true, estimatedDiscountCents: CFG2.memberBenefitDiscountCents });
213
+ benefits.push({ benefitRef: "demo:benefit:member-discount", title: "\u4F1A\u5458 95 \u6298", description: "mock \u6F14\u793A\u6743\u76CA", kind: "discount", autoSelected: true, estimatedDiscountCents: memberDiscountCents });
196
214
  }
197
215
  if (CFG2.pointsBenefitEnabled) {
198
- benefits.push({ benefitRef: "demo:benefit:points-offset", title: "\u79EF\u5206\u62B5 5 \u5143", description: "mock \u6F14\u793A\u6743\u76CA", kind: "points", autoSelected: false, estimatedDiscountCents: 500, requiredPoints: 500, previewPayableCents: 1e3 });
216
+ benefits.push({ benefitRef: "demo:benefit:points-offset", title: "\u79EF\u5206\u62B5 5 \u5143", description: "mock \u6F14\u793A\u6743\u76CA", kind: "points", autoSelected: false, estimatedDiscountCents: 500, requiredPoints: 500, previewPayableCents: Math.max(0, feeCents - 500) });
199
217
  }
200
218
  return benefits;
201
219
  }
202
- quote(q, plateNo) {
220
+ /** entryAt 可由 reprice 传入以复用原报价锚点;新报价默认取演示入场时刻 */
221
+ quote(q, plateNo, entryAt = demoEntryAt()) {
222
+ const quoteRef = `demo:quote:${plateNo}`;
223
+ mockParkingState.quotes.set(quoteRef, { plateNo, entryAt });
224
+ const fee = demoFee();
203
225
  return {
204
- quoteRef: `demo:quote:${plateNo}`,
226
+ quoteRef,
205
227
  plateNo,
206
228
  mallId: q.scope.mallId ?? "demo",
207
- entryAt: now(),
208
- feeItems: [{ name: CFG2.feeName, amountCents: CFG2.feeCents }],
209
- totalCents: CFG2.feeCents,
229
+ entryAt,
230
+ feeItems: [{ name: fee.name, amountCents: fee.amountCents }],
231
+ totalCents: fee.amountCents,
210
232
  discountCents: 0,
211
- payableCents: CFG2.feeCents,
233
+ payableCents: fee.amountCents,
212
234
  appliedBenefits: [],
213
235
  revision: 1,
214
236
  paymentState: "UNPAID"
@@ -265,7 +287,7 @@ var MockParkingServiceImpl = class {
265
287
  return { payOrderId: `demo:pay:${quoteRef}`, paymentRef: `demo:payment:${quoteRef}` };
266
288
  }
267
289
  async getOrderInfo(_q, _paymentRef) {
268
- return { orderInfo: "demo-order-info", channel: "50", payableFeeCents: CFG2.feeCents };
290
+ return { orderInfo: "demo-order-info", channel: "50", payableFeeCents: demoFee().amountCents };
269
291
  }
270
292
  async getPaymentSign(_q, _paymentRef) {
271
293
  return { orderInfo: "demo-order-info" };
@@ -276,11 +298,14 @@ var MockParkingServiceImpl = class {
276
298
  return "PAID";
277
299
  }
278
300
  async reprice(q, quoteRef, benefitRefs) {
279
- const base = this.quote(q, "demo-plate");
301
+ const baseRef = quoteRef.replace(/(?:#r\d+)+$/, "");
302
+ const cached = mockParkingState.quotes.get(baseRef);
303
+ const plateFromRef = baseRef.startsWith("demo:quote:") ? baseRef.slice("demo:quote:".length) : "";
304
+ const base = this.quote(q, cached?.plateNo ?? (plateFromRef || "demo-plate"), cached?.entryAt);
280
305
  const discount = this.benefits().filter((b) => benefitRefs.includes(b.benefitRef)).reduce((sum, b) => sum + (b.estimatedDiscountCents ?? 0), 0);
281
306
  return {
282
307
  ...base,
283
- quoteRef: `${quoteRef}#r${Date.now()}`,
308
+ quoteRef: `${baseRef}#r${Date.now()}`,
284
309
  discountCents: discount,
285
310
  payableCents: Math.max(0, base.totalCents - discount)
286
311
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-provider-mock",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "type": "module",
5
5
  "description": "商圈 Mock Provider 包(极简零配置):18 槽 local 供给开箱即用(含 auth.alipay-login 标签供给——登录换码路由仍走 member.account 绑定);免传输/凭据/实例配置/集成配置;config 消费与配置验证面见 @tbox.cn/app-provider-mocktest。",
6
6
  "exports": {
@@ -15,9 +15,9 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@tbox.cn/app-contracts": "0.13.3",
18
- "@tbox.cn/app-contracts-mall": "0.13.2",
19
- "@tbox.cn/app-agent-sdk-client": "0.2.0",
20
- "@tbox.cn/app-agent-sdk-server": "0.3.1"
18
+ "@tbox.cn/app-contracts-mall": "0.14.0",
19
+ "@tbox.cn/app-agent-sdk-client": "0.2.1",
20
+ "@tbox.cn/app-agent-sdk-server": "0.3.3"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/express": "4.17.25",
@@ -12,8 +12,9 @@
12
12
  * (catalog 空 + shop/category/directory 纯 mock 数据);assistance/navigation 本地知识库域
13
13
  * 归模块本地 adapter,不属 provider 供给面。
14
14
  *
15
- * 零配置开箱(2026-09-20 拆分):五域工厂不带 config——演示常量冻结在各 impl
16
- * (值 ≡ 0.4.0 缺省);config 消费面随 provider-mocktest 迁出。
15
+ * 零配置开箱(2026-09-20 拆分):五域工厂不带 config——演示常量自持在各 impl
16
+ * (多数域值 ≡ 0.4.0 缺省;parking 报价自 0.7.3 由 parkedMinutes 派生入场/费项);
17
+ * config 消费面随 provider-mocktest 迁出。
17
18
  *
18
19
  * 隐式默认单实例(零拓扑部署兜底):register 期经 ctx.integrations.declareProviderInstances
19
20
  * 声明 mall-demo——显式 instances/defaultInstanceId 恒赢(融合规则见 contracts-mall
@@ -7,7 +7,8 @@
7
7
  * 演示位(parked 徽标与无线索查费扫描共用该语义)。写操作要求登录态(对齐真实厂商
8
8
  * 「无令牌不可写」),读操作匿名降级为空车队;无车辆线索查费扫描属人车队,空车队
9
9
  * 返回空(调用方引导绑定)。
10
- * 演示常量零配置冻结:CFG 值 ≡ 0.4.0 缺省(2026-09-20 拆分——config 消费随 provider-mocktest 迁出)。
10
+ * 演示常量零配置:CFG 自持(2026-09-20 拆分——config 消费随 provider-mocktest 迁出);
11
+ * 报价的入场时间/费项名/金额由同一 parkedMinutes 派生(禁止两源漂移)。
11
12
  */
12
13
  import type {
13
14
  ParkingBenefit,
@@ -27,15 +28,23 @@ export type MockParkingService = ParkingQueryPort & ParkingPaymentPort & Parking
27
28
 
28
29
  const now = () => new Date().toISOString();
29
30
 
30
- /** 演示常量(零配置冻结——0.5.0 起本包无 config 面;值 ≡ 0.4.0 缺省) */
31
+ /**
32
+ * 演示常量(零配置——0.5.0 起本包无 config 面)。
33
+ *
34
+ * 报价叙事固定为「入场 162 分钟前(2 小时 42 分)」:162 同时满足模块
35
+ * durationText 的 round(2.7→3)与计费 ceil(→3),使卡面「已停 3 小时」与
36
+ * 费项「停车费(3 小时)」同值。安全区间 [150, 180] 分钟;低于 150 或大于 180
37
+ * 时 round 与 ceil 分叉,会重新制造「时长短于计费小时」的旧缺陷。
38
+ * 费率 5.00 元/小时、每日封顶 60.00 元(与模块演示费率卡同源)。
39
+ */
31
40
  const CFG = {
32
41
  parkName: '示例停车场',
33
- feeName: '停车费(3 小时)',
34
- feeCents: 1500,
42
+ parkedMinutes: 162,
43
+ hourlyRateCents: 500,
44
+ dailyCapCents: 6000,
35
45
  remainingSpaces: 128,
36
- firstHourRate: '免费',
46
+ firstHourRate: '5.00 元/小时',
37
47
  memberBenefitEnabled: true,
38
- memberBenefitDiscountCents: 75,
39
48
  pointsBenefitEnabled: true,
40
49
  invoiceEnabled: true,
41
50
  vehicleFloor: 'B1',
@@ -43,6 +52,28 @@ const CFG = {
43
52
  vehicleSpaceNo: 'A-128',
44
53
  } as const;
45
54
 
55
+ /** 计费小时:不足 1 小时按 1 小时(向上取整) */
56
+ function billedHours(minutes: number): number {
57
+ return Math.max(1, Math.ceil(minutes / 60));
58
+ }
59
+
60
+ /**
61
+ * 演示报价单源:费项名与金额都从 parkedMinutes 派生。禁止分别硬编码——
62
+ * 否则卡面会出现「已停 X 小时 / 停车费(Y 小时)」两源不一致。
63
+ */
64
+ function demoFee(): { name: string; amountCents: number } {
65
+ const hours = billedHours(CFG.parkedMinutes);
66
+ return {
67
+ name: `停车费(${hours} 小时)`,
68
+ amountCents: Math.min(hours * CFG.hourlyRateCents, CFG.dailyCapCents),
69
+ };
70
+ }
71
+
72
+ /** 演示入场时刻:报价时恒为 parkedMinutes 之前(mock 无真实入场事件) */
73
+ function demoEntryAt(): string {
74
+ return new Date(Date.now() - CFG.parkedMinutes * 60_000).toISOString();
75
+ }
76
+
46
77
  /** 每用户绑定上限(与客户端车辆卡添加按钮上限同值——防御纵深:动作直调路径) */
47
78
  const MAX_BOUND_VEHICLES = 3;
48
79
 
@@ -53,11 +84,14 @@ const MAX_BOUND_VEHICLES = 3;
53
84
  */
54
85
  const mockParkingState = {
55
86
  vehicles: new Map<string, ParkingVehicle[]>(),
87
+ /** quoteRef → 车牌/入场时间(reprice 跨请求复用同一辆车的报价锚点) */
88
+ quotes: new Map<string, { plateNo: string; entryAt: string }>(),
56
89
  };
57
90
 
58
91
  /** 测试复位(沿 __resetMockMemberState 先例——模块级共享状态可重置) */
59
92
  export function __resetMockParkingState(): void {
60
93
  mockParkingState.vehicles.clear();
94
+ mockParkingState.quotes.clear();
61
95
  }
62
96
 
63
97
  export class MockParkingServiceImpl implements MockParkingService {
@@ -69,7 +103,7 @@ export class MockParkingServiceImpl implements MockParkingService {
69
103
  {
70
104
  recordRef: 'demo:record:1',
71
105
  plateNo: 'demo-plate',
72
- amountCents: CFG.feeCents,
106
+ amountCents: demoFee().amountCents,
73
107
  paidAt: now(),
74
108
  status: 'PAID',
75
109
  parkName: CFG.parkName,
@@ -87,25 +121,33 @@ export class MockParkingServiceImpl implements MockParkingService {
87
121
  */
88
122
  private benefits(): ParkingBenefit[] {
89
123
  const benefits: ParkingBenefit[] = [];
124
+ const feeCents = demoFee().amountCents;
125
+ // 会员 95 折 = 5% 减免(随演示费项金额派生,避免另一处硬编码)
126
+ const memberDiscountCents = Math.round(feeCents * 0.05);
90
127
  if (CFG.memberBenefitEnabled) {
91
- benefits.push({ benefitRef: 'demo:benefit:member-discount', title: '会员 95 折', description: 'mock 演示权益', kind: 'discount', autoSelected: true, estimatedDiscountCents: CFG.memberBenefitDiscountCents });
128
+ benefits.push({ benefitRef: 'demo:benefit:member-discount', title: '会员 95 折', description: 'mock 演示权益', kind: 'discount', autoSelected: true, estimatedDiscountCents: memberDiscountCents });
92
129
  }
93
130
  if (CFG.pointsBenefitEnabled) {
94
- benefits.push({ benefitRef: 'demo:benefit:points-offset', title: '积分抵 5 元', description: 'mock 演示权益', kind: 'points', autoSelected: false, estimatedDiscountCents: 500, requiredPoints: 500, previewPayableCents: 1000 });
131
+ benefits.push({ benefitRef: 'demo:benefit:points-offset', title: '积分抵 5 元', description: 'mock 演示权益', kind: 'points', autoSelected: false, estimatedDiscountCents: 500, requiredPoints: 500, previewPayableCents: Math.max(0, feeCents - 500) });
95
132
  }
96
133
  return benefits;
97
134
  }
98
135
 
99
- private quote(q: ParkingQueryContext, plateNo: string): QuoteSnapshot {
136
+ /** entryAt 可由 reprice 传入以复用原报价锚点;新报价默认取演示入场时刻 */
137
+ private quote(q: ParkingQueryContext, plateNo: string, entryAt = demoEntryAt()): QuoteSnapshot {
138
+ const quoteRef = `demo:quote:${plateNo}`;
139
+ // 跨请求实例重建后 reprice 仍要拿到同一辆车/同一入场时间(factory 每请求新建实例)
140
+ mockParkingState.quotes.set(quoteRef, { plateNo, entryAt });
141
+ const fee = demoFee();
100
142
  return {
101
- quoteRef: `demo:quote:${plateNo}`,
143
+ quoteRef,
102
144
  plateNo,
103
145
  mallId: q.scope.mallId ?? 'demo',
104
- entryAt: now(),
105
- feeItems: [{ name: CFG.feeName, amountCents: CFG.feeCents }],
106
- totalCents: CFG.feeCents,
146
+ entryAt,
147
+ feeItems: [{ name: fee.name, amountCents: fee.amountCents }],
148
+ totalCents: fee.amountCents,
107
149
  discountCents: 0,
108
- payableCents: CFG.feeCents,
150
+ payableCents: fee.amountCents,
109
151
  appliedBenefits: [],
110
152
  revision: 1,
111
153
  paymentState: 'UNPAID',
@@ -183,7 +225,7 @@ export class MockParkingServiceImpl implements MockParkingService {
183
225
  }
184
226
 
185
227
  async getOrderInfo(_q: ParkingQueryContext, _paymentRef: string): Promise<{ orderInfo?: string; channel: string; payableFeeCents: number | undefined }> {
186
- return { orderInfo: 'demo-order-info', channel: '50', payableFeeCents: CFG.feeCents };
228
+ return { orderInfo: 'demo-order-info', channel: '50', payableFeeCents: demoFee().amountCents };
187
229
  }
188
230
 
189
231
  async getPaymentSign(_q: ParkingQueryContext, _paymentRef: string): Promise<{ orderInfo: string }> {
@@ -199,12 +241,17 @@ export class MockParkingServiceImpl implements MockParkingService {
199
241
  }
200
242
 
201
243
  async reprice(q: ParkingQueryContext, quoteRef: string, benefitRefs: readonly string[]): Promise<QuoteSnapshot> {
202
- const base = this.quote(q, 'demo-plate');
244
+ // 同一报价单重算:车牌/入场时间从报价引用复原(不再固定 demo-plate、不再重锚入场时间);
245
+ // 引用可能已被上一次 reprice 追加 `#r<ts>`,剥离全部后缀后取注册表。
246
+ const baseRef = quoteRef.replace(/(?:#r\d+)+$/, '');
247
+ const cached = mockParkingState.quotes.get(baseRef);
248
+ const plateFromRef = baseRef.startsWith('demo:quote:') ? baseRef.slice('demo:quote:'.length) : '';
249
+ const base = this.quote(q, cached?.plateNo ?? (plateFromRef || 'demo-plate'), cached?.entryAt);
203
250
  const discount = this.benefits().filter((b) => benefitRefs.includes(b.benefitRef))
204
251
  .reduce((sum, b) => sum + (b.estimatedDiscountCents ?? 0), 0);
205
252
  return {
206
253
  ...base,
207
- quoteRef: `${quoteRef}#r${Date.now()}`,
254
+ quoteRef: `${baseRef}#r${Date.now()}`,
208
255
  discountCents: discount,
209
256
  payableCents: Math.max(0, base.totalCents - discount),
210
257
  };
@@ -3,7 +3,7 @@
3
3
  * 会员态为模块级共享 store(C5 入会闭环前提)——文件级复位保证用例顺序无关
4
4
  * (「初始 not_enrolled」类断言不依赖前序用例是否 enroll 过同一 userId)。
5
5
  */
6
- import { beforeEach, describe, expect, it } from 'vitest';
6
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
7
7
  import { MockMemberServiceImpl } from '../src/server/member';
8
8
  import { MockParkingServiceImpl, __resetMockParkingState } from '../src/server/parking';
9
9
  import { MockPromotionServiceImpl } from '../src/server/promotion';
@@ -116,6 +116,50 @@ describe('provider-mock:mock 实现 Port 面与厂商中立', () => {
116
116
  await expect(parking.reconcile(parkCtx, order.paymentRef)).resolves.toBe('PAID');
117
117
  });
118
118
 
119
+ it('parking reprice:保留原车牌与入场时间,#r 后缀不叠加(跨请求引用复原)', async () => {
120
+ vi.useFakeTimers();
121
+ try {
122
+ vi.setSystemTime(new Date('2026-10-27T10:17:00+08:00'));
123
+ const parking = new MockParkingServiceImpl('mall-demo');
124
+ const quote = (await parking.queryFee(parkCtx, { plateNo: '浙A12345' }))[0]!;
125
+ const first = await parking.reprice(parkCtx, quote.quoteRef, ['demo:benefit:member-discount']);
126
+ expect(first.plateNo).toBe('浙A12345');
127
+ expect(first.entryAt).toBe(quote.entryAt);
128
+ expect(first.quoteRef).toBe(`${quote.quoteRef}#r${Date.now()}`);
129
+ expect(first.discountCents).toBe(75);
130
+ // 已被 reprice 过的引用再次重算:剥离全部 #r 后缀后仍命中同一辆车/同一入场时间
131
+ const second = await parking.reprice(parkCtx, `${first.quoteRef}#r999`, ['demo:benefit:points-offset']);
132
+ expect(second.plateNo).toBe('浙A12345');
133
+ expect(second.entryAt).toBe(quote.entryAt);
134
+ expect(second.quoteRef.match(/#r/g)).toHaveLength(1);
135
+ expect(second.payableCents).toBe(1000);
136
+ } finally {
137
+ vi.useRealTimers();
138
+ }
139
+ });
140
+
141
+ it('parking:入场时间与费项同源(162 分钟前 / 3 小时 / 1500),round 与 ceil 同为 3', async () => {
142
+ vi.useFakeTimers();
143
+ try {
144
+ vi.setSystemTime(new Date('2026-10-27T10:17:00+08:00'));
145
+ const parking = new MockParkingServiceImpl('mall-demo');
146
+ const quote = (await parking.queryFee(parkCtx, { plateNo: 'demo-plate' }))[0]!;
147
+ const minutes = Math.round((Date.now() - new Date(quote.entryAt!).getTime()) / 60_000);
148
+ expect(minutes).toBe(162);
149
+ expect(quote.feeItems).toEqual([{ name: '停车费(3 小时)', amountCents: 1500 }]);
150
+ expect(quote.totalCents).toBe(1500);
151
+ // 演示偏移须同时满足模块 durationText 的 round 与计费 ceil,否则会重现「已停 X / 停车费(Y)」两源不一致
152
+ expect(Math.round(minutes / 60)).toBe(3);
153
+ expect(Math.ceil(minutes / 60)).toBe(3);
154
+ const info = await parking.queryParkingInfo(parkCtx, 'chargeRules');
155
+ expect(info.entries).toContainEqual({ label: '首小时费率', value: '5.00 元/小时' });
156
+ const [member] = await parking.queryApplicableBenefits(parkCtx, 'demo-plate');
157
+ expect(member?.estimatedDiscountCents).toBe(75);
158
+ } finally {
159
+ vi.useRealTimers();
160
+ }
161
+ });
162
+
119
163
  it('promotion:搜索/精查/推荐/资产/领取闭环,ref 恒 demo: 前缀', async () => {
120
164
  const promotion = new MockPromotionServiceImpl();
121
165
  const page = await promotion.searchOffers(promoCtx, { keyword: '' });