import { DyNTS_Cors_Settings } from './cors-settings.interface'; describe('| DyNTS_Cors_Settings', () => { it('| accepts an explicit array allowlist', () => { const s: DyNTS_Cors_Settings = { allowedOrigins: ['https://organizer.futdevpro.hu', 'https://test.organizer.futdevpro.hu'], }; expect(Array.isArray(s.allowedOrigins)).toBe(true); expect((s.allowedOrigins as string[]).length).toBe(2); }); it('| accepts a predicate function', () => { const s: DyNTS_Cors_Settings = { allowedOrigins: (origin: string): boolean => /\.futdevpro\.hu$/.test(origin), }; const fn: (o: string) => boolean = s.allowedOrigins as (o: string) => boolean; expect(fn('https://organizer.futdevpro.hu')).toBe(true); expect(fn('https://attacker.com')).toBe(false); }); it('| accepts wildcard with allowCredentials=false', () => { const s: DyNTS_Cors_Settings = { allowedOrigins: '*', allowCredentials: false, }; expect(s.allowedOrigins).toBe('*'); expect(s.allowCredentials).toBe(false); }); it('| defaults to allowCredentials=true when omitted', () => { // Type-level: omitted is allowed; runtime middleware reads `!== false` and treats as true. const s: DyNTS_Cors_Settings = { allowedOrigins: ['https://example.com'], }; expect(s.allowCredentials).toBeUndefined(); }); it('| supports custom methods + headers + exposed + maxAge', () => { const s: DyNTS_Cors_Settings = { allowedOrigins: ['https://example.com'], allowedMethods: ['GET', 'POST'], allowedHeaders: ['Authorization', 'X-Trace-Id'], exposedHeaders: ['X-Total-Count'], maxAgeSeconds: 3600, }; expect(s.allowedMethods).toEqual(['GET', 'POST']); expect(s.allowedHeaders).toContain('X-Trace-Id'); expect(s.exposedHeaders).toEqual(['X-Total-Count']); expect(s.maxAgeSeconds).toBe(3600); }); });