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
Reviewed-on: #97 Reviewed-by: Colby Whitlock <whitlocktech@gmail.com>
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user