@tbox.cn/app-module-parking 0.10.9 → 0.10.11
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/dist/{chunk-BYN4OF6Z.js → chunk-YVL4JFJL.js} +37 -30
- package/dist/index.js +1 -1
- package/dist/server/index.d.ts +104 -104
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
- package/src/server/cards/parking-payment/meta.ts +9 -4
- package/src/server/cards/parking-payment/samples.ts +26 -21
- package/src/server/cards/parking-payment-records/samples.ts +1 -1
- package/src/server/cards/parking-payment-result/samples.ts +6 -6
- package/tests/pretool-parking-fee.test.ts +11 -1
- package/tests/samples.test.ts +72 -5
- package/tests/tools-gate.test.ts +45 -0
package/dist/server/index.js
CHANGED
package/package.json
CHANGED
|
@@ -10,16 +10,21 @@ const meta: CardMeta<typeof parkingPaymentCardDataSchema> = {
|
|
|
10
10
|
sampleData: {
|
|
11
11
|
quoteRef: 'q_demo',
|
|
12
12
|
plateNo: '浙A12345',
|
|
13
|
-
entryAtText: '08-14 07:
|
|
14
|
-
durationText: '
|
|
13
|
+
entryAtText: '08-14 07:35',
|
|
14
|
+
durationText: '2 小时 42 分',
|
|
15
15
|
feeItems: [{ name: '停车费(3 小时)', amountText: '15.00 元' }],
|
|
16
16
|
totalText: '15.00 元',
|
|
17
17
|
discountText: '5.75 元',
|
|
18
18
|
payableText: '9.25 元',
|
|
19
|
-
|
|
19
|
+
// 5.75 = 会员 95 折 0.75 + 积分 5.00:appliedBenefits 必须与 discountText 同源明细
|
|
20
|
+
appliedBenefits: [
|
|
21
|
+
{ benefitRef: 'member-discount', title: '会员 95 折', discountText: '0.75 元' },
|
|
22
|
+
{ benefitRef: 'points-offset', title: '积分抵 5 元', discountText: '5.00 元' },
|
|
23
|
+
],
|
|
20
24
|
selectableBenefits: [
|
|
21
25
|
{ benefitRef: 'member-discount', title: '会员 95 折', autoSelected: true },
|
|
22
|
-
|
|
26
|
+
// 已计入上方 appliedBenefits → 勾选态与已应用态一致
|
|
27
|
+
{ benefitRef: 'points-offset', title: '积分抵 5 元', autoSelected: true },
|
|
23
28
|
],
|
|
24
29
|
revision: 1,
|
|
25
30
|
caveats: ['费用以出场实际计费为准'],
|
|
@@ -18,13 +18,15 @@ const BASIC = '缴费卡·基础形态(金额 / 费项 / 时长 / 终态)';
|
|
|
18
18
|
const MATRIX = '缴费卡·优惠矩阵(会员态 × 券 × 积分 × 互斥)';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* 共用基底:同一张「停留 2 小时 42 分 / 计费 3 小时 / 15.00 元」的报价单。
|
|
22
|
+
* 只让被考察的维度变——金额各不相同的话,一眼扫过去分不清是维度差异还是数字差异。
|
|
23
|
+
* 162 分钟同时满足运行时 durationText 的 round(2.7→3)与计费 ceil(→3),
|
|
24
|
+
* 保证样本与 provider-mock 的演示叙事同源;改动前先核对这两条口径。
|
|
23
25
|
*/
|
|
24
26
|
const BASE = {
|
|
25
27
|
plateNo: '浙A12345',
|
|
26
|
-
entryAtText: '08-14 07:
|
|
27
|
-
durationText: '
|
|
28
|
+
entryAtText: '08-14 07:35',
|
|
29
|
+
durationText: '2 小时 42 分',
|
|
28
30
|
feeItems: [{ name: '停车费(3 小时)', amountText: '15.00 元' }],
|
|
29
31
|
totalText: '15.00 元',
|
|
30
32
|
revision: 1,
|
|
@@ -38,10 +40,10 @@ type Membership = NonNullable<ParkingPaymentCardData['membership']>;
|
|
|
38
40
|
/** 已入会且积分充足——矩阵里大部分格子的会员轴取值。 */
|
|
39
41
|
const MEMBER_ACTIVE: Membership = { state: 'active', availablePoints: 860 };
|
|
40
42
|
|
|
41
|
-
/** 券:可与积分叠加(默认规则)。 */
|
|
43
|
+
/** 券:可与积分叠加(默认规则)。2 小时 × 5.00 元/小时 = 10.00 元(与演示费率卡同源)。 */
|
|
42
44
|
const COUPON_STACKABLE: SelectableBenefit = {
|
|
43
45
|
benefitRef: 'c1', title: '2 小时免费券', kind: 'coupon', autoSelected: true,
|
|
44
|
-
description: '限首次停车', discountText: '
|
|
46
|
+
description: '限首次停车', discountText: '10.00 元',
|
|
45
47
|
};
|
|
46
48
|
/** 券:厂商标记不可与积分叠加——规则写在券上,判定却是双向的。 */
|
|
47
49
|
const COUPON_EXCLUSIVE: SelectableBenefit = {
|
|
@@ -53,6 +55,9 @@ const POINTS_BENEFIT: SelectableBenefit = {
|
|
|
53
55
|
benefitRef: 'p1', title: '积分抵 5 元', kind: 'points', autoSelected: false,
|
|
54
56
|
description: '消耗 500 积分', discountText: '5.00 元',
|
|
55
57
|
};
|
|
58
|
+
/** 已应用的会员 95 折 / 积分抵扣——仅用于 discountText 已包含它们的终态样本。 */
|
|
59
|
+
const MEMBER_APPLIED: AppliedBenefit = { benefitRef: 'member-discount', title: '会员 95 折', discountText: '0.75 元' };
|
|
60
|
+
const POINTS_APPLIED: AppliedBenefit = { benefitRef: 'p1', title: '积分抵 5 元', discountText: '5.00 元' };
|
|
56
61
|
/**
|
|
57
62
|
* 等级权益的两种形态,判据是 autoSelected 而非 kind:
|
|
58
63
|
* - discount + autoSelected:够等级就自动生效,用户没有决策权 → 剔出勾选区,只在费用明细现身
|
|
@@ -84,7 +89,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
84
89
|
data: {
|
|
85
90
|
quoteRef: 'b_free', plateNo: '浙A12345', revision: 1,
|
|
86
91
|
entryAtText: '08-12 09:00', durationText: '28 分',
|
|
87
|
-
feeItems: [{ name: '停车费(
|
|
92
|
+
feeItems: [{ name: '停车费(1 小时)', amountText: '0.00 元' }],
|
|
88
93
|
totalText: '0.00 元', payableText: '0.00 元',
|
|
89
94
|
appliedBenefits: [], selectableBenefits: [POINTS_BENEFIT],
|
|
90
95
|
caveats: ['免费时段内出场不收费', '费用以出场实际计费为准'],
|
|
@@ -92,14 +97,14 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
92
97
|
},
|
|
93
98
|
{
|
|
94
99
|
label: '多费项·跨日长时长',
|
|
95
|
-
note: '三行费项 + 四位金额 + 26
|
|
100
|
+
note: '三行费项 + 四位金额 + 26 小时 12 分停留(计费 27 小时)——检查右对齐、换行与 hero meta 宽度',
|
|
96
101
|
group: BASIC,
|
|
97
102
|
data: {
|
|
98
103
|
...BASE, quoteRef: 'b_long', plateNo: '浙AD12345',
|
|
99
104
|
entryAtText: '08-13 20:30', durationText: '26 小时 12 分',
|
|
100
105
|
membership: MEMBER_ACTIVE,
|
|
101
106
|
feeItems: [
|
|
102
|
-
{ name: '停车费(
|
|
107
|
+
{ name: '停车费(27 小时)', amountText: '120.00 元' },
|
|
103
108
|
{ name: '超时占用附加费', amountText: '30.00 元' },
|
|
104
109
|
{ name: '夜间服务费', amountText: '12.50 元' },
|
|
105
110
|
],
|
|
@@ -141,7 +146,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
141
146
|
data: {
|
|
142
147
|
...BASE, quoteRef: 'b_paying', membership: MEMBER_ACTIVE,
|
|
143
148
|
discountText: '5.75 元', payableText: '9.25 元',
|
|
144
|
-
appliedBenefits: [], selectableBenefits: [], revision: 2,
|
|
149
|
+
appliedBenefits: [MEMBER_APPLIED, POINTS_APPLIED], selectableBenefits: [], revision: 2,
|
|
145
150
|
settlement: { state: 'paying', text: '支付处理中,结果以回执为准' },
|
|
146
151
|
},
|
|
147
152
|
},
|
|
@@ -152,7 +157,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
152
157
|
data: {
|
|
153
158
|
...BASE, quoteRef: 'b_paid', membership: MEMBER_ACTIVE,
|
|
154
159
|
discountText: '5.75 元', payableText: '9.25 元',
|
|
155
|
-
appliedBenefits: [], selectableBenefits: [], revision: 2,
|
|
160
|
+
appliedBenefits: [MEMBER_APPLIED, POINTS_APPLIED], selectableBenefits: [], revision: 2,
|
|
156
161
|
settlement: { state: 'paid', text: '已完成支付,请在 15 分钟内离场' },
|
|
157
162
|
},
|
|
158
163
|
},
|
|
@@ -185,13 +190,13 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
185
190
|
},
|
|
186
191
|
{
|
|
187
192
|
label: '已入会·只有券',
|
|
188
|
-
note: '券已 autoSelected 生效 → 按钮报
|
|
193
|
+
note: '券已 autoSelected 生效 → 按钮报 5.00 元(与「当前应付」同源)',
|
|
189
194
|
group: MATRIX,
|
|
190
195
|
hidden: true,
|
|
191
196
|
data: {
|
|
192
197
|
...BASE, quoteRef: 'm_coupon', membership: MEMBER_ACTIVE,
|
|
193
|
-
discountText: '
|
|
194
|
-
appliedBenefits: [{ benefitRef: 'c1', title: '2 小时免费券', discountText: '
|
|
198
|
+
discountText: '10.00 元', payableText: '5.00 元',
|
|
199
|
+
appliedBenefits: [{ benefitRef: 'c1', title: '2 小时免费券', discountText: '10.00 元' }],
|
|
195
200
|
selectableBenefits: [COUPON_STACKABLE],
|
|
196
201
|
},
|
|
197
202
|
},
|
|
@@ -227,8 +232,8 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
227
232
|
hidden: true,
|
|
228
233
|
data: {
|
|
229
234
|
...BASE, quoteRef: 'm_stack', membership: MEMBER_ACTIVE,
|
|
230
|
-
discountText: '
|
|
231
|
-
appliedBenefits: [{ benefitRef: 'c1', title: '2 小时免费券', discountText: '
|
|
235
|
+
discountText: '10.00 元', payableText: '5.00 元',
|
|
236
|
+
appliedBenefits: [{ benefitRef: 'c1', title: '2 小时免费券', discountText: '10.00 元' }],
|
|
232
237
|
selectableBenefits: [COUPON_STACKABLE, POINTS_BENEFIT],
|
|
233
238
|
},
|
|
234
239
|
},
|
|
@@ -249,10 +254,10 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
249
254
|
group: MATRIX,
|
|
250
255
|
data: {
|
|
251
256
|
...BASE, quoteRef: 'm_mixed', membership: MEMBER_ACTIVE,
|
|
252
|
-
discountText: '
|
|
257
|
+
discountText: '10.75 元', payableText: '4.25 元',
|
|
253
258
|
appliedBenefits: [
|
|
254
259
|
LEVEL_APPLIED,
|
|
255
|
-
{ benefitRef: 'c1', title: '2 小时免费券', discountText: '
|
|
260
|
+
{ benefitRef: 'c1', title: '2 小时免费券', discountText: '10.00 元' },
|
|
256
261
|
],
|
|
257
262
|
selectableBenefits: [LEVEL_SELECTABLE, COUPON_STACKABLE, COUPON_EXCLUSIVE, POINTS_BENEFIT],
|
|
258
263
|
},
|
|
@@ -290,8 +295,8 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
290
295
|
data: {
|
|
291
296
|
...BASE, quoteRef: 'm_ne_coupon',
|
|
292
297
|
membership: { state: 'not_enrolled' },
|
|
293
|
-
discountText: '
|
|
294
|
-
appliedBenefits: [{ benefitRef: 'c1', title: '2 小时免费券', discountText: '
|
|
298
|
+
discountText: '10.00 元', payableText: '5.00 元',
|
|
299
|
+
appliedBenefits: [{ benefitRef: 'c1', title: '2 小时免费券', discountText: '10.00 元' }],
|
|
295
300
|
selectableBenefits: [COUPON_STACKABLE],
|
|
296
301
|
},
|
|
297
302
|
},
|
|
@@ -312,7 +317,7 @@ export const samples: CardSample<ParkingPaymentCardData>[] = [
|
|
|
312
317
|
group: MATRIX,
|
|
313
318
|
hidden: true,
|
|
314
319
|
data: {
|
|
315
|
-
...BASE, quoteRef: 'm_anon', durationText: '
|
|
320
|
+
...BASE, quoteRef: 'm_anon', durationText: '2 小时 42 分', entryAtText: undefined,
|
|
316
321
|
membership: { state: 'unauthenticated' },
|
|
317
322
|
payableText: '15.00 元', appliedBenefits: [], selectableBenefits: [],
|
|
318
323
|
},
|
|
@@ -63,7 +63,7 @@ export const samples: CardSample<ParkingPaymentRecordsCardData>[] = [
|
|
|
63
63
|
items: [{
|
|
64
64
|
recordRef: 'r_1', plateNo: '浙A12345', amountText: '9.25 元', paidAtText: '08-14 10:20',
|
|
65
65
|
status: 'PAID', parkName: '示例广场地下停车场',
|
|
66
|
-
entryAtText: '08-14 07:
|
|
66
|
+
entryAtText: '08-14 07:35', exitAtText: '08-14 10:25', payOrderNoMasked: '2026****8891',
|
|
67
67
|
orderCompleted: true, invoiceEligible: true, invoiceIssued: false,
|
|
68
68
|
}],
|
|
69
69
|
total: 1, hasMore: false, caveats: ['仅展示近 6 个月缴费记录'],
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* parking-payment-result 附加预览样本(沉淀自 mall dev-gallery 停车场景画廊)。
|
|
3
3
|
* 方法论:见同目录 ../parking-payment/samples.ts 头注释。
|
|
4
|
-
* 叙事基线:与 ../parking-payment/samples.ts BASE 同一停车叙事——入场 08-14 07:
|
|
5
|
-
* 报价时已停
|
|
6
|
-
* 停车时长 = 缴费时间 − 入场时间(07:
|
|
4
|
+
* 叙事基线:与 ../parking-payment/samples.ts BASE 同一停车叙事——入场 08-14 07:35,
|
|
5
|
+
* 报价时已停 2 小时 42 分(10:17,计费 3 小时);三态回执 = 这张报价单的三种结局,
|
|
6
|
+
* 停车时长 = 缴费时间 − 入场时间(07:35)逐分吻合,金额对齐缴费卡应付(tests 守卫)。
|
|
7
7
|
*/
|
|
8
8
|
import type { CardSample } from '@tbox.cn/app-contracts';
|
|
9
9
|
import type { ParkingPaymentResultCardData } from '@tbox.cn/app-contracts-mall';
|
|
@@ -21,7 +21,7 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
|
|
|
21
21
|
leaveNotice: '请在 15 分钟内离场,超时将重新计费',
|
|
22
22
|
details: [
|
|
23
23
|
{ label: '车牌', value: '浙A12345' },
|
|
24
|
-
{ label: '停车时长', value: '
|
|
24
|
+
{ label: '停车时长', value: '2 小时 45 分' },
|
|
25
25
|
{ label: '缴费时间', value: '今天 10:20' },
|
|
26
26
|
],
|
|
27
27
|
},
|
|
@@ -35,7 +35,7 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
|
|
|
35
35
|
amountText: '9.25 元', message: '支付已取消,可重新发起缴费',
|
|
36
36
|
details: [
|
|
37
37
|
{ label: '车牌', value: '浙A12345' },
|
|
38
|
-
{ label: '停车时长', value: '
|
|
38
|
+
{ label: '停车时长', value: '2 小时 47 分' },
|
|
39
39
|
{ label: '缴费时间', value: '今天 10:22' },
|
|
40
40
|
],
|
|
41
41
|
},
|
|
@@ -50,7 +50,7 @@ export const samples: CardSample<ParkingPaymentResultCardData>[] = [
|
|
|
50
50
|
amountText: '15.00 元', message: '厂商对账中,请稍后再查询', retryable: true,
|
|
51
51
|
details: [
|
|
52
52
|
{ label: '车牌', value: '浙A12345' },
|
|
53
|
-
{ label: '停车时长', value: '
|
|
53
|
+
{ label: '停车时长', value: '2 小时 56 分' },
|
|
54
54
|
{ label: '缴费时间', value: '今天 10:31' },
|
|
55
55
|
],
|
|
56
56
|
},
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* - withCardEmissionHint wrap:8 出卡工具 description 含预告知句,locateVehicle 不含;
|
|
5
5
|
* - note 契约:报价/支付状态 note 含主体+关键事实(车牌/金额/状态/时长)。
|
|
6
6
|
*/
|
|
7
|
-
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
8
8
|
import {
|
|
9
9
|
createParkingTools,
|
|
10
10
|
decideParkingFeePreRun,
|
|
@@ -82,6 +82,16 @@ describe('note 契约(W7):主体+关键事实', () => {
|
|
|
82
82
|
it('durationText:entryAt 缺省 → undefined', () => {
|
|
83
83
|
expect(durationText(undefined)).toBeUndefined();
|
|
84
84
|
});
|
|
85
|
+
|
|
86
|
+
it('durationText:162 分钟前入场 → 3 小时(与「停车费(3 小时)」同值)', () => {
|
|
87
|
+
vi.useFakeTimers();
|
|
88
|
+
try {
|
|
89
|
+
vi.setSystemTime(new Date('2026-10-27T10:17:00+08:00'));
|
|
90
|
+
expect(durationText(new Date(Date.now() - 162 * 60_000).toISOString())).toBe('3 小时');
|
|
91
|
+
} finally {
|
|
92
|
+
vi.useRealTimers();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
85
95
|
});
|
|
86
96
|
|
|
87
97
|
describe('decideListVehiclesPreRun:车辆问句门控', () => {
|
package/tests/samples.test.ts
CHANGED
|
@@ -74,8 +74,8 @@ describe('parking samples 双断言(样本即契约)', () => {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
describe('样本叙事自洽(回执 × 缴费卡 × 缴费记录同一停车叙事)', () => {
|
|
77
|
-
/** 基线入场时刻 08-14 07:
|
|
78
|
-
const ENTRY_MIN = 7 * 60 +
|
|
77
|
+
/** 基线入场时刻 08-14 07:35(真源 ../src/server/cards/parking-payment/samples.ts BASE)。 */
|
|
78
|
+
const ENTRY_MIN = 7 * 60 + 35;
|
|
79
79
|
/** 「X 小时 Y 分」→ 分钟。 */
|
|
80
80
|
const durationMinutes = (text: string) => {
|
|
81
81
|
const [h = '0', m = '0'] = text.match(/\d+/g) ?? [];
|
|
@@ -87,7 +87,7 @@ describe('样本叙事自洽(回执 × 缴费卡 × 缴费记录同一停车
|
|
|
87
87
|
return Number(hh) * 60 + Number(mm);
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
it('回执三态:时长 = 缴费时间 − 入场(07:
|
|
90
|
+
it('回执三态:时长 = 缴费时间 − 入场(07:35)逐分吻合,金额对齐缴费卡应付', () => {
|
|
91
91
|
const cases = [
|
|
92
92
|
{ label: '缴费成功', amountText: '9.25 元', paidAtText: '今天 10:20' },
|
|
93
93
|
{ label: '支付取消', amountText: '9.25 元', paidAtText: '今天 10:22' },
|
|
@@ -98,8 +98,8 @@ describe('样本叙事自洽(回执 × 缴费卡 × 缴费记录同一停车
|
|
|
98
98
|
expect(sample?.label, expected.label).toBe(expected.label);
|
|
99
99
|
expect(sample?.data.amountText, `${expected.label} 金额对齐缴费卡应付`).toBe(expected.amountText);
|
|
100
100
|
const duration = sample?.data.details?.find((d) => d.label === '停车时长')?.value ?? '';
|
|
101
|
-
expect(duration, `${expected.label} 时长须落在 3
|
|
102
|
-
/^
|
|
101
|
+
expect(duration, `${expected.label} 时长须落在 2 小时档(计费 3 小时,与停车费(3 小时)同叙事)`).toMatch(
|
|
102
|
+
/^2 小时 \d{2} 分$/,
|
|
103
103
|
);
|
|
104
104
|
expect(durationMinutes(duration), `${expected.label} 时长 = 缴费时间 − 入场`).toBe(
|
|
105
105
|
clockMinutes(expected.paidAtText) - ENTRY_MIN,
|
|
@@ -122,6 +122,73 @@ describe('样本叙事自洽(回执 × 缴费卡 × 缴费记录同一停车
|
|
|
122
122
|
});
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
+
describe('缴费卡计费口径自洽(费项小时数 = ceil(时长))', () => {
|
|
126
|
+
/** 「15.00 元」→ 1500 分。 */
|
|
127
|
+
const cents = (text?: string): number | undefined => {
|
|
128
|
+
if (!text) return undefined;
|
|
129
|
+
const value = Number(text.replace(/[^\d.]/g, ''));
|
|
130
|
+
return Number.isFinite(value) ? Math.round(value * 100) : undefined;
|
|
131
|
+
};
|
|
132
|
+
/** 「X 小时 Y 分」/「Y 分」→ 分钟。 */
|
|
133
|
+
const minutesOf = (text?: string): number => {
|
|
134
|
+
const hours = Number(text?.match(/(\d+)\s*小时/)?.[1] ?? 0);
|
|
135
|
+
const minutes = Number(text?.match(/(\d+)\s*分/)?.[1] ?? 0);
|
|
136
|
+
return hours * 60 + minutes;
|
|
137
|
+
};
|
|
138
|
+
/** 费项名「停车费(N 小时)」→ N;无小时数(附加费/服务费)→ undefined。 */
|
|
139
|
+
const billedHoursOf = (name: string): number | undefined => {
|
|
140
|
+
const match = name.match(/((\d+)\s*小时)/);
|
|
141
|
+
return match ? Number(match[1]) : undefined;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const paymentCards = [
|
|
145
|
+
paymentMeta.sampleData,
|
|
146
|
+
...(paymentMeta.samples ?? []).map((sample) => sample.data),
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
it('费项小时数 = max(1, ceil(已停分钟 / 60))(含初始态与全部附加样本)', () => {
|
|
150
|
+
for (const data of paymentCards) {
|
|
151
|
+
expect(data.durationText, `${data.quoteRef} 缺 durationText`).toBeTruthy();
|
|
152
|
+
const expectedHours = Math.max(1, Math.ceil(minutesOf(data.durationText) / 60));
|
|
153
|
+
for (const fee of data.feeItems) {
|
|
154
|
+
const billed = billedHoursOf(fee.name);
|
|
155
|
+
if (billed === undefined) continue;
|
|
156
|
+
expect(billed, `${data.quoteRef}/${fee.name} 计费小时数`).toBe(expectedHours);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('金额自洽:total = Σ费项;payable = total − discount;discount = ΣappliedBenefits', () => {
|
|
162
|
+
for (const data of paymentCards) {
|
|
163
|
+
const feeSum = data.feeItems.reduce((sum, fee) => sum + (cents(fee.amountText) ?? NaN), 0);
|
|
164
|
+
expect(feeSum, `${data.quoteRef} 费项合计`).toBe(cents(data.totalText));
|
|
165
|
+
expect(
|
|
166
|
+
(cents(data.totalText) ?? 0) - (cents(data.discountText) ?? 0),
|
|
167
|
+
`${data.quoteRef} 应付 = 总额 − 减免`,
|
|
168
|
+
).toBe(cents(data.payableText));
|
|
169
|
+
const appliedSum = data.appliedBenefits.reduce(
|
|
170
|
+
(sum, benefit) => sum + (cents(benefit.discountText) ?? 0),
|
|
171
|
+
0,
|
|
172
|
+
);
|
|
173
|
+
expect(appliedSum, `${data.quoteRef} 减免明细合计`).toBe(cents(data.discountText) ?? 0);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('券面小时数与演示费率匹配(N 小时免费券 = N × 5.00 元)', () => {
|
|
178
|
+
const HOUR_RATE_CENTS = 500; // 演示费率 5.00 元/小时(与 provider-mock / InMemory 费率卡同源)
|
|
179
|
+
for (const data of paymentCards) {
|
|
180
|
+
for (const benefit of [...data.selectableBenefits, ...data.appliedBenefits]) {
|
|
181
|
+
const match = benefit.title.match(/^(\d+) 小时免费券$/);
|
|
182
|
+
if (!match) continue;
|
|
183
|
+
expect(
|
|
184
|
+
cents(benefit.discountText),
|
|
185
|
+
`${data.quoteRef}/${benefit.title} 券面额`,
|
|
186
|
+
).toBe(Number(match[1]) * HOUR_RATE_CENTS);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
125
192
|
describe('卡级 hidden 标记守卫(预览策展)', () => {
|
|
126
193
|
it('支付结果卡降噪型(2026-10-19 裁决——出卡链路照常,恢复 = 删标记)', () => {
|
|
127
194
|
expect(resultMeta.hidden).toBe(true);
|
package/tests/tools-gate.test.ts
CHANGED
|
@@ -172,6 +172,51 @@ describe('门禁边界(require 守卫之外的形态)', () => {
|
|
|
172
172
|
});
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
+
describe('停车费卡:运行时投影与费项同源(162 分钟 → 3 小时)', () => {
|
|
176
|
+
it('queryParkingFee:entryAt 162 分钟前 + 费项(3 小时)/1500 → durationText 3 小时', async () => {
|
|
177
|
+
vi.useFakeTimers();
|
|
178
|
+
try {
|
|
179
|
+
vi.setSystemTime(new Date('2026-10-27T10:17:00+08:00'));
|
|
180
|
+
const quote = {
|
|
181
|
+
quoteRef: 'demo:quote:浙A12345',
|
|
182
|
+
plateNo: '浙A12345',
|
|
183
|
+
mallId: 'mall-1',
|
|
184
|
+
entryAt: new Date(Date.now() - 162 * 60_000).toISOString(),
|
|
185
|
+
feeItems: [{ name: '停车费(3 小时)', amountCents: 1500 }],
|
|
186
|
+
totalCents: 1500,
|
|
187
|
+
discountCents: 0,
|
|
188
|
+
payableCents: 1500,
|
|
189
|
+
appliedBenefits: [],
|
|
190
|
+
revision: 1,
|
|
191
|
+
paymentState: 'UNPAID' as const,
|
|
192
|
+
};
|
|
193
|
+
const service = {
|
|
194
|
+
queryFee: async () => [quote],
|
|
195
|
+
listVehicles: async () => ({ bound: [] }),
|
|
196
|
+
};
|
|
197
|
+
const tools = createParkingTools({ getCtx: () => ctxWithStatus(guestStatus) as never });
|
|
198
|
+
mockAllSlots(service);
|
|
199
|
+
const result = (await tools.queryParkingFee.execute!(
|
|
200
|
+
{} as never,
|
|
201
|
+
execCtx(),
|
|
202
|
+
)) as {
|
|
203
|
+
cards?: {
|
|
204
|
+
cardType: string;
|
|
205
|
+
note: string;
|
|
206
|
+
data: { durationText?: string; feeItems: { name: string; amountText: string }[] };
|
|
207
|
+
}[];
|
|
208
|
+
};
|
|
209
|
+
const card = result.cards?.[0];
|
|
210
|
+
expect(card?.cardType).toBe('parking-payment');
|
|
211
|
+
expect(card?.data.durationText).toBe('3 小时');
|
|
212
|
+
expect(card?.data.feeItems).toEqual([{ name: '停车费(3 小时)', amountText: '15.00 元' }]);
|
|
213
|
+
expect(card?.note).toContain('已停 3 小时');
|
|
214
|
+
} finally {
|
|
215
|
+
vi.useRealTimers();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
175
220
|
describe('非绑定车牌拒查(安全防护)', () => {
|
|
176
221
|
function serviceWithBound(...plates: string[]) {
|
|
177
222
|
const service = new InMemoryParkingService();
|