import { randomUUID } from 'node:crypto'; import { consentSchema } from '../src/messaging/consent.schemas'; it('requires explicit supported terms and permits withdrawal without agreeing to a notice', () => { const grant = { channel: 'EMAIL', purpose: 'PROMOTIONS', granted: true, version: 0, noticeVersion: '2026-10-07', idempotencyKey: randomUUID(), }; expect(consentSchema.safeParse(grant).success).toBe(true); expect( consentSchema.safeParse({ ...grant, granted: false, noticeVersion: undefined, }).success, ).toBe(true); for (const override of [ { granted: 'true' }, { noticeVersion: undefined }, { granted: false }, { channel: 'SMS' }, { purpose: 'ALL' }, { version: -1 }, { version: 2147483647 }, { userId: randomUUID() }, ]) { expect(consentSchema.safeParse({ ...grant, ...override }).success).toBe( false, ); } });