feat: add backend analytics endpoints
This commit is contained in:
34
backend/test/analyticsService.test.js
Normal file
34
backend/test/analyticsService.test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const test = require('node:test');
|
||||
|
||||
const { buildDateFilter, normalizeDateParam } = require('../services/analyticsService');
|
||||
|
||||
test('normalizeDateParam accepts strict ISO dates', () => {
|
||||
assert.equal(normalizeDateParam('2026-05-28'), '2026-05-28');
|
||||
});
|
||||
|
||||
test('normalizeDateParam rejects non-ISO or impossible dates', () => {
|
||||
assert.equal(normalizeDateParam('28/05/2026'), null);
|
||||
assert.equal(normalizeDateParam('2026-02-31'), null);
|
||||
assert.equal(normalizeDateParam(''), null);
|
||||
});
|
||||
|
||||
test('buildDateFilter builds bounded date predicates', () => {
|
||||
const filter = buildDateFilter({ start: '2026-05-01', end: '2026-05-28' });
|
||||
|
||||
assert.deepEqual(filter.params, ['2026-05-01', '2026-05-28']);
|
||||
assert.equal(
|
||||
filter.whereClause,
|
||||
'WHERE data_pedido_date IS NOT NULL AND data_pedido_date >= $1::date AND data_pedido_date <= $2::date'
|
||||
);
|
||||
});
|
||||
|
||||
test('buildDateFilter ignores invalid bounds', () => {
|
||||
const filter = buildDateFilter({ start: 'invalid', end: '2026-05-28' });
|
||||
|
||||
assert.deepEqual(filter.params, ['2026-05-28']);
|
||||
assert.equal(
|
||||
filter.whereClause,
|
||||
'WHERE data_pedido_date IS NOT NULL AND data_pedido_date <= $1::date'
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user