import { describe, expect, it } from 'vitest'; import { isOnOrBeforeVisibleDate, throughVisibleDate } from '../visibility.ts'; describe('throughVisibleDate', () => { const rows = [{ date: '2026-09-05' }, { date: '2026-09-06' }, { date: '2026-09-07' }]; it('drops rows after the publish cutoff', () => { expect(throughVisibleDate(rows, '2026-09-06')).toEqual([ { date: '2026-09-05' }, { date: '2026-09-06' }, ]); }); it('returns all rows when cutoff is missing', () => { expect(throughVisibleDate(rows, undefined)).toEqual(rows); expect(throughVisibleDate(rows, null)).toEqual(rows); }); }); describe('isOnOrBeforeVisibleDate', () => { it('rejects dates after the cutoff', () => { expect(isOnOrBeforeVisibleDate('2026-09-07', '2026-09-06')).toBe(false); }); it('accepts dates on or before the cutoff', () => { expect(isOnOrBeforeVisibleDate('2026-09-06', '2026-09-06')).toBe(true); expect(isOnOrBeforeVisibleDate('2026-09-05', '2026-09-06')).toBe(true); }); it('rejects empty dates', () => { expect(isOnOrBeforeVisibleDate(null, '2026-09-06')).toBe(false); expect(isOnOrBeforeVisibleDate(undefined, '2026-09-06')).toBe(false); }); });