unrip/test/history-writer-refresh-policy.test.mjs
philipp 4adc705a2b
Some checks failed
deploy / deploy (push) Failing after 34s
Use bridge deposit time for funding activity
Proof: npm test (147 passing); npm run operator-dashboard:build; git diff --cached --check.

Assumptions: Bridge recent_deposits created_at is the authoritative source time for deposit activity; rows without created_at must be deduped to their earliest observed status instead of the latest replay ingestion.

Still fake: No fund movement or bridge migration was performed; ntfy messages already sent before this fix cannot be unsent.
2026-05-07 16:47:52 +02:00

58 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { shouldRunDerivedRefreshForEvent } from '../src/core/history-writer-refresh-policy.mjs';
test('history writer derived refresh policy skips stale replayed events', () => {
assert.equal(shouldRunDerivedRefreshForEvent({
event: {
ingested_at: '2026-05-05T07:56:03.203Z',
},
now: '2026-05-07T14:12:00.000Z',
maxEventAgeMs: 300000,
}), false);
});
test('history writer derived refresh policy runs for fresh and undated events', () => {
assert.equal(shouldRunDerivedRefreshForEvent({
event: {
ingested_at: '2026-05-07T14:11:52.729Z',
},
now: '2026-05-07T14:12:00.000Z',
maxEventAgeMs: 300000,
}), true);
assert.equal(shouldRunDerivedRefreshForEvent({
event: {},
now: '2026-05-07T14:12:00.000Z',
maxEventAgeMs: 300000,
}), true);
});
test('history writer derived refresh policy skips events outside request freshness window', () => {
assert.equal(shouldRunDerivedRefreshForEvent({
event: {
ingested_at: '2026-05-07T14:11:20.000Z',
},
now: '2026-05-07T14:12:00.000Z',
maxEventAgeMs: 30000,
}), false);
assert.equal(shouldRunDerivedRefreshForEvent({
event: {
ingested_at: '2026-05-07T14:11:45.000Z',
},
now: '2026-05-07T14:12:00.000Z',
maxEventAgeMs: 30000,
}), true);
});
test('history writer derived refresh policy prefers source observed time over replay ingestion time', () => {
assert.equal(shouldRunDerivedRefreshForEvent({
event: {
observed_at: '2026-04-07T15:20:19.909Z',
ingested_at: '2026-05-07T14:07:23.119Z',
},
now: '2026-05-07T14:07:24.000Z',
maxEventAgeMs: 30000,
}), false);
});