import { describe, it, expect } from 'vitest'; import { isAuthenticated, parseStoredSession, Session } from './session'; const session: Session = { bsn: '19012345601', naam: 'Test' }; describe('isAuthenticated', () => { it('narrows a present session to Session', () => { expect(isAuthenticated(session)).toBe(true); }); it('reports no session as not authenticated', () => { expect(isAuthenticated(null)).toBe(false); }); }); describe('parseStoredSession', () => { it('returns null when nothing is stored', () => { expect(parseStoredSession(null)).toBeNull(); }); it('returns null for a non-JSON string', () => { expect(parseStoredSession('not json')).toBeNull(); }); it('returns null when the stored shape is wrong (no naam)', () => { expect(parseStoredSession(JSON.stringify({ bsn: '19012345601' }))).toBeNull(); }); it('G1: a stored bsn is never restored, even if present in the raw value', () => { const restored = parseStoredSession(JSON.stringify({ bsn: '19012345601', naam: 'Test' })); expect(restored).toEqual({ bsn: '', naam: 'Test' }); }); });