"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const moment_1 = tslib_1.__importDefault(require("moment"));
const _1 = require(".");
const index_mock_1 = require("./index.mock");
describe('Common index', () => {
    describe('default values on filter rule', () => {
        // TODO mock some timezones
        test('should return right default day value', async () => {
            const date = (0, moment_1.default)().format('YYYY-MM-DD');
            expect((0, _1.getFilterRuleFromFieldWithDefaultValue)(index_mock_1.dateDayDimension, index_mock_1.emptyValueFilter, undefined).values).toEqual([date]);
        });
        test('should return right default month value', async () => {
            const date = (0, moment_1.default)().format('YYYY-MM-01');
            expect((0, _1.getFilterRuleFromFieldWithDefaultValue)(index_mock_1.dateMonthDimension, index_mock_1.emptyValueFilter, undefined).values).toEqual([date]);
        });
        test('should return right default year value', async () => {
            const date = (0, moment_1.default)().format('YYYY-01-01');
            expect((0, _1.getFilterRuleFromFieldWithDefaultValue)(index_mock_1.dateYearDimension, index_mock_1.emptyValueFilter, undefined).values).toEqual([date]);
        });
    });
    describe('filter rule with default values', () => {
        test('should return with undefined values', async () => {
            expect((0, _1.getFilterRuleFromFieldWithDefaultValue)(index_mock_1.stringDimension, index_mock_1.emptyValueFilter, undefined).values).toEqual([]);
        });
        test('should return with empty values', async () => {
            expect((0, _1.getFilterRuleFromFieldWithDefaultValue)(index_mock_1.stringDimension, index_mock_1.emptyValueFilter, []).values).toEqual([]);
        });
        test('should return single value', async () => {
            expect((0, _1.getFilterRuleFromFieldWithDefaultValue)(index_mock_1.stringDimension, index_mock_1.emptyValueFilter, ['test']).values).toEqual(['test']);
        });
        test('should return multiple values', async () => {
            expect((0, _1.getFilterRuleFromFieldWithDefaultValue)(index_mock_1.stringDimension, index_mock_1.emptyValueFilter, ['test1', 'test2']).values).toEqual(['test1', 'test2']);
        });
    });
});
describe('Password Validation', () => {
    test('valid password', () => {
        const validPasswords = [
            'Lightdash1!',
            'Light@123',
            '#@#@#dash123',
            'light_dash',
        ];
        validPasswords.forEach((password) => {
            const result = (0, _1.getPasswordSchema)().safeParse(password);
            expect(result.success).toBe(true);
        });
    });
    test('password missing letter', () => {
        const passwords = ['12345678!', '@$%^&*()123'];
        passwords.forEach((password) => {
            const result = (0, _1.getPasswordSchema)().safeParse(password);
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.errors[0].message).toBe('must contain a letter');
            }
        });
    });
    test('password missing number or symbol', () => {
        const passwords = ['PasswordOnlyLetters', 'AnotherPassword'];
        passwords.forEach((password) => {
            const result = (0, _1.getPasswordSchema)().safeParse(password);
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.errors[0].message).toBe('must contain a number or symbol');
            }
        });
    });
    test('password too short', () => {
        const invalidPasswords = ['short', 'only', '1234'];
        invalidPasswords.forEach((password) => {
            const result = (0, _1.getPasswordSchema)().safeParse(password);
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.errors[0].message).toBe('must be at least 8 characters long');
            }
        });
    });
});
describe('getDateGroupLabel', () => {
    test('returns undefined if not a date dimension', () => {
        expect((0, _1.getDateGroupLabel)(index_mock_1.stringDimension)).toBeUndefined();
    });
    test('returns undefined if no group', () => {
        expect((0, _1.getDateGroupLabel)(index_mock_1.dateDayDimension)).toBeUndefined();
    });
    test('removes time interval from end of label', () => {
        expect((0, _1.getDateGroupLabel)(index_mock_1.dateDayDimensionWithGroup)).toEqual('date');
        expect((0, _1.getDateGroupLabel)({
            ...index_mock_1.dateDayDimensionWithGroup,
            label: 'month dayday month date year day',
        })).toEqual('month dayday month date year'); // only replaces time frame at the end of string
    });
    test('returns friendly label if it cant recognise time interval', () => {
        expect((0, _1.getDateGroupLabel)({
            ...index_mock_1.dateDayDimensionWithGroup,
            label: 'day date (day)',
        })).toEqual('Day date day'); // doesn't recognize (day) as a valid time frame
    });
});
describe('email validation', () => {
    test.each([
        'demo@lightdash.com',
        'de.mo@lightdash.com',
        'Demo@lightdash.com',
        'user+tag@domain.co.uk',
        'user@sub.domain.com',
        'user@domain.info',
        'user123@domain.org',
        "o'brien@company.com",
    ])('valid email: %s', (email) => {
        expect((0, _1.isValidEmailAddress)(email)).toBe(true);
    });
    test.each([
        ['demo@lightdash', 'Missing top-level domain'],
        ['de mo@lightdash.com', 'Whitespace in email'],
        ['demo@lightdash..com', 'Double dot in domain'],
        ['@lightdash.com', 'Missing local part'],
        ['demo@.com', 'Missing domain name'],
        ['demo@lightdash.c', 'Top-level domain too short'],
    ])('invalid email: %s - %s', (email) => {
        expect((0, _1.isValidEmailAddress)(email)).toBe(false);
    });
});
//# sourceMappingURL=index.test.js.map