@tbox.cn/app-contracts-mall 1.0.0-alpha.1 → 1.0.0-alpha.7
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 +1 -1
- package/dist/activity-play/cards.d.ts +92 -0
- package/dist/activity-play-prize/cards.d.ts +314 -0
- package/dist/domain/activity-play-prize.d.ts +208 -0
- package/dist/domain/activity-play.d.ts +78 -0
- package/dist/index.d.ts +6 -0
- package/dist/member/cards.d.ts +28 -28
- package/dist/parking/cards.d.ts +20 -20
- package/dist/promotion/cards.d.ts +32 -32
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +773 -634
- package/dist/services/activity-play-prize.d.ts +36 -0
- package/dist/services/activity-play.d.ts +39 -0
- package/dist/services/member.d.ts +1 -1
- package/dist/services/parking.d.ts +1 -1
- package/dist/services/promotion.d.ts +1 -1
- package/dist/shopping-guide/cards.d.ts +36 -36
- package/package.json +3 -3
- package/src/activity-play/cards.ts +33 -0
- package/src/activity-play-prize/cards.ts +69 -0
- package/src/domain/activity-play-prize.ts +105 -0
- package/src/domain/activity-play.ts +83 -0
- package/src/index.ts +6 -0
- package/src/runtime.ts +28 -0
- package/src/service-slots.json +83 -19
- package/src/services/activity-play-prize.ts +47 -0
- package/src/services/activity-play.ts +45 -0
- package/src/services/member.ts +1 -1
- package/src/services/parking.ts +1 -1
- package/src/services/promotion.ts +1 -1
- package/tests/activity-play-prize.test.ts +175 -0
- package/tests/activity-play.test.ts +123 -0
- package/tests/service-slots.test.ts +11 -7
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 个人奖品域契约测试(任务07):
|
|
3
|
+
* - DTO 面:必填/可选/strict 拒未知键;记录标识原样通过('001'/'1.20'/'1e3' 不数字化);
|
|
4
|
+
* total 非负整数;图片 HTTPS / 含时区时间纪律与活动域单源一致;
|
|
5
|
+
* - UNKNOWN 兜底:toActivityPlayPrizeStatusTag 命中 known 原样、未知/缺失/非字符串归 UNKNOWN;
|
|
6
|
+
* - 卡片面:列表条目 itemActions(actionDraft 单源)、noResultsReason、详情平铺不套
|
|
7
|
+
* mode/items/prize 包装。
|
|
8
|
+
*/
|
|
9
|
+
import { describe, expect, it } from 'vitest';
|
|
10
|
+
import {
|
|
11
|
+
ACTIVITY_PLAY_PRIZE_STATUS_UNKNOWN,
|
|
12
|
+
activityPlayPrizeDetailSchema,
|
|
13
|
+
activityPlayPrizeListResultSchema,
|
|
14
|
+
activityPlayPrizeRecordSchema,
|
|
15
|
+
toActivityPlayPrizeStatusTag,
|
|
16
|
+
} from '../src/domain/activity-play-prize';
|
|
17
|
+
import {
|
|
18
|
+
ACTIVITY_PLAY_PRIZE_DETAIL_CARD_TYPE,
|
|
19
|
+
ACTIVITY_PLAY_PRIZE_LIST_CARD_TYPE,
|
|
20
|
+
activityPlayPrizeCardItemSchema,
|
|
21
|
+
activityPlayPrizeDetailCardDataSchema,
|
|
22
|
+
activityPlayPrizeListCardDataSchema,
|
|
23
|
+
} from '../src/activity-play-prize/cards';
|
|
24
|
+
import { ACTIVITY_PLAY_PRIZES_SERVICE } from '../src/services/activity-play-prize';
|
|
25
|
+
|
|
26
|
+
const baseRecord = {
|
|
27
|
+
prizeRecordRef: 'prize-demo-001',
|
|
28
|
+
title: '咖啡兑换券',
|
|
29
|
+
prizeType: 'COUPON',
|
|
30
|
+
claimStatus: 'CLAIMED',
|
|
31
|
+
useStatus: 'UNUSED',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const fullRecord = {
|
|
35
|
+
...baseRecord,
|
|
36
|
+
activityId: 'demo-wheel',
|
|
37
|
+
activityTitle: '幸运转盘',
|
|
38
|
+
imageUrl: 'https://example.com/prize.png',
|
|
39
|
+
wonAt: '2026-11-01T10:00:00+08:00',
|
|
40
|
+
usageRuleText: '请在有效期内到店使用',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe('奖品记录 schema(domain 单源)', () => {
|
|
44
|
+
it('基础面通过;全量可选字段在场也通过', () => {
|
|
45
|
+
expect(activityPlayPrizeRecordSchema.safeParse(baseRecord).success).toBe(true);
|
|
46
|
+
expect(activityPlayPrizeRecordSchema.safeParse(fullRecord).success).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('必填字段缺席或非法显性拒绝(不丢坏记录归未中奖——由上层显性失败承载)', () => {
|
|
50
|
+
for (const bad of [
|
|
51
|
+
{ ...baseRecord, title: '' },
|
|
52
|
+
{ ...baseRecord, prizeRecordRef: ' ' },
|
|
53
|
+
{ ...baseRecord, prizeType: '' },
|
|
54
|
+
{ ...baseRecord, claimStatus: '' },
|
|
55
|
+
{ ...baseRecord, useStatus: '' },
|
|
56
|
+
]) {
|
|
57
|
+
expect(activityPlayPrizeRecordSchema.safeParse(bad).success).toBe(false);
|
|
58
|
+
}
|
|
59
|
+
const { prizeRecordRef: _dropped, ...missing } = baseRecord;
|
|
60
|
+
expect(activityPlayPrizeRecordSchema.safeParse(missing).success).toBe(false);
|
|
61
|
+
const { title: _t, ...noTitle } = baseRecord;
|
|
62
|
+
expect(activityPlayPrizeRecordSchema.safeParse(noTitle).success).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('strict 拒未知键(厂商原始字段须先经适配层归一,不透传)', () => {
|
|
66
|
+
expect(activityPlayPrizeRecordSchema.safeParse({ ...baseRecord, rawJson: '{}' }).success).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('记录标识按原字符串定位:001 / 1.20 / 1e3 / 带首尾空白原样通过(不数字/JSON/trim 改写)', () => {
|
|
70
|
+
for (const ref of ['001', '1.20', '1e3', '23847104', 'a_b.c:d-e', ' record-001 ']) {
|
|
71
|
+
const parsed = activityPlayPrizeRecordSchema.safeParse({ ...baseRecord, prizeRecordRef: ref });
|
|
72
|
+
expect(parsed.success).toBe(true);
|
|
73
|
+
if (parsed.success) expect(parsed.data.prizeRecordRef).toBe(ref);
|
|
74
|
+
}
|
|
75
|
+
expect(activityPlayPrizeRecordSchema.safeParse({ ...baseRecord, prizeRecordRef: 'x'.repeat(129) }).success).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('图片恒 HTTPS;无效 URL/时间日历真值拒收(与活动域单源同纪律)', () => {
|
|
79
|
+
expect(activityPlayPrizeRecordSchema.safeParse({ ...fullRecord, imageUrl: 'http://example.com/p.png' }).success).toBe(false);
|
|
80
|
+
expect(activityPlayPrizeRecordSchema.safeParse({ ...fullRecord, imageUrl: 'https://' }).success).toBe(false);
|
|
81
|
+
expect(activityPlayPrizeRecordSchema.safeParse({ ...fullRecord, wonAt: '2026-11-01T10:00:00' }).success).toBe(false);
|
|
82
|
+
expect(activityPlayPrizeRecordSchema.safeParse({ ...fullRecord, wonAt: '2027-02-30T10:00:00+08:00' }).success).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('prizeUrl 恒为有效 HTTPS URL(详情面)', () => {
|
|
86
|
+
const base = { ...fullRecord, prizeRecordRef: 'prize-demo-002' };
|
|
87
|
+
expect(activityPlayPrizeDetailSchema.safeParse({ ...base, prizeUrl: 'https://example.com/claim' }).success).toBe(true);
|
|
88
|
+
expect(activityPlayPrizeDetailSchema.safeParse({ ...base, prizeUrl: 'http://example.com/claim' }).success).toBe(false);
|
|
89
|
+
expect(activityPlayPrizeDetailSchema.safeParse({ ...base, prizeUrl: 'not-a-url' }).success).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('列表结果:total 非负整数;items 缺一不可', () => {
|
|
93
|
+
expect(activityPlayPrizeListResultSchema.safeParse({ total: 0, items: [] }).success).toBe(true);
|
|
94
|
+
expect(activityPlayPrizeListResultSchema.safeParse({ total: 2, items: [baseRecord, { ...baseRecord, prizeRecordRef: 'prize-demo-002' }] }).success).toBe(true);
|
|
95
|
+
expect(activityPlayPrizeListResultSchema.safeParse({ total: -1, items: [] }).success).toBe(false);
|
|
96
|
+
expect(activityPlayPrizeListResultSchema.safeParse({ total: 1.5, items: [] }).success).toBe(false);
|
|
97
|
+
expect(activityPlayPrizeListResultSchema.safeParse({ items: [] }).success).toBe(false);
|
|
98
|
+
expect(activityPlayPrizeListResultSchema.safeParse({ total: 0, items: [{ ...baseRecord, extra: 1 }] }).success).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('UNKNOWN 状态兜底(契约单源)', () => {
|
|
103
|
+
it('命中 known 集 → 原样;未知/缺失/非字符串 → UNKNOWN', () => {
|
|
104
|
+
const known = ['CLAIMED', 'WAIT_CLAIM'];
|
|
105
|
+
expect(toActivityPlayPrizeStatusTag('CLAIMED', known)).toBe('CLAIMED');
|
|
106
|
+
expect(toActivityPlayPrizeStatusTag('unknown-campaign-state', known)).toBe(ACTIVITY_PLAY_PRIZE_STATUS_UNKNOWN);
|
|
107
|
+
expect(toActivityPlayPrizeStatusTag(undefined, known)).toBe(ACTIVITY_PLAY_PRIZE_STATUS_UNKNOWN);
|
|
108
|
+
expect(toActivityPlayPrizeStatusTag(null, known)).toBe(ACTIVITY_PLAY_PRIZE_STATUS_UNKNOWN);
|
|
109
|
+
expect(toActivityPlayPrizeStatusTag(7, known)).toBe(ACTIVITY_PLAY_PRIZE_STATUS_UNKNOWN);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('奖品卡片数据 schema(两张稳定卡型)', () => {
|
|
114
|
+
const listItem = {
|
|
115
|
+
...fullRecord,
|
|
116
|
+
itemActions: [
|
|
117
|
+
{
|
|
118
|
+
kind: 'send',
|
|
119
|
+
label: '查看详情',
|
|
120
|
+
value: '查看中奖记录 prize-demo-001 的奖品详情',
|
|
121
|
+
visibleValue: '查看咖啡兑换券详情',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
it('列表卡:truncated 展示截断标记合法(布尔形态;items 仍受 ≤50 上限约束)', () => {
|
|
127
|
+
const data = { mallId: 'mall-demo', total: 51, items: [listItem], truncated: true };
|
|
128
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse(data).success).toBe(true);
|
|
129
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse({ ...data, truncated: 'yes' }).success).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('列表卡:条目 itemActions 沿 actionDraft 单源;total/noResultsReason 形状', () => {
|
|
133
|
+
const data = { mallId: 'mall-demo', total: 1, items: [listItem] };
|
|
134
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse(data).success).toBe(true);
|
|
135
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse({ ...data, noResultsReason: '暂无中奖记录' }).success).toBe(true);
|
|
136
|
+
|
|
137
|
+
// 空态:total 0 + 空 items(成功无记录);失败不出卡由出卡层承载
|
|
138
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse({ mallId: 'mall-demo', total: 0, items: [] }).success).toBe(true);
|
|
139
|
+
|
|
140
|
+
// itemActions 超限 / 未知动作 kind / 卡 data 未知键
|
|
141
|
+
const many = Array.from({ length: 5 }, () => listItem.itemActions![0]);
|
|
142
|
+
expect(activityPlayPrizeCardItemSchema.safeParse({ ...fullRecord, itemActions: many }).success).toBe(false);
|
|
143
|
+
expect(
|
|
144
|
+
activityPlayPrizeCardItemSchema.safeParse({ ...fullRecord, itemActions: [{ kind: 'navigate' } as never] }).success,
|
|
145
|
+
).toBe(false);
|
|
146
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse({ ...data, mode: 'list' }).success).toBe(false);
|
|
147
|
+
|
|
148
|
+
// mallId 与 total 必填
|
|
149
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse({ total: 1, items: [listItem] }).success).toBe(false);
|
|
150
|
+
expect(activityPlayPrizeListCardDataSchema.safeParse({ mallId: 'mall-demo', items: [listItem] }).success).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('详情卡:平铺 {mallId, ...detail}——不套 mode/items/prize 包装', () => {
|
|
154
|
+
const detail = {
|
|
155
|
+
...fullRecord,
|
|
156
|
+
redemptionMethod: '门店柜台',
|
|
157
|
+
redemptionInstruction: '请按活动页面的领取及使用指引操作',
|
|
158
|
+
prizeUrl: 'https://example.com/claim',
|
|
159
|
+
};
|
|
160
|
+
const data = { mallId: 'mall-demo', ...detail };
|
|
161
|
+
expect(activityPlayPrizeDetailCardDataSchema.safeParse(data).success).toBe(true);
|
|
162
|
+
|
|
163
|
+
// 套 mode / items / prize 包装对象均非法(api.md 钉死平铺)
|
|
164
|
+
expect(activityPlayPrizeDetailCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'detail', prize: detail }).success).toBe(false);
|
|
165
|
+
expect(activityPlayPrizeDetailCardDataSchema.safeParse({ mallId: 'mall-demo', items: [detail] }).success).toBe(false);
|
|
166
|
+
// 无 mallId 拒收
|
|
167
|
+
expect(activityPlayPrizeDetailCardDataSchema.safeParse(detail).success).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('卡型常量与槽词汇面稳定', () => {
|
|
171
|
+
expect(ACTIVITY_PLAY_PRIZE_LIST_CARD_TYPE).toBe('activity-play-prize-list');
|
|
172
|
+
expect(ACTIVITY_PLAY_PRIZE_DETAIL_CARD_TYPE).toBe('activity-play-prize-detail');
|
|
173
|
+
expect(ACTIVITY_PLAY_PRIZES_SERVICE).toBe('activity-play.prizes');
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 活动玩法远端查询契约行为测试(2026-11-17 改造):活动对象 schema 形状 +
|
|
3
|
+
* activityId 原字符串语义(R-06)+ 旧字段退场(R-03)+ 卡片契约 + 槽词汇。
|
|
4
|
+
* 风险≡验收点:标识不改写/未知状态合法且不推断、旧键 activityRef/loginRequired
|
|
5
|
+
* 显性拒绝、劣质供给 fail-visible、list≤50/detail 恰一。
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
import type { ActivityPlayActivity } from '../src/domain/activity-play';
|
|
9
|
+
import {
|
|
10
|
+
activityPlayActivitySchema,
|
|
11
|
+
activityPlayIdSchema,
|
|
12
|
+
} from '../src/domain/activity-play';
|
|
13
|
+
import { activityPlayCardDataSchema } from '../src/activity-play/cards';
|
|
14
|
+
import { ACTIVITY_PLAY_QUERY_SERVICE, type ActivityPlayQueryPort } from '../src/services/activity-play';
|
|
15
|
+
import slotsJson from '../src/service-slots.json';
|
|
16
|
+
|
|
17
|
+
const base = {
|
|
18
|
+
activityId: 'demo-wheel',
|
|
19
|
+
title: '幸运转盘',
|
|
20
|
+
status: 'active',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('activityPlayIdSchema(供应商标识——原字符串语义)', () => {
|
|
24
|
+
it('数字形态字符串原样通过:001 / 1.20 / 1e3 互不相同且均合法(R-06)', () => {
|
|
25
|
+
for (const id of ['001', '1.20', '1e3', '1', '0']) {
|
|
26
|
+
const r = activityPlayIdSchema.safeParse(id);
|
|
27
|
+
expect(r.success, id).toBe(true);
|
|
28
|
+
if (r.success) expect(r.data).toBe(id); // 不改写
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('空/超长/控制字符/路径段破坏符拒绝(路径定位防线)', () => {
|
|
33
|
+
const tooLong = 'x'.repeat(129);
|
|
34
|
+
for (const bad of ['', tooLong, 'a/b', 'a?b', 'a#b', 'a%b', '.', '..', './a', '../a', 'a\u0001b']) {
|
|
35
|
+
expect(activityPlayIdSchema.safeParse(bad).success, JSON.stringify(bad)).toBe(false);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('activityPlayActivitySchema 运行时校验', () => {
|
|
41
|
+
it('最小对象合法;可选字段缺省为 undefined(不合成默认值、不编造)', () => {
|
|
42
|
+
const parsed = activityPlayActivitySchema.safeParse(base);
|
|
43
|
+
expect(parsed.success).toBe(true);
|
|
44
|
+
if (parsed.success) {
|
|
45
|
+
expect(parsed.data.description).toBeUndefined();
|
|
46
|
+
expect(parsed.data.startsAt).toBeUndefined();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('unknown 状态合法(未知不拒绝——由消费方保守展示,不推断 active)', () => {
|
|
51
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, status: 'unknown' }).success).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('旧字段退场(R-03):activityRef/loginRequired/target 系字段显性拒绝(strict)', () => {
|
|
55
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, activityRef: 'demo:wheel' }).success).toBe(false);
|
|
56
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, loginRequired: false }).success).toBe(false);
|
|
57
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, target: { kind: 'miniapp-plugin' } }).success).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('非合法 URL / 非法 status / 空标题 / 空 ID 被拒(供给数据劣质可识别)', () => {
|
|
61
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, imageUrl: 'http://x/a.png' }).success).toBe(false);
|
|
62
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, imageUrl: 'https://?' }).success).toBe(false);
|
|
63
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, status: 'running' }).success).toBe(false);
|
|
64
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, status: 'paused' as string }).success).toBe(false);
|
|
65
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, title: '' }).success).toBe(false);
|
|
66
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, activityId: '' }).success).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('时间字段要求含时区偏移的 ISO 形态且为真实日历时刻(naive 与滚日值拒绝)', () => {
|
|
70
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, startsAt: '2026-06-01T10:00:00' }).success).toBe(false);
|
|
71
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, startsAt: '2026-06-01T10:00:00+08:00' }).success).toBe(true);
|
|
72
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, endsAt: '2026-06-02T02:00:00Z' }).success).toBe(true);
|
|
73
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, startsAt: '2027-02-30T00:00:00Z' }).success).toBe(false);
|
|
74
|
+
expect(activityPlayActivitySchema.safeParse({ ...base, startsAt: '2028-02-29T00:00:00Z' }).success).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('activity-play.query 槽词汇与 Port 形状', () => {
|
|
79
|
+
it('服务常量与词汇真源一致;entry 槽退场(R-03)', () => {
|
|
80
|
+
expect(ACTIVITY_PLAY_QUERY_SERVICE).toBe('activity-play.query');
|
|
81
|
+
expect(slotsJson.slots).toContain(ACTIVITY_PLAY_QUERY_SERVICE);
|
|
82
|
+
expect(slotsJson.slots).not.toContain('activity-play.entry');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('Port 类型面消费自检(getActivity 按原字符串收参——typelevel 守卫)', () => {
|
|
86
|
+
const port: ActivityPlayQueryPort = {
|
|
87
|
+
listActivities: async () => ({ items: [] }),
|
|
88
|
+
getActivity: async (_q, activityId): Promise<ActivityPlayActivity | null> => (activityId === '001' ? activityPlayActivitySchema.parse({ ...base, activityId: '001' }) : null),
|
|
89
|
+
};
|
|
90
|
+
expect(port.getActivity).toBeTypeOf('function');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('activityPlayCardDataSchema(出卡契约:list/detail 传输形态)', () => {
|
|
95
|
+
const item = { activityId: 'demo-wheel', title: '幸运转盘', status: 'active' } as const;
|
|
96
|
+
|
|
97
|
+
it('list:条目直接复用活动对象 schema;空 items 合法(前端空态/示例验证)', () => {
|
|
98
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'list', items: [item] }).success).toBe(true);
|
|
99
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'list', items: [] }).success).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('detail:恰好 1 项合法(可携 unknown/disabled);空/多项拒绝;非法 mode 拒绝', () => {
|
|
103
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'detail', items: [item] }).success).toBe(true);
|
|
104
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'detail', items: [{ ...item, status: 'unknown' }] }).success).toBe(true);
|
|
105
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'detail', items: [] }).success).toBe(false);
|
|
106
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'detail', items: [item, item] }).success).toBe(false);
|
|
107
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'mixed', items: [item] }).success).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('list 至多 50 项(limit 协议与卡片容量同源)', () => {
|
|
111
|
+
const many = Array.from({ length: 51 }, () => item);
|
|
112
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'list', items: many }).success).toBe(false);
|
|
113
|
+
const fifty = Array.from({ length: 50 }, (_, i) => ({ ...item, activityId: `demo-${i}` }));
|
|
114
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'list', items: fifty }).success).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('条目劣质 DTO 传导拒绝(复用条目单源校验——含旧键残留)', () => {
|
|
118
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'list', items: [{ ...item, imageUrl: 'https://?' }] }).success).toBe(false);
|
|
119
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'list', items: [{ ...item, status: 'running' }] }).success).toBe(false);
|
|
120
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: '', mode: 'list', items: [item] }).success).toBe(false);
|
|
121
|
+
expect(activityPlayCardDataSchema.safeParse({ mallId: 'mall-demo', mode: 'list', items: [{ ...item, loginRequired: false }] }).success).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
SHOPPING_DIRECTORY_SERVICE,
|
|
31
31
|
} from '../src/services/shopping-guide';
|
|
32
32
|
import { MALL_INFO_SERVICE } from '../src/services/mall-info';
|
|
33
|
+
import { ACTIVITY_PLAY_QUERY_SERVICE } from '../src/services/activity-play';
|
|
34
|
+
import { ACTIVITY_PLAY_PRIZES_SERVICE } from '../src/services/activity-play-prize';
|
|
33
35
|
import { AUTH_LOGIN_SERVICE } from '../src/assembly';
|
|
34
36
|
|
|
35
37
|
const constants = [
|
|
@@ -51,25 +53,27 @@ const constants = [
|
|
|
51
53
|
SHOPPING_DIRECTORY_SERVICE,
|
|
52
54
|
AUTH_LOGIN_SERVICE,
|
|
53
55
|
MALL_INFO_SERVICE,
|
|
56
|
+
ACTIVITY_PLAY_QUERY_SERVICE,
|
|
57
|
+
ACTIVITY_PLAY_PRIZES_SERVICE,
|
|
54
58
|
];
|
|
55
59
|
|
|
56
60
|
describe('service slot 词汇交叉锁(JSON 真源 ↔ TS 共址常量)', () => {
|
|
57
|
-
it('计数 =
|
|
58
|
-
expect(slotsJson.slots).toHaveLength(
|
|
59
|
-
expect(constants).toHaveLength(
|
|
61
|
+
it('计数 = 20(auth.alipay-login 与 mall.info 族含在内;聚合快照槽已退词汇;entry 随远端活动改造退场;prizes 入词汇——任务07)', () => {
|
|
62
|
+
expect(slotsJson.slots).toHaveLength(20);
|
|
63
|
+
expect(constants).toHaveLength(20);
|
|
60
64
|
});
|
|
61
65
|
|
|
62
66
|
it('常量并集 ≡ JSON slots(互为子集;无重复无缺漏)', () => {
|
|
63
67
|
const jsonSet = new Set(slotsJson.slots);
|
|
64
68
|
const constSet = new Set(constants);
|
|
65
|
-
expect(jsonSet.size).toBe(
|
|
66
|
-
expect(constSet.size).toBe(
|
|
69
|
+
expect(jsonSet.size).toBe(20);
|
|
70
|
+
expect(constSet.size).toBe(20);
|
|
67
71
|
for (const id of jsonSet) expect(constSet.has(id), `常量缺 ${id}`).toBe(true);
|
|
68
72
|
for (const id of constSet) expect(jsonSet.has(id), `JSON 缺 ${id}`).toBe(true);
|
|
69
73
|
});
|
|
70
74
|
|
|
71
|
-
it('词汇形状:domain.capability 且 domain ∈
|
|
72
|
-
const domains = new Set(['member', 'parking', 'promotion', 'shopping-guide', 'auth', 'mall']);
|
|
75
|
+
it('词汇形状:domain.capability 且 domain ∈ 六域 + activity-play', () => {
|
|
76
|
+
const domains = new Set(['member', 'parking', 'promotion', 'shopping-guide', 'auth', 'mall', 'activity-play']);
|
|
73
77
|
for (const id of slotsJson.slots) {
|
|
74
78
|
expect(id).toMatch(/^[a-z-]+\.[a-z-]+$/);
|
|
75
79
|
expect(domains.has(id.split('.')[0]), `${id} 域前缀未登记`).toBe(true);
|