import { describe, it, expect } from 'vitest'; import { makeInitialReviewRows } from '../src/lib/reviews.ts'; describe('makeInitialReviewRows', () => { it('creates one row per subIndex', () => { const now = new Date('2025-01-01T00:00:00Z'); const rows = makeInitialReviewRows({ userId: 'u-1', cardId: 'c-1', subIndices: [0, 1, 2], now, }); expect(rows).toHaveLength(3); expect(rows[0].subIndex).toBe(0); expect(rows[1].subIndex).toBe(1); expect(rows[2].subIndex).toBe(2); }); it('sets correct userId and cardId on each row', () => { const now = new Date(); const rows = makeInitialReviewRows({ userId: 'u-test', cardId: 'c-test', subIndices: [0], now, }); expect(rows[0].userId).toBe('u-test'); expect(rows[0].cardId).toBe('c-test'); }); it('returns empty array for empty subIndices', () => { const rows = makeInitialReviewRows({ userId: 'u-1', cardId: 'c-1', subIndices: [], now: new Date(), }); expect(rows).toHaveLength(0); }); it('initial state has reps=0 and lapses=0', () => { const rows = makeInitialReviewRows({ userId: 'u-1', cardId: 'c-1', subIndices: [0], now: new Date(), }); expect(rows[0].reps).toBe(0); expect(rows[0].lapses).toBe(0); }); it('due date is a Date instance', () => { const now = new Date(); const rows = makeInitialReviewRows({ userId: 'u-1', cardId: 'c-1', subIndices: [0], now, }); expect(rows[0].due).toBeInstanceOf(Date); }); });