@tbox.cn/app-provider-mock 0.4.0 → 0.6.0

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/tbox.module.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "name": "provider-mock",
4
- "title": "Mock",
5
- "description": "全槽本地演示供给:免真实厂商接入的完整商圈演示",
3
+ "id": "provider-mock",
4
+ "name": "Mock",
5
+ "description": "全槽本地演示供给:零配置开箱(免传输/凭据/实例配置/集成配置)",
6
6
  "version": "0.1.0",
7
7
  "kind": "business",
8
8
  "risk": {
@@ -12,7 +12,11 @@
12
12
  "distribution": {
13
13
  "defaultMode": "codegen"
14
14
  },
15
- "contributes": {
15
+ "dependencies": {
16
+ "modules": []
17
+ },
18
+ "env": [],
19
+ "declare": {
16
20
  "handlers": [],
17
21
  "tools": [],
18
22
  "cards": [],
@@ -26,143 +30,122 @@
26
30
  "credentialType": "-",
27
31
  "local": true,
28
32
  "provider": "mock",
29
- "implementation": "mock-member@1",
30
- "configSchema": "schemas/member.config.json"
33
+ "implementation": "mock-member@1"
31
34
  },
32
35
  {
33
36
  "service": "member.profile",
34
37
  "credentialType": "-",
35
38
  "local": true,
36
39
  "provider": "mock",
37
- "implementation": "mock-member@1",
38
- "configSchema": "schemas/member.config.json"
40
+ "implementation": "mock-member@1"
39
41
  },
40
42
  {
41
43
  "service": "member.card",
42
44
  "credentialType": "-",
43
45
  "local": true,
44
46
  "provider": "mock",
45
- "implementation": "mock-member@1",
46
- "configSchema": "schemas/member.config.json"
47
+ "implementation": "mock-member@1"
47
48
  },
48
49
  {
49
50
  "service": "member.benefits",
50
51
  "credentialType": "-",
51
52
  "local": true,
52
53
  "provider": "mock",
53
- "implementation": "mock-member@1",
54
- "configSchema": "schemas/member.config.json"
54
+ "implementation": "mock-member@1"
55
55
  },
56
56
  {
57
57
  "service": "member.enrollment",
58
58
  "credentialType": "-",
59
59
  "local": true,
60
60
  "provider": "mock",
61
- "implementation": "mock-member@1",
62
- "configSchema": "schemas/member.config.json"
61
+ "implementation": "mock-member@1"
63
62
  },
64
63
  {
65
64
  "service": "parking.query",
66
65
  "credentialType": "-",
67
66
  "local": true,
68
67
  "provider": "mock",
69
- "implementation": "mock-parking@1",
70
- "configSchema": "schemas/parking.config.json"
68
+ "implementation": "mock-parking@1"
71
69
  },
72
70
  {
73
71
  "service": "parking.payment",
74
72
  "credentialType": "-",
75
73
  "local": true,
76
74
  "provider": "mock",
77
- "implementation": "mock-parking@1",
78
- "configSchema": "schemas/parking.config.json"
75
+ "implementation": "mock-parking@1"
79
76
  },
80
77
  {
81
78
  "service": "parking.vehicle",
82
79
  "credentialType": "-",
83
80
  "local": true,
84
81
  "provider": "mock",
85
- "implementation": "mock-parking@1",
86
- "configSchema": "schemas/parking.config.json"
82
+ "implementation": "mock-parking@1"
87
83
  },
88
84
  {
89
85
  "service": "promotion.offers",
90
86
  "credentialType": "-",
91
87
  "local": true,
92
88
  "provider": "mock",
93
- "implementation": "mock-promotion@1",
94
- "configSchema": "schemas/promotion.config.json"
89
+ "implementation": "mock-promotion@1"
95
90
  },
96
91
  {
97
92
  "service": "promotion.entitlements",
98
93
  "credentialType": "-",
99
94
  "local": true,
100
95
  "provider": "mock",
101
- "implementation": "mock-promotion@1",
102
- "configSchema": "schemas/promotion.config.json"
96
+ "implementation": "mock-promotion@1"
103
97
  },
104
98
  {
105
99
  "service": "promotion.activities",
106
100
  "credentialType": "-",
107
101
  "local": true,
108
102
  "provider": "mock",
109
- "implementation": "mock-promotion@1",
110
- "configSchema": "schemas/promotion.config.json"
103
+ "implementation": "mock-promotion@1"
111
104
  },
112
105
  {
113
106
  "service": "promotion.acquisition",
114
107
  "credentialType": "-",
115
108
  "local": true,
116
109
  "provider": "mock",
117
- "implementation": "mock-promotion@1",
118
- "configSchema": "schemas/promotion.config.json"
110
+ "implementation": "mock-promotion@1"
119
111
  },
120
112
  {
121
113
  "service": "shopping-guide.catalog",
122
114
  "credentialType": "-",
123
115
  "local": true,
124
116
  "provider": "mock",
125
- "implementation": "mock-shopping@1",
126
- "configSchema": "schemas/shopping.config.json"
117
+ "implementation": "mock-shopping@1"
127
118
  },
128
119
  {
129
120
  "service": "shopping-guide.shops",
130
121
  "credentialType": "-",
131
122
  "local": true,
132
123
  "provider": "mock",
133
- "implementation": "mock-shopping@1",
134
- "configSchema": "schemas/shopping.config.json"
124
+ "implementation": "mock-shopping@1"
135
125
  },
136
126
  {
137
127
  "service": "shopping-guide.categories",
138
128
  "credentialType": "-",
139
129
  "local": true,
140
130
  "provider": "mock",
141
- "implementation": "mock-shopping@1",
142
- "configSchema": "schemas/shopping.config.json"
131
+ "implementation": "mock-shopping@1"
143
132
  },
144
133
  {
145
134
  "service": "shopping-guide.directory",
146
135
  "credentialType": "-",
147
136
  "local": true,
148
137
  "provider": "mock",
149
- "implementation": "mock-shopping@1",
150
- "configSchema": "schemas/shopping.config.json"
138
+ "implementation": "mock-shopping@1"
151
139
  },
152
140
  {
153
141
  "service": "mall.info",
154
142
  "credentialType": "-",
155
143
  "local": true,
156
144
  "provider": "mock",
157
- "implementation": "mock-mall-info@1",
158
- "configSchema": "schemas/mall-info.config.json"
145
+ "implementation": "mock-mall-info@1"
159
146
  }
160
147
  ]
161
148
  },
