Merge pull request 'fix(moderation): windowValue must not fall back to the 30d total on a null column' (#97) from fix/window-value-null-column into main
All checks were successful
Build container images / build (push) Successful in 54s
Build container images / deploy (push) Successful in 36s
SonarQube / analysis (push) Successful in 2m27s

Reviewed-on: #97
Reviewed-by: Colby Whitlock <whitlocktech@gmail.com>
This commit is contained in:
2026-07-22 18:15:46 +00:00
2 changed files with 10 additions and 1 deletions

View File

@@ -40,7 +40,7 @@ function reshapeWindows(rows) {
// { d1, d7, d30 } sum row, coercing to a number and tolerating a null row. // { d1, d7, d30 } sum row, coercing to a number and tolerating a null row.
function windowValue(row, key) { function windowValue(row, key) {
if (!row) return 0 if (!row) return 0
const col = { '24h': row.d1, '7d': row.d7 }[key] ?? row.d30 const col = { '24h': row.d1, '7d': row.d7, '30d': row.d30 }[key]
return Number(col) || 0 return Number(col) || 0
} }

View File

@@ -87,3 +87,12 @@ test('windowValue: null row (no rows in window) yields 0', () => {
test('windowValue: null sum column yields 0', () => { test('windowValue: null sum column yields 0', () => {
assert.strictEqual(moderation.windowValue({ d1: null, d7: null, d30: null }, '7d'), 0) assert.strictEqual(moderation.windowValue({ d1: null, d7: null, d30: null }, '7d'), 0)
}) })
test('windowValue: a null narrow-window column never falls back to the 30d total', () => {
// Regression: an earlier rewrite used `{...}[key] ?? row.d30`, so a null d1/d7
// returned the 30-day count instead of 0 — inflating the 24h/7d tiles.
const row = { d1: null, d7: null, d30: 5 }
assert.strictEqual(moderation.windowValue(row, '24h'), 0)
assert.strictEqual(moderation.windowValue(row, '7d'), 0)
assert.strictEqual(moderation.windowValue(row, '30d'), 5)
})