feat(F-160): completed feature
This commit is contained in:
@@ -375,7 +375,7 @@ export class ReportingService {
|
||||
WHERE i.order_id IN (SELECT id FROM filtered_orders)
|
||||
)
|
||||
SELECT
|
||||
${selectExpr}
|
||||
${selectExpr},
|
||||
COUNT(DISTINCT o.id)::int AS orders,
|
||||
COUNT(DISTINCT o.user_id) FILTER (WHERE o.user_id IS NOT NULL)::int AS customers,
|
||||
COALESCE(SUM(i.unit_price_cents * i.quantity), 0)::bigint AS gross_sales_cents,
|
||||
@@ -576,7 +576,7 @@ export class ReportingService {
|
||||
};
|
||||
case 'terminal':
|
||||
return {
|
||||
groupExpr: 'terminal_id',
|
||||
groupExpr: 'store_id, terminal_id',
|
||||
selectExpr: "NULL::text AS period, NULL::text AS channel, o.store_id, o.terminal_id",
|
||||
};
|
||||
default:
|
||||
|
||||
@@ -285,5 +285,27 @@ describe('ReportingService', () => {
|
||||
expect(result.items).toHaveLength(1);
|
||||
expect(result.items[0]!.storeId).toBe(storeId);
|
||||
});
|
||||
|
||||
it('separates dimensional columns from aggregate metrics with a comma', async () => {
|
||||
const pool = makeMockPool([]);
|
||||
const svc = new ReportingService(pool);
|
||||
await svc.sales(makeFilters({ groupBy: 'day' }));
|
||||
|
||||
expect(pool.query).toHaveBeenCalledWith(
|
||||
expect.stringMatching(/NULL::uuid AS terminal_id,\s+COUNT\(DISTINCT o\.id\)/),
|
||||
expect.any(Array),
|
||||
);
|
||||
});
|
||||
|
||||
it('groups terminal reports by both store and terminal', async () => {
|
||||
const pool = makeMockPool([]);
|
||||
const svc = new ReportingService(pool);
|
||||
await svc.sales(makeFilters({ groupBy: 'terminal' }));
|
||||
|
||||
expect(pool.query).toHaveBeenCalledWith(
|
||||
expect.stringContaining('GROUP BY store_id, terminal_id'),
|
||||
expect.any(Array),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user