import { describe, it, expect } from 'vitest'; import { parseMe } from './me.adapter'; describe('parseMe (trust boundary)', () => { it('parses a known capability list', () => { const r = parseMe({ capabilities: ['brief:approve', 'brief:reject', 'brief:send'] }); expect(r).toEqual({ ok: true, value: ['brief:approve', 'brief:reject', 'brief:send'] }); }); it('parses an empty list (drafter — no capabilities)', () => { expect(parseMe({ capabilities: [] })).toEqual({ ok: true, value: [] }); }); it('recognizes the admin org-template capability (WP-23)', () => { expect(parseMe({ capabilities: ['orgtemplate:edit'] })).toEqual({ ok: true, value: ['orgtemplate:edit'], }); }); // Regression: WP-66's `aanvraag:beoordelen` (behandelportal) shipped on the `Capability` // type but was never added to this trust-boundary's runtime KNOWN list, so a real // behandelaar's `/me` response had the capability silently dropped and the werkvoorraad // page always denied — every `Capability` union member belongs in KNOWN too. it('recognizes the behandelportal besluit capability (WP-66)', () => { expect(parseMe({ capabilities: ['aanvraag:beoordelen'] })).toEqual({ ok: true, value: ['aanvraag:beoordelen'], }); }); it('drops unrecognized capability strings instead of rejecting the response', () => { const r = parseMe({ capabilities: ['brief:approve', 'unknown:future-thing'] }); expect(r).toEqual({ ok: true, value: ['brief:approve'] }); }); it('rejects malformed responses instead of trusting them', () => { expect(parseMe(null).ok).toBe(false); expect(parseMe({}).ok).toBe(false); expect(parseMe({ capabilities: 'brief:approve' }).ok).toBe(false); }); });