New filter panel layout at client page
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m20s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m20s
This commit is contained in:
@@ -10,6 +10,7 @@ const {
|
||||
isClientToken,
|
||||
getClientAnalytics,
|
||||
getClientDetailsAnalytics,
|
||||
getClientFilterOptions,
|
||||
getPreviousDate,
|
||||
getProductAnalytics,
|
||||
getProductDetailsAnalytics,
|
||||
@@ -91,6 +92,33 @@ test('buildDateFilter ignores invalid bounds', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('buildDateFilter composes client metadata predicates after date predicates', () => {
|
||||
const filter = buildDateFilter({
|
||||
start: '2026-05-01',
|
||||
end: '2026-05-28',
|
||||
marketplace: ' Mercado Livre ',
|
||||
canal_venda: ' Online ',
|
||||
seller: 'id:VEN-1'
|
||||
});
|
||||
|
||||
assert.deepEqual(filter.params, ['2026-05-01', '2026-05-28', 'Mercado Livre', 'Online', 'VEN-1']);
|
||||
assert.equal(filter.endParamIndex, 2);
|
||||
assert.equal(
|
||||
filter.whereClause,
|
||||
"WHERE data_pedido_date IS NOT NULL AND data_pedido_date >= $1::date AND data_pedido_date <= $2::date AND NULLIF(TRIM(marketplace), '') = $3 AND NULLIF(TRIM(canal_venda), '') = $4 AND NULLIF(TRIM(id_vendedor), '') = $5"
|
||||
);
|
||||
});
|
||||
|
||||
test('buildDateFilter can filter seller by display name when no seller id is selected', () => {
|
||||
const filter = buildDateFilter({ seller: 'name:Maria' });
|
||||
|
||||
assert.deepEqual(filter.params, ['Maria']);
|
||||
assert.equal(
|
||||
filter.whereClause,
|
||||
"WHERE data_pedido_date IS NOT NULL AND NULLIF(TRIM(nome_vendedor), '') = $1"
|
||||
);
|
||||
});
|
||||
|
||||
test('getPreviousDate returns the calendar day before an ISO date', () => {
|
||||
assert.equal(getPreviousDate('2026-06-15'), '2026-06-14');
|
||||
assert.equal(getPreviousDate('2026-03-01'), '2026-02-28');
|
||||
@@ -540,6 +568,50 @@ test('getClientAnalytics returns opaque client tokens', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('getClientFilterOptions returns distinct date-scoped order metadata options', async () => {
|
||||
const originalQuery = pool.query;
|
||||
const calls = [];
|
||||
|
||||
pool.query = async (sql, params = []) => {
|
||||
calls.push({ sql, params });
|
||||
|
||||
if (sql.includes('SELECT DISTINCT NULLIF(TRIM(marketplace)')) {
|
||||
return { rows: [{ value: 'Mercado Livre' }, { value: 'Shopee' }] };
|
||||
}
|
||||
|
||||
if (sql.includes('SELECT DISTINCT NULLIF(TRIM(canal_venda)')) {
|
||||
return { rows: [{ value: 'Online' }] };
|
||||
}
|
||||
|
||||
return {
|
||||
rows: [
|
||||
{ id: 'VEN-1', name: 'Maria' },
|
||||
{ id: '', name: 'Sem ID' },
|
||||
{ id: 'VEN-1', name: 'Maria' }
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
try {
|
||||
const options = await getClientFilterOptions({ start: '2026-06-01', end: '2026-06-15' });
|
||||
|
||||
assert.equal(calls.length, 3);
|
||||
calls.forEach(call => {
|
||||
assert.deepEqual(call.params, ['2026-06-01', '2026-06-15']);
|
||||
assert.match(call.sql, /data_pedido_date >= \$1::date/);
|
||||
assert.match(call.sql, /data_pedido_date <= \$2::date/);
|
||||
});
|
||||
assert.deepEqual(options.marketplaces, ['Mercado Livre', 'Shopee']);
|
||||
assert.deepEqual(options.salesChannels, ['Online']);
|
||||
assert.deepEqual(options.sellers, [
|
||||
{ value: 'id:VEN-1', id: 'VEN-1', name: 'Maria' },
|
||||
{ value: 'name:Sem ID', id: '', name: 'Sem ID' }
|
||||
]);
|
||||
} finally {
|
||||
pool.query = originalQuery;
|
||||
}
|
||||
});
|
||||
|
||||
test('getClientDetailsAnalytics fetches only the tokenized client and period rows', async () => {
|
||||
const originalQuery = pool.query;
|
||||
const calls = [];
|
||||
|
||||
Reference in New Issue
Block a user