162
- "services": []
163
- },
164
- "dependencies": {
165
- "modules": []
166
- },
167
- "env": []
149
+ "consumes": []
150
+ }
168
151
  }
@@ -5,7 +5,7 @@
5
5
  * mock 实现经槽位轴产出(demo ref 厂商中立)。
6
6
  */
7
7
  import { beforeEach, describe, expect, it } from 'vitest';
8
- import { createIntegrationsRegistry, createAuthStrategyRegistry, createEnvironmentSecretProvider, createServerContext } from '@tbox.cn/app-sdk/server';
8
+ import { createIntegrationsRegistry, createAuthStrategyRegistry, createEnvironmentSecretProvider, createServerContext } from '@tbox.cn/app-agent-sdk-server';
9
9
  import { serverModule, enrollMockMember, logoutMockMember, __resetMockMemberState } from '../src/server/index';
10
10
  import { mallControlPlaneOf } from '@tbox.cn/app-contracts-mall/server';
11
11
  import type { IntegrationsConfig } from '@tbox.cn/app-contracts';
@@ -55,10 +55,11 @@ function requestContext(mallId = 'mall-demo'): RequestContext {
55
55
  };
56
56
  }
57
57
 
58
- function fixtureCtx(integrationsOverride?: IntegrationsConfig) {
58
+ function fixtureCtx(integrationsOverride?: IntegrationsConfig, ownerOf?: Record<string, string>) {
59
59
  const registry = createIntegrationsRegistry({
60
60
  integrations: integrationsOverride ?? integrations,
61
61
  catalog,
62
+ ...(ownerOf ? { ownerOf } : {}),
62
63
  authStrategies: createAuthStrategyRegistry(),
63
64
  secretProvider: createEnvironmentSecretProvider({ source: {}, production: false }),
64
65
  instanceIdOf: (scope) => scope.mallId ?? '',
@@ -238,86 +239,6 @@ describe('C5:scoped mock 换码器(入会闭环身份供给)', () => {
238
239
  });
239
240
  });
240
241
 
241
- describe('F2 端到端:config 级联(resolveService 全链——五层浅合并消费)', () => {
242
- it('槽级 config 流入:parking.query.config.feeCents=200 → 报价同源', async () => {
243
- const override: IntegrationsConfig = {
244
- ...integrations,
245
- services: {
246
- ...integrations.services,
247
- 'parking.query': { ...integrations.services['parking.query'], config: { feeCents: 200 } },
248
- },
249
- };
250
- const { ctx } = fixtureCtx(override);
251
- const parking = (await ctx.integrations!.resolveService({
252
- service: 'parking.query',
253
- scope: { mallId: 'mall-demo' },
254
- request: requestContext(),
255
- })) as { queryFee(q: unknown, input: { plateNo: string }): Promise<Array<{ totalCents: number; payableCents: number }>> };
256
- const quotes = await parking.queryFee({ scope: {} } as never, { plateNo: 'demo-plate' });
257
- expect(quotes[0]?.totalCents).toBe(200);
258
- expect(quotes[0]?.payableCents).toBe(200);
259
- });
260
-
261
- it('root config 级联:根 config.cardName → member 槽实例同源', async () => {
262
- const override: IntegrationsConfig = { ...integrations, config: { cardName: 'Root 卡' } };
263
- const { ctx } = fixtureCtx(override);
264
- const member = (await ctx.integrations!.resolveService({
265
- service: 'member.account',
266
- scope: { mallId: 'mall-demo' },
267
- request: requestContext(),
268
- })) as { queryPoints(u: string): Promise<{ membershipLabel: string }> };
269
- await expect(member.queryPoints('u1')).resolves.toMatchObject({ membershipLabel: 'Root 卡' });
270
- });
271
-
272
- it('浅合并键级覆盖:root 共享键 + slot 差异键并行生效(面板分层配置语义)', async () => {
273
- const override: IntegrationsConfig = {
274
- ...integrations,
275
- config: { parkName: 'RootP' },
276
- services: {
277
- ...integrations.services,
278
- 'parking.query': { ...integrations.services['parking.query'], config: { feeCents: 200 } },
279
- },
280
- };
281
- const { ctx } = fixtureCtx(override);
282
- const parking = (await ctx.integrations!.resolveService({
283
- service: 'parking.query',
284
- scope: { mallId: 'mall-demo' },
285
- request: requestContext(),
286
- })) as {
287
- queryFee(q: unknown, input: { plateNo: string }): Promise<Array<{ totalCents: number }>>;
288
- queryParkingInfo(q: unknown, kind: string): Promise<{ title: string }>;
289
- };
290
- const quotes = await parking.queryFee({ scope: {} } as never, { plateNo: 'demo-plate' });
291
- expect(quotes[0]?.totalCents).toBe(200); // slot 差异键
292
- const info = await parking.queryParkingInfo({ scope: {} } as never, 'chargeRules');
293
- expect(info.title).toBe('RootP'); // root 共享键
294
- });
295
-
296
- it('domain 层级联 + slot 胜 domain:域级键流入 + 槽级同名键覆盖(键级层序)', async () => {
297
- const override: IntegrationsConfig = {
298
- ...integrations,
299
- domains: { parking: { config: { parkName: 'DomainP', remainingSpaces: 99 } } },
300
- services: {
301
- ...integrations.services,
302
- 'parking.query': { ...integrations.services['parking.query'], config: { feeCents: 250, parkName: 'SlotP' } },
303
- },
304
- };
305
- const { ctx } = fixtureCtx(override);
306
- const parking = (await ctx.integrations!.resolveService({
307
- service: 'parking.query',
308
- scope: { mallId: 'mall-demo' },
309
- request: requestContext(),
310
- })) as {
311
- queryFee(q: unknown, input: { plateNo: string }): Promise<Array<{ totalCents: number }>>;
312
- queryParkingInfo(q: unknown, kind: string): Promise<{ title: string; entries: Array<{ label: string; value: string }> }>;
313
- };
314
- const quotes = await parking.queryFee({ scope: {} } as never, { plateNo: 'demo-plate' });
315
- expect(quotes[0]?.totalCents).toBe(250); // 槽级差异键
316
- const info = await parking.queryParkingInfo({ scope: {} } as never, 'chargeRules');
317
- expect(info.title).toBe('SlotP'); // slot 胜 domain(同名键)
318
- expect(info.entries).toContainEqual({ label: '剩余车位', value: '99' }); // 域级键流入(槽未覆盖)
319
- });
320
- });
321
242
 
322
243
  // ── 隐式默认单实例声明(零拓扑兜底——provider-mock declareProviderInstances) ──
323
244
 
@@ -44,13 +44,4 @@ describe('mockMallInfoFactory:请求形状守卫', () => {
44
44
  expect(MOCK_MALL_INFO_PROVIDER).toBe('mock');
45
45
  expect(MOCK_MALL_INFO_IMPL).toBe('mock-mall-info@1');
46
46
  });
47
-
48
- it('config 驱动:name 直出 / 空串回退动态别名 / 分式经纬度合法', async () => {
49
- const named = makePort({ name: '星河 Mock 小镇' });
50
- await expect(named.getMallInfo('1102588')).resolves.toMatchObject({ name: '星河 Mock 小镇' });
51
- const fallback = makePort({ name: '', latitude: 31.2304 });
52
- const info = await fallback.getMallInfo('1102588');
53
- expect(info?.name).toBe('示例商场(1102588)');
54
- expect((info as { latitude?: number })?.latitude).toBe(31.2304);
55
- });
56
47
  });
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { beforeEach, describe, expect, it } from 'vitest';
7
7
  import { MockMemberServiceImpl } from '../src/server/member';
