Reapply "Fix RFV period classification"
This reverts commit 28af45c315.
This commit is contained in:
@@ -191,14 +191,14 @@ test('buildRfmClients scores segments from RFM history when period totals are sm
|
||||
assert.equal(yesterdayBuyer.monetaryScore, 3);
|
||||
});
|
||||
|
||||
test('getRfmAnalytics groups period buyers by their RFM tag before the selected period', async () => {
|
||||
test('getRfmAnalytics classifies period buyers by history through the selected range end', async () => {
|
||||
const originalQuery = pool.query;
|
||||
const calls = [];
|
||||
|
||||
pool.query = async (sql, params) => {
|
||||
calls.push({ sql, params });
|
||||
const isHistoryQuery = sql.includes('recency_days');
|
||||
const endDate = params[0];
|
||||
const referenceDate = params[0];
|
||||
|
||||
if (isHistoryQuery) {
|
||||
return {
|
||||
@@ -211,7 +211,7 @@ test('getRfmAnalytics groups period buyers by their RFM tag before the selected
|
||||
frequency: 20,
|
||||
quantity_purchased: 20,
|
||||
last_purchase_date: '2026-06-14',
|
||||
recency_days: endDate === '2026-06-13' ? 0 : 1
|
||||
recency_days: referenceDate === '2026-06-14' ? 0 : 1
|
||||
},
|
||||
{
|
||||
customer_key: '2',
|
||||
@@ -268,9 +268,9 @@ test('getRfmAnalytics groups period buyers by their RFM tag before the selected
|
||||
assert.deepEqual(calls[0].params, ['2026-06-09', '2026-06-15']);
|
||||
assert.match(calls[1].sql, /\(\$1::date - MAX\(data_pedido_date\)\)::int/);
|
||||
assert.match(calls[1].sql, /data_pedido_date <= \$1::date/);
|
||||
assert.deepEqual(calls[1].params, ['2026-06-08']);
|
||||
assert.deepEqual(calls[1].params, ['2026-06-15']);
|
||||
assert.deepEqual(calls[2].params, ['2026-06-14', '2026-06-14']);
|
||||
assert.deepEqual(calls[3].params, ['2026-06-13']);
|
||||
assert.deepEqual(calls[3].params, ['2026-06-14']);
|
||||
assert.equal(sevenDays.clients[0].segmentKey, 'champions');
|
||||
assert.equal(yesterday.clients[0].segmentKey, 'champions');
|
||||
assert.equal(yesterday.clients[0].frequency, 1);
|
||||
|
||||
Reference in New Issue
Block a user