|
|
@@ -45,6 +45,44 @@ describe('OperationsService', () => {
|
|
|
expect(functions.operations).toHaveBeenCalledWith('ops/stores/list', { page: 1, pageSize: 20, search: '南昌', filters: { status: 'active' } });
|
|
|
});
|
|
|
|
|
|
+ it('fills missing store counts from filtered member totals on an older gateway', async () => {
|
|
|
+ functions.operations.and.callFake(async (operation, params) => {
|
|
|
+ if (operation === 'ops/stores/list') return { items: [{ userId: 287 }, { userId: 100 }, { userId: 73 }], total: 3 } as any;
|
|
|
+ const storeId = (params?.['filters'] as Record<string, unknown>)['parentUserId'];
|
|
|
+ return { items: [{}], total: storeId === 287 ? 0 : storeId === 100 ? 68 : 100 } as any;
|
|
|
+ });
|
|
|
+ const result = await service.stores(1, 20, '门店', { status: 'active' });
|
|
|
+ expect(result.items.map((store) => store.activeStudyingMemberCount)).toEqual([0, 68, 100]);
|
|
|
+ expect(result.activeStudyingMemberCountError).toBe('');
|
|
|
+ for (const parentUserId of [287, 100, 73]) {
|
|
|
+ expect(functions.operations).toHaveBeenCalledWith('ops/users/list', {
|
|
|
+ page: 1, pageSize: 1, search: '',
|
|
|
+ filters: { parentUserId, learningStatus: 'studying', status: 'active' },
|
|
|
+ sort: { field: 'registeredAt', direction: 'desc' }, refresh: false,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ it('uses the server count including zero without extra member queries', async () => {
|
|
|
+ functions.operations.and.resolveTo({ items: [{ userId: 1, activeStudyingMemberCount: 0 }, { userId: 2, activeStudyingMemberCount: 8 }] });
|
|
|
+ const result = await service.stores(1, 20);
|
|
|
+ expect(result.items.map((store) => store.activeStudyingMemberCount)).toEqual([0, 8]);
|
|
|
+ expect(functions.operations).toHaveBeenCalledTimes(1);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('keeps store data and reports count failures instead of inventing zero', async () => {
|
|
|
+ functions.operations.and.callFake(async (operation, params) => {
|
|
|
+ if (operation === 'ops/stores/list') return { items: [{ userId: 1 }, { userId: 2 }, { userId: 0 }], total: 3 } as any;
|
|
|
+ if ((params?.['filters'] as Record<string, unknown>)['parentUserId'] === 1) return { total: 5 } as any;
|
|
|
+ throw new Error('查询暂不可用');
|
|
|
+ });
|
|
|
+ const result = await service.stores(1, 20);
|
|
|
+ expect(result.items.length).toBe(3);
|
|
|
+ expect(result.items.map((store) => store.activeStudyingMemberCount)).toEqual([5, undefined, undefined]);
|
|
|
+ expect(result.activeStudyingMemberCountError).toContain('加载失败');
|
|
|
+ expect(functions.operations).toHaveBeenCalledTimes(3);
|
|
|
+ });
|
|
|
+
|
|
|
it('loads one store operating detail with an independent month', async () => {
|
|
|
functions.operations.and.resolveTo({ store: {}, month: '2026-08', summary: {}, members: [], coaches: [], appointments: [], courses: [] });
|
|
|
await service.storeDetail('store-object-1', '2026-08', true);
|