"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-useless-escape */
const email_1 = require("./email");
describe('getEmailDomain', () => {
    it('should return the correct domain for a valid email', () => {
        expect((0, email_1.getEmailDomain)('user@example.com')).toBe('example.com');
        expect((0, email_1.getEmailDomain)('another.user@sub.domain.co.uk')).toBe('sub.domain.co.uk');
    });
    it('should convert the domain to lowercase', () => {
        expect((0, email_1.getEmailDomain)('user@EXAMPLE.COM')).toBe('example.com');
        expect((0, email_1.getEmailDomain)('user@Example.Com')).toBe('example.com');
    });
    it('should throw an error for emails containing whitespace', () => {
        expect(() => (0, email_1.getEmailDomain)('user @example.com')).toThrow('Invalid email, contains whitespace');
        expect(() => (0, email_1.getEmailDomain)(' user@example.com')).toThrow('Invalid email, contains whitespace');
        expect(() => (0, email_1.getEmailDomain)('user@example.com ')).toThrow('Invalid email, contains whitespace');
    });
    it('should throw an error for emails without exactly one @ symbol', () => {
        expect(() => (0, email_1.getEmailDomain)('userexample.com')).toThrow('Invalid email');
        expect(() => (0, email_1.getEmailDomain)('user@example@com')).toThrow('Invalid email');
    });
    it('should handle email addresses with special characters in the local part', () => {
        expect((0, email_1.getEmailDomain)('user+tag@example.com')).toBe('example.com');
        expect((0, email_1.getEmailDomain)('user.name@example.com')).toBe('example.com');
        expect((0, email_1.getEmailDomain)('user-name@example.com')).toBe('example.com');
    });
    it('should correctly handle email addresses with multiple @ symbols', () => {
        expect(() => (0, email_1.getEmailDomain)('user@domain.com@example.com')).toThrow('Invalid email');
        expect(() => (0, email_1.getEmailDomain)('"user@domain.com"@example.com')).toThrow('Invalid email');
        expect(() => (0, email_1.getEmailDomain)('"@domain.com@"@example.com')).toThrow('Invalid email');
    });
    it('should not be fooled by attempts to manipulate the domain extraction', () => {
        expect(() => (0, email_1.getEmailDomain)('user@malicious.com@legitimate.org')).toThrow('Invalid email');
        expect(() => (0, email_1.getEmailDomain)('"@organization.com@"@attacker.com')).toThrow('Invalid email');
        expect(() => (0, email_1.getEmailDomain)('user+@company.com@personal.email')).toThrow('Invalid email');
    });
    it('should throw an error for invalid email constructions', () => {
        expect(() => (0, email_1.getEmailDomain)('user@@domain.com')).toThrow('Invalid email');
        expect(() => (0, email_1.getEmailDomain)('@domain.com@')).toThrow('Invalid email');
        expect(() => (0, email_1.getEmailDomain)('user@')).toThrow('Invalid email');
    });
    it('should handle complex but valid email addresses', () => {
        // Unusual email without extra @
        expect((0, email_1.getEmailDomain)('"very.(),:;<>[]".VERY."very\\"very".unusual"@strange.example.com')).toBe('strange.example.com');
        // Unusual email with extra @
        expect(() => (0, email_1.getEmailDomain)('"very.(),:;<>[]".VERY."very@\\"very".unusual"@strange.example.com')).toThrow('Invalid email');
        expect((0, email_1.getEmailDomain)("!#$%&'*+-/=?^_`{}|~@example.org")).toBe('example.org');
    });
});
describe('isPublicEmailProviderDomain', () => {
    it('flags public providers (including former SSO-only entries)', () => {
        expect((0, email_1.isPublicEmailProviderDomain)('gmail.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('outlook.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('icloud.com')).toBe(true);
        // Consolidated from OrganizationSsoService.DISALLOWED_DOMAINS
        expect((0, email_1.isPublicEmailProviderDomain)('google.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('microsoft.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('onmicrosoft.com')).toBe(true);
        // sfr.fr is absent from free-email-domains; kept via the additional
        // list so the swap doesn't regress the old hand-maintained coverage.
        expect((0, email_1.isPublicEmailProviderDomain)('sfr.fr')).toBe(true);
    });
    it('flags providers from the maintained list that the old hand-list missed', () => {
        expect((0, email_1.isPublicEmailProviderDomain)('proton.me')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('protonmail.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('gmx.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('zoho.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('qq.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('163.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('yandex.com')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('fastmail.com')).toBe(true);
    });
    it('is case-insensitive and trims', () => {
        expect((0, email_1.isPublicEmailProviderDomain)('GMAIL.COM')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('  Gmail.com ')).toBe(true);
        expect((0, email_1.isPublicEmailProviderDomain)('  Proton.ME ')).toBe(true);
    });
    it('does not flag corporate domains', () => {
        expect((0, email_1.isPublicEmailProviderDomain)('acme.com')).toBe(false);
        expect((0, email_1.isPublicEmailProviderDomain)('lightdash.com')).toBe(false);
    });
});
describe('validateOrganizationEmailDomains', () => {
    it('returns undefined when all domains are allowed', () => {
        expect((0, email_1.validateOrganizationEmailDomains)(['acme.com', 'acme.io'])).toBeUndefined();
    });
    it('returns an error listing public providers', () => {
        expect((0, email_1.validateOrganizationEmailDomains)(['gmail.com'])).toContain('gmail.com');
        expect((0, email_1.validateOrganizationEmailDomains)(['acme.com', 'outlook.com'])).toContain('outlook.com');
    });
});
//# sourceMappingURL=email.test.js.map