8
- import { MockParkingServiceImpl } from '../src/server/parking';
8
+ import { MockParkingServiceImpl, __resetMockParkingState } from '../src/server/parking';
9
9
  import { MockPromotionServiceImpl } from '../src/server/promotion';
10
10
  import { MockShoppingServiceImpl } from '../src/server/shopping';
11
11
  import { serverModule, MOCK_SHELL_USER_ID, enrollMockMember, logoutMockMember, isMockMemberEnrolled, isMockMemberLoggedOut, __resetMockMemberState } from '../src/server/index';
@@ -14,6 +14,7 @@ import { merchantLocationSchema, merchantStatusSchema } from '@tbox.cn/app-contr
14
14
 
15
15
  beforeEach(() => {
16
16
  __resetMockMemberState();
17
+ __resetMockParkingState();
17
18
  });
18
19
  import type { ParkingQueryContext, PromotionQueryContext, ShopRecord, ShoppingQueryContext } from '@tbox.cn/app-contracts-mall';
19
20
 
@@ -90,6 +91,15 @@ describe('provider-mock:mock 实现 Port 面与厂商中立', () => {
90
91
  expect(member.enrollUrl).toMatch(/^alipays:\/\//);
91
92
  });
92
93
 
94
+ it('member:getCard 发 dynamic face(presentation+cardImageUrl,与真实 provider 同构)', async () => {
95
+ const member = new MockMemberServiceImpl();
96
+ await member.enroll({ userId: 'u1', identity: 'enrollment_submission', fieldValues: {}, acceptedConsentIds: [], idempotencyKey: 'k1' });
97
+ const card = await member.getCard('u1');
98
+ // black 恒发:恢复 wanda 世代叠字后唯一可读的深卡配对(见 member.ts CARD_FACE_URL 注)
99
+ expect(card?.presentation).toEqual({ variant: 'black', labelsEmbedded: true });
100
+ expect(card?.cardImageUrl).toMatch(/^https:\/\/mdn\.alipayobjects\.com\//);
101
+ });
102
+
93
103
  it('parking:报价/权益/reprice/支付三步链(reconcile 恒 PAID),ref 恒 demo: 前缀', async () => {
94
104
  const parking = new MockParkingServiceImpl('mall-demo');
95
105
  const quote = (await parking.queryFee(parkCtx, { plateNo: 'demo-plate' }))[0];
@@ -109,8 +119,22 @@ describe('provider-mock:mock 实现 Port 面与厂商中立', () => {
109
119
  const page = await promotion.searchOffers(promoCtx, { keyword: '' });
110
120
  expect(page.items.length).toBeGreaterThanOrEqual(2);
111
121
  expect(page.items.every((o) => o.offerRef.startsWith('demo:'))).toBe(true);
122
+ expect(page.items).toEqual(expect.arrayContaining([
123
+ expect.objectContaining({
124
+ title: '满 100 减 20 元券',
125
+ imageUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*LHeBTp64HUYAAAAARLAAAAgAegitAQ/fmt.webp',
126
+ }),
127
+ expect.objectContaining({
128
+ title: '餐饮双人套餐 5 折',
129
+ imageUrl: 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*GzryQrxX2WEAAAAATYAAAAgAegitAQ/fmt.webp',
130
+ }),
131
+ ]));
112
132
  const detail = await promotion.getOfferDetail(promoCtx, { offerRef: 'demo:coupon:1001' });
113
133
  expect(detail?.title).toContain('满 100 减 20');
134
+ const activities = await promotion.listActivities();
135
+ expect(activities.items[0]?.coverUrl).toBe('https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*DIRTQ6CBBC0AAAAAgEAAAAgAegitAQ/fmt.webp');
136
+ const activityDetail = await promotion.getActivityDetail(promoCtx, 'demo:activity:3001');
137
+ expect(activityDetail?.coverUrl).toBe('https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*DIRTQ6CBBC0AAAAAgEAAAAgAegitAQ/fmt.webp');
114
138
  const op = await promotion.acquire(promoCtx, { offerRef: 'demo:coupon:1001', externalMemberRef: 'demo:member:u1', idempotencyKey: 'k1' });
115
139
  expect(op.status).toBe('SUCCEEDED');
116
140
  });
@@ -170,6 +194,25 @@ describe('provider-mock:shopping mock 行为(seed 派生 + 过滤矩阵)',
170
194
  expect(byBrand.total).toBe(2); // 品牌命中
171
195
  });
172
196
 
197
+ it('门店 logo 按名称映射到指定素材', async () => {
198
+ const page = await impl.searchShops({ ctx: shopCtx, page: 1, pageSize: 20 });
199
+ const logos = Object.fromEntries(page.items.map((shop) => [shop.name, shop.logoUrl]));
200
+ expect(logos).toMatchObject({
201
+ '屈臣氏': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*c7cRQIe83NYAAAAAQFAAAAgAegitAQ/original',
202
+ '周大福': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*WKXJTqR3BwQAAAAAQCAAAAgAegitAQ/original',
203
+ '星巴克': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*pa08SZMqBNYAAAAAQEAAAAgAegitAQ/original',
204
+ '永辉超市': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*5Y45SqtTrvcAAAAAQCAAAAgAegitAQ/original',
205
+ '小米': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*6FBqSYVXFDEAAAAAMrAAAAgAegitAQ/original',
206
+ '华为': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*BrpxQ6dwGj0AAAAAQCAAAAgAegitAQ/original',
207
+ 'NIKE 专卖店': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*dFmuSKEMDwIAAAAAQCAAAAgAegitAQ/original',
208
+ 'NIKE 跑步体验店': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*dFmuSKEMDwIAAAAAQCAAAAgAegitAQ/original',
209
+ '海底捞': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*18hVSI5dg6EAAAAAQCAAAAgAegitAQ/original',
210
+ '安踏': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*edsgTpDq0GUAAAAAQDAAAAgAegitAQ/original',
211
+ '西贝莜面村': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*9X-US6dZvcIAAAAARAAAAAgAegitAQ/fmt.webp',
212
+ '外婆家': 'https://mdn.alipayobjects.com/huamei_b00jk5/afts/img/A*_uaLSZqH8-4AAAAASOAAAAgAegitAQ/fmt.webp',
213
+ });
214
+ });
215
+
173
216
  it('类目等值过滤', async () => {
174
217
  const page = await impl.searchShops({ ctx: shopCtx, page: 1, pageSize: 10, businessCategory: '餐饮' });
175
218
  expect(page.total).toBe(4);
@@ -347,105 +390,85 @@ describe('provider-mock:登出态(logout 路由 + 换码降级 GUEST 形态
347
390
  });
348
391
  });
349
392
 
350
- describe('provider-mock:config 驱动(fail-soft 快照)', () => {
351
- const enroll = (member: MockMemberServiceImpl, userId: string) =>
352
- member.enroll({ userId, identity: 'enrollment_submission', fieldValues: {}, acceptedConsentIds: [], idempotencyKey: `k-${userId}` });
393
+ describe('provider-mock:停车属人绑定 store(绑定/回显闭环)', () => {
394
+ const ctxOf = (subjectId?: string): ParkingQueryContext =>
395
+ ({
396
+ scope: { miniAppId: 'demo-app', mallId: 'mall-demo' },
397
+ ...(subjectId ? { subjectId } : {}),
398
+ requestContext: { credentials: {} },
399
+ }) as ParkingQueryContext;
400
+
401
+ it('跨实例可见(factory 每请求新建模拟):A 实例绑定 → B 实例列表回显', async () => {
402
+ const writer = new MockParkingServiceImpl('mall-demo');
403
+ const reader = new MockParkingServiceImpl('mall-demo');
404
+ await writer.bindVehicle(ctxOf('u1'), '浙A12345');
405
+ const { bound } = await reader.listVehicles(ctxOf('u1'));
406
+ expect(bound.map((v) => v.plateNo)).toEqual(['浙A12345']);
407
+ expect(bound[0]?.vehicleRef).toBe('demo:vehicle:浙A12345');
408
+ });
409
+
410
+ it('属人隔离:u2 看不到 u1 车队;u2 解绑 u1 的车报「未找到要解绑的车牌」', async () => {
411
+ const svc = new MockParkingServiceImpl('mall-demo');
412
+ await svc.bindVehicle(ctxOf('u1'), '浙A12345');
413
+ await expect(svc.listVehicles(ctxOf('u2'))).resolves.toEqual({ bound: [] });
414
+ await expect(svc.unbindVehicle(ctxOf('u2'), { plateNo: '浙A12345' })).rejects.toThrow('未找到要解绑的车牌');
415
+ });
416
+
417
+ it('重复绑定幂等:同车牌返回既有(大小写归一),计数不增', async () => {
418
+ const svc = new MockParkingServiceImpl('mall-demo');
419
+ await svc.bindVehicle(ctxOf('u1'), '浙A12345');
420
+ await svc.bindVehicle(ctxOf('u1'), '浙A12345');
421
+ const again = await svc.bindVehicle(ctxOf('u1'), '浙a12345');
422
+ const { bound } = await svc.listVehicles(ctxOf('u1'));
423
+ expect(bound).toHaveLength(1);
424
+ expect(again.vehicleRef).toBe('demo:vehicle:浙A12345');
425
+ expect(again.boundAt).toBeDefined();
426
+ });
427
+
428
+ it('绑定上限 3 辆:第 4 辆抛「最多绑定 3 辆车」', async () => {
429
+ const svc = new MockParkingServiceImpl('mall-demo');
430
+ for (const plate of ['浙A11111', '浙B22222', '粤C33333']) {
431
+ await svc.bindVehicle(ctxOf('u1'), plate);
432
+ }
433
+ await expect(svc.bindVehicle(ctxOf('u1'), '浙D44444')).rejects.toThrow('最多绑定 3 辆车');
434
+ });
353
435
 
354
- it('member 全字段:卡名/初值积分/等级/名称/深链/流水同源', async () => {
355
- const member = new MockMemberServiceImpl({}, { cardName: '黑金卡', initialPoints: 800, levelName: '金卡', memberName: '张三' });
356
- await enroll(member, 'u1');
357
- await expect(member.getCard('u1')).resolves.toMatchObject({ cardDisplay: '黑金卡', levelName: '金卡' });
358
- await expect(member.queryPoints('u1')).resolves.toMatchObject({ balance: 800, membershipLabel: '黑金卡' });
359
- await expect(member.getProfile('u1')).resolves.toMatchObject({ labels: [{ labelRef: 'demo:label:1', name: '张三' }] });
360
- const usage = await member.listPointUsage('u1', 1, 10);
361
- expect(usage.items[0].amount).toBe('+800');
436
+ it('匿名写拒绝:无 subjectId 绑定/解绑显性报错;匿名读降级空车队', async () => {
437
+ const svc = new MockParkingServiceImpl('mall-demo');
438
+ await expect(svc.bindVehicle(ctxOf(), '浙A12345')).rejects.toThrow('缺少用户身份');
439
+ await expect(svc.unbindVehicle(ctxOf(), { plateNo: '浙A12345' })).rejects.toThrow('缺少用户身份');
440
+ await expect(svc.listVehicles(ctxOf())).resolves.toEqual({ bound: [] });
362
441
  });
363
442
 
364
- it('member 非法值回退缺省:类型族/空串/NaN/分式整数(intKeys)', async () => {
365
- const member = new MockMemberServiceImpl({}, { initialPoints: 'x', cardName: '', enrollUrl: '', levelName: '' });
366
- await enroll(member, 'u1');
367
- await expect(member.queryPoints('u1')).resolves.toMatchObject({ balance: 300, membershipLabel: '示例会员卡' });
368
- const card = (await member.getCard('u1'))!;
369
- expect('levelName' in card).toBe(false);
370
- expect(member.enrollUrl).toMatch(/^alipays:\/\//);
371
- const nan = new MockMemberServiceImpl({}, { initialPoints: Number.NaN });
372
- await enroll(nan, 'u2');
373
- await expect(nan.queryPoints('u2')).resolves.toMatchObject({ balance: 300 });
374
- const fractional = new MockMemberServiceImpl({}, { initialPoints: 1500.5 });
375
- await enroll(fractional, 'u3');
376
- await expect(fractional.queryPoints('u3')).resolves.toMatchObject({ balance: 300 });
377
- });
378
-
379
- it('member 余额惰性读:入会不写种子 + 显式增减单源(queryPoints ≡ getBenefits)', async () => {
380
- const member = new MockMemberServiceImpl({}, { initialPoints: 500 });
381
- await expect(member.queryPoints('nobody')).resolves.toMatchObject({ balance: 0 });
382
- await enroll(member, 'u1');
383
- await expect(member.queryPoints('u1')).resolves.toMatchObject({ balance: 500 });
384
- await expect(member.getBenefits('u1')).resolves.toMatchObject({ availablePoints: 500 });
385
- await expect(member.deductPoints('u1', 100, 'd1')).resolves.toBe(true);
386
- await expect(member.deductPoints('u1', 1000, 'd2')).resolves.toBe(false);
387
- await expect(member.getBenefits('u1')).resolves.toMatchObject({ availablePoints: 400 });
388
- await expect(member.awardPoints('u1', 50)).resolves.toBe(true);
389
- await expect(member.refundPoints('u1', 25, 'r1')).resolves.toBe(true);
390
- await expect(member.queryPoints('u1')).resolves.toMatchObject({ balance: 475 });
391
- });
392
-
393
- it('parking 驱动:费用/权益开关/开票开关/信息/记录/寻车同源', async () => {
394
- const parking = new MockParkingServiceImpl('mall-demo', {
395
- feeCents: 200, parkName: 'P2 停车场', memberBenefitEnabled: false, invoiceEnabled: false, remainingSpaces: 56, vehicleSpaceNo: 'C-9',
396
- });
397
- const quote = (await parking.queryFee(parkCtx, { plateNo: 'demo-plate' }))[0];
398
- expect(quote).toMatchObject({ totalCents: 200, payableCents: 200 });
399
- expect(quote.feeItems[0]).toEqual({ name: '停车费(3 小时)', amountCents: 200 });
400
- const benefits = await parking.queryApplicableBenefits(parkCtx, 'demo-plate');
401
- expect(benefits).toHaveLength(1);
402
- expect(benefits[0].kind).toBe('points');
403
- await expect(parking.getInvoiceSettings()).resolves.toEqual({ parkingInvoiceEnabled: false });
404
- const info = await parking.queryParkingInfo(parkCtx, 'chargeRules');
405
- expect(info.title).toBe('P2 停车场');
406
- expect(info.entries).toContainEqual({ label: '剩余车位', value: '56' });
407
- expect(info.entries).toContainEqual({ label: '会员权益', value: '—' });
408
- await expect(parking.getOrderInfo(parkCtx, 'r')).resolves.toMatchObject({ payableFeeCents: 200 });
409
- const records = await parking.listPaymentRecords(parkCtx, 1, 10);
410
- expect(records.items[0]).toMatchObject({ parkName: 'P2 停车场', amountCents: 200 });
411
- expect((await parking.locateVehicle(parkCtx, 'demo-plate'))?.spaceNo).toBe('C-9');
412
- });
413
-
414
- it('promotion 驱动:券标题/面额/门槛 + 团购开关 + 资产/活动派生', async () => {
415
- const promotion = new MockPromotionServiceImpl({
416
- couponTitle: '满 200 减 50 元券', couponValueCents: 5000, couponThresholdCents: 20000, couponValidityDays: 7, grouponEnabled: false, activityTitle: '周年庆',
417
- });
418
- const page = await promotion.searchOffers(promoCtx, { keyword: '' });
419
- expect(page.items).toHaveLength(1);
420
- expect(page.items[0].title).toBe('满 200 减 50 元券');
421
- expect(page.items[0].facets[0]).toMatchObject({ value: 5000, thresholdCents: 20000 });
422
- const ents = await promotion.listEntitlements(promoCtx, {});
423
- expect(ents.items[0].title).toBe('满 200 减 50 元券');
424
- const acts = await promotion.listActivities();
425
- expect(acts.items[0].title).toBe('周年庆');
426
- await expect(promotion.getOfferDetail(promoCtx, { offerRef: 'demo:coupon:1001' })).resolves.toMatchObject({ title: '满 200 减 50 元券' });
427
- });
428
-
429
- it('shopping 驱动:追加门店进列表/类目/楼层目录', async () => {
430
- const impl = new MockShoppingServiceImpl(undefined, {
431
- extraShopName: '新店', extraShopFloor: '2 楼', extraShopCategory: '文创', extraShopUnit: '203', extraShopOpen: false,
432
- });
433
- const page = await impl.searchShops({ ctx: shopCtx, page: 1, pageSize: 20 });
434
- expect(page.total).toBe(13);
435
- const extra = page.items.find((s) => s.merchantId === 'demo-shop-1013');
436
- expect(extra).toMatchObject({ name: '新店', location: { floorName: '2 楼', unitName: '203' }, status: { code: 'disabled', label: '休息中' } });
437
- const cats = await impl.listCategories(shopCtx);
438
- expect(cats.find((c) => c.name === '文创')?.merchantCount).toBe(1);
439
- const dir = await impl.getDirectory(shopCtx);
440
- expect(dir?.buildings[0].floors.find((f) => f.floorName === '2 楼')?.merchantCount).toBe(3);
441
- expect((await impl.searchShops({ ctx: shopCtx, page: 1, pageSize: 20, floorCode: '2 楼' })).total).toBe(3);
443
+ it('未命中解绑抛「未找到要解绑的车牌」;命中后车队移除', async () => {
444
+ const svc = new MockParkingServiceImpl('mall-demo');
445
+ await svc.bindVehicle(ctxOf('u1'), '浙A12345');
446
+ await expect(svc.unbindVehicle(ctxOf('u1'), { vehicleRef: 'demo:vehicle:浙B00000' })).rejects.toThrow('未找到要解绑的车牌');
447
+ await svc.unbindVehicle(ctxOf('u1'), { vehicleRef: 'demo:vehicle:浙A12345' });
448
+ await expect(svc.listVehicles(ctxOf('u1'))).resolves.toEqual({ bound: [] });
449
+ });
450
+
451
+ it('queryFee 无线索扫描属人车队:在场演示位(首辆)出报价;空车队返回空', async () => {
452
+ const svc = new MockParkingServiceImpl('mall-demo');
453
+ await expect(svc.queryFee(ctxOf('u1'), {})).resolves.toEqual([]);
454
+ await svc.bindVehicle(ctxOf('u1'), '浙A12345');
455
+ await svc.bindVehicle(ctxOf('u1'), '浙B22222');
456
+ const quotes = await svc.queryFee(ctxOf('u1'), {});
457
+ expect(quotes.map((x) => x.plateNo)).toEqual(['浙A12345']);
458
+ });
459
+
460
+ it('queryFee 显式车牌照查不受绑定约束(厂商语义;匿名也出报价——存量行为锁)', async () => {
461
+ const svc = new MockParkingServiceImpl('mall-demo');
462
+ const quote = (await svc.queryFee(ctxOf(), { plateNo: 'demo-plate' }))[0];
463
+ expect(quote).toMatchObject({ plateNo: 'demo-plate', payableCents: 1500 });
442
464
  });
443
465
 
444
- it('shopping 消费点守卫:空白名不追加 + 未知楼层回退 3 楼', async () => {
445
- const blank = new MockShoppingServiceImpl(undefined, { extraShopName: ' ' });
446
- expect((await blank.searchShops({ ctx: shopCtx, page: 1, pageSize: 20 })).total).toBe(12);
447
- const badFloor = new MockShoppingServiceImpl(undefined, { extraShopName: 'X 店', extraShopFloor: '5 楼' });
448
- const page = await badFloor.searchShops({ ctx: shopCtx, page: 1, pageSize: 20, floorCode: '3 楼' });
449
- expect(page.items.some((s) => s.merchantId === 'demo-shop-1013')).toBe(true);
466
+ it('listVehicles 仅首辆标 parked(在场演示位),其余缺省', async () => {
467
+ const svc = new MockParkingServiceImpl('mall-demo');
468
+ await svc.bindVehicle(ctxOf('u1'), '浙A12345');
469
+ await svc.bindVehicle(ctxOf('u1'), '浙B22222');
470
+ const { bound } = await svc.listVehicles(ctxOf('u1'));
471
+ expect(bound[0]?.parked).toBe(true);
472
+ expect(bound[1]?.parked).toBeUndefined();
450
473
  });
451
474
  });
package/tsup.config.ts CHANGED
@@ -15,7 +15,8 @@ export default defineConfig({
15
15
  // 声明产物一次性构建无需增量——仅 dts 关闭,typecheck 的增量缓存不受影响。
16
16
  dts: { compilerOptions: { incremental: false } },
17
17
  external: [
18
- '@tbox.cn/app-sdk',
18
+ '@tbox.cn/app-agent-sdk-client',
19
+ '@tbox.cn/app-agent-sdk-server',
19
20
  '@tbox.cn/app-contracts',
20
21
  '@tbox.cn/app-contracts-mall',
21
22
  // mock-enroll-route 挂 express Router(devDep 不自动外部化——沿 module-member 先例显式声明,
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "Mock 商场基础信息实例配置",
4
- "type": "object",
5
- "properties": {
6
- "name": { "type": "string", "title": "商场名称", "description": "空串 = 动态别名「示例商场(mallId)」回退", "default": "" },
7
- "address": { "type": "string", "title": "商场地址", "default": "示例商场地址(demo)" },
8
- "latitude": { "type": "number", "minimum": -90, "maximum": 90, "title": "纬度(分式合法)", "default": 30 },
9
- "longitude": { "type": "number", "minimum": -180, "maximum": 180, "title": "经度(分式合法)", "default": 120 }
10
- }
11
- }
@@ -1,13 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "Mock 会员域实例配置",
4
- "type": "object",
5
- "properties": {
6
- "memberName": { "type": "string", "title": "会员名称", "description": "资料标签展示", "default": "示例会员" },
7
- "cardName": { "type": "string", "title": "会员卡名称", "description": "卡面与积分标签", "default": "示例会员卡" },
8
- "levelName": { "type": "string", "title": "等级名称", "description": "空串 = 不展示等级区", "default": "" },
9
- "initialPoints": { "type": "integer", "minimum": 0, "title": "初始积分", "description": "入会后余额;流水金额同源派生", "default": 300 },
10
- "enrollUrl": { "type": "string", "title": "入会落地页深链", "description": "alipays:// 或 H5", "default": "alipays://platformapi/startapp?appId=demo&page=v/index/index" },
11
- "loginUrl": { "type": "string", "title": "登录页深链", "description": "alipays:// 或 H5", "default": "alipays://platformapi/startapp?appId=demo&page=v/login/index" }
12
- }
13
- }
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "Mock 停车域实例配置",
4
- "type": "object",
5
- "properties": {
6
- "parkName": { "type": "string", "title": "停车场名称", "description": "信息卡标题 + 缴费记录", "default": "示例停车场" },
7
- "feeName": { "type": "string", "title": "费用项名称", "default": "停车费(3 小时)" },
8
- "feeCents": { "type": "integer", "minimum": 0, "title": "停车费(分)", "default": 1500 },
9
- "remainingSpaces": { "type": "integer", "minimum": 0, "title": "剩余车位", "default": 128 },
10
- "firstHourRate": { "type": "string", "title": "首小时费率文案", "default": "免费" },
11
- "memberBenefitEnabled": { "type": "boolean", "title": "会员折扣权益开关", "description": "关闭 = 权益列表少一项 + reprice 不变", "default": true },
12
- "memberBenefitDiscountCents": { "type": "integer", "minimum": 0, "title": "会员折扣权益预估减免(分)", "default": 75 },
13
- "pointsBenefitEnabled": { "type": "boolean", "title": "积分抵扣权益开关", "description": "关闭 = 权益列表少「积分抵 5 元」项(积分入口)", "default": true },
14
- "invoiceEnabled": { "type": "boolean", "title": "开票入口开关", "description": "关闭 = 缴费卡无开票按钮", "default": true },
15
- "vehicleFloor": { "type": "string", "title": "寻车楼层", "default": "B1" },
16
- "vehicleZone": { "type": "string", "title": "寻车区域", "default": "A 区" },
17
- "vehicleSpaceNo": { "type": "string", "title": "寻车车位号", "default": "A-128" }
18
- }
19
- }