Add seller performance dashboard charts
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 35s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 35s
This commit is contained in:
@@ -11,6 +11,7 @@ const {
|
||||
getClientAnalytics,
|
||||
getClientDetailsAnalytics,
|
||||
getClientFilterOptions,
|
||||
getDashboardAnalytics,
|
||||
getPreviousDate,
|
||||
getProductAnalytics,
|
||||
getProductDetailsAnalytics,
|
||||
@@ -135,6 +136,69 @@ test('getPreviousDate returns the calendar day before an ISO date', () => {
|
||||
assert.equal(getPreviousDate('invalid'), null);
|
||||
});
|
||||
|
||||
test('getDashboardAnalytics includes seller revenue and order metrics', async () => {
|
||||
const originalQuery = pool.query;
|
||||
const calls = [];
|
||||
|
||||
pool.query = async (sql, params = []) => {
|
||||
calls.push({ sql, params });
|
||||
|
||||
if (sql.includes('total_revenue')) {
|
||||
return {
|
||||
rows: [{
|
||||
total_revenue: 1000,
|
||||
total_items: 25,
|
||||
order_line_count: 5
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
||||
if (sql.includes('seller_orders') && sql.includes('SUM(quantidade * valor_unitario)')) {
|
||||
return {
|
||||
rows: [{ id: '977226210', name: 'KEDMA DA SILVA', value: 750 }]
|
||||
};
|
||||
}
|
||||
|
||||
if (sql.includes('seller_orders') && sql.includes('COUNT(DISTINCT')) {
|
||||
return {
|
||||
rows: [{ id: '977226210', name: 'KEDMA DA SILVA', value: 3 }]
|
||||
};
|
||||
}
|
||||
|
||||
if (sql.includes('SUM(quantidade), 0) as value')) {
|
||||
return {
|
||||
rows: [{ id: 'P1', name: 'Produto A', value: 10 }]
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
rows: [{ id: 'P1', name: 'Produto A', value: 1000 }]
|
||||
};
|
||||
};
|
||||
|
||||
try {
|
||||
const dashboard = await getDashboardAnalytics({ start: '2026-06-01', end: '2026-06-24' });
|
||||
const sellerRevenueQuery = calls.find(call => call.sql.includes('seller_orders') && call.sql.includes('SUM(quantidade * valor_unitario)'));
|
||||
const sellerOrdersQuery = calls.find(call => call.sql.includes('seller_orders') && call.sql.includes('COUNT(DISTINCT'));
|
||||
|
||||
assert.equal(calls.length, 5);
|
||||
calls.forEach(call => {
|
||||
assert.deepEqual(call.params, ['2026-06-01', '2026-06-24']);
|
||||
});
|
||||
assert.match(sellerRevenueQuery.sql, /substring\(NULLIF\(TRIM\(nome_vendedor\), ''\) from/);
|
||||
assert.match(sellerRevenueQuery.sql, /regexp_replace\(COALESCE\(nome_vendedor, ''\)/);
|
||||
assert.match(sellerOrdersQuery.sql, /COUNT\(DISTINCT COALESCE/);
|
||||
assert.deepEqual(dashboard.revenueBySeller, [
|
||||
{ id: '977226210', name: 'KEDMA DA SILVA', value: 750 }
|
||||
]);
|
||||
assert.deepEqual(dashboard.ordersBySeller, [
|
||||
{ id: '977226210', name: 'KEDMA DA SILVA', value: 3 }
|
||||
]);
|
||||
} finally {
|
||||
pool.query = originalQuery;
|
||||
}
|
||||
});
|
||||
|
||||
test('client tokens are opaque and stable for customer keys', () => {
|
||||
const phoneKey = '(16) 99103-6131';
|
||||
const nameKey = 'name:Cliente Sem Fone';
|
||||
|
||||
Reference in New Issue
Block a user