import { describe, it, expect } from 'vitest';
import { parseDashboardView } from './dashboard-view.adapter';

const valid = {
  registration: {
    bigNummer: '19012345601',
    naam: 'Dr. A. de Vries',
    beroep: 'Arts',
    registratiedatum: '2012-09-01',
    geboortedatum: '1985-03-14',
    status: { tag: 'Geregistreerd', herregistratieDatum: '2027-03-01' },
  },
  person: { naam: 'Dr. A. de Vries', geboortedatum: '1985-03-14', adres: { straat: 'X 1', postcode: '2514 EA', woonplaats: 'Den Haag' } },
  decisions: { eligibleForHerregistratie: true, herregistratieReason: 'within window' },
};

describe('parseDashboardView (trust boundary)', () => {
  it('maps a valid response into a DashboardView', () => {
    const r = parseDashboardView(valid);
    expect(r.ok).toBe(true);
    if (r.ok) {
      expect(r.value.profile.registration.bigNummer).toBe('19012345601');
      expect(r.value.decisions.eligibleForHerregistratie).toBe(true);
    }
  });

  it('rejects malformed responses instead of trusting them', () => {
    expect(parseDashboardView(null).ok).toBe(false);
    expect(parseDashboardView({ ...valid, registration: undefined }).ok).toBe(false);
    expect(parseDashboardView({ ...valid, decisions: { eligibleForHerregistratie: 'yes' } }).ok).toBe(false);
  });
});
