import { tbankSourceNeedsRefresh, tbankSourceTtlMs, } from './tbank-source.policy'; describe('mutable source freshness', () => { it.each(Object.keys(tbankSourceTtlMs) as (keyof typeof tbankSourceTtlMs)[])( '%s expires at its boundary without changing source time', (source) => { const fetchedAt = new Date('2026-09-01Z'); // eslint-disable-next-line security/detect-object-injection -- The key comes from the local source-policy test table. const ttl = tbankSourceTtlMs[source]; expect( tbankSourceNeedsRefresh( source, fetchedAt, new Date(fetchedAt.valueOf() + ttl - 1000), ), ).toBe(false); expect( tbankSourceNeedsRefresh( source, fetchedAt, new Date(fetchedAt.valueOf() + ttl), ), ).toBe(true); expect(tbankSourceNeedsRefresh(source, fetchedAt, fetchedAt, true)).toBe( true, ); expect(tbankSourceNeedsRefresh(source, null, fetchedAt)).toBe(true); expect(fetchedAt.toISOString()).toBe('2026-09-01T00:00:00.000Z'); }, ); });