"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("../types/errors");
const loadLightdashProjectConfig_1 = require("./loadLightdashProjectConfig");
const loadLightdashProjectConfig_mock_1 = require("./loadLightdashProjectConfig.mock");
describe('loadLightdashProjectConfig', () => {
    it('should load an empty config', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.emptyConfig);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
        });
    });
    it('should load a valid config with parameters', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithParameters);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                test_param: {
                    label: 'Test Parameter',
                    options: ['option1', 'option2'],
                },
            },
        });
    });
    it('should load a valid config with parameters using options_from_dimension', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithOptionsFromDimension);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                test_param: {
                    label: 'Test Parameter',
                    options_from_dimension: {
                        model: 'test_model',
                        dimension: 'test_dimension',
                    },
                },
            },
        });
    });
    it('should load a valid config with parameters using allow_custom_values', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithAllowCustomValues);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                test_param: {
                    label: 'Test Parameter',
                    allow_custom_values: true,
                },
            },
        });
    });
    it('should throw an error for invalid parameter with no options', async () => {
        await expect((0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.invalidConfigWithNoOptions)).rejects.toThrow(errors_1.ParseError);
    });
    it('should throw an error for invalid parameter with allow_custom_values set to false', async () => {
        await expect((0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.invalidConfigWithAllowCustomValuesFalse)).rejects.toThrow(errors_1.ParseError);
    });
    it('should throw an error for parameter with empty options array', async () => {
        await expect((0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.configWithEmptyOptionsArray)).rejects.toThrow(errors_1.ParseError);
    });
    it('should throw an error for invalid parameter with incomplete options_from_dimension', async () => {
        await expect((0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.invalidConfigWithIncompleteOptionsFromDimension)).rejects.toThrow(errors_1.ParseError);
    });
    it('should load a valid config with number parameter', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithNumberParameter);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                customer_id: {
                    label: 'Customer ID',
                    type: 'number',
                    default: 100,
                    options: [100, 200, 300],
                },
            },
        });
    });
    it('should load a valid config with number array parameter', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithNumberArrayParameter);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                product_ids: {
                    label: 'Product IDs',
                    type: 'number',
                    multiple: true,
                    default: [1, 2, 3],
                    options: [1, 2, 3, 4, 5],
                },
            },
        });
    });
    it('should load a valid config with explicit string type', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithStringTypeExplicit);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                status: {
                    label: 'Status',
                    type: 'string',
                    default: 'active',
                    options: ['active', 'inactive', 'pending'],
                },
            },
        });
    });
    it('should load a valid config with string array parameter', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithMixedArrayTypes);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                customer_name: {
                    label: 'Customer Name',
                    type: 'string',
                    multiple: true,
                    default: ['John', 'Jane'],
                    options: ['John', 'Jane', 'Bob', 'Alice'],
                },
            },
        });
    });
    it('should load a valid config with date parameter', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithDateParameter);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                start_date: {
                    label: 'Start Date',
                    type: 'date',
                    default: '2025-08-06',
                    options: ['2025-08-06', '2025-08-07', '2025-08-08'],
                },
            },
        });
    });
    it('should load a valid config with date parameter using options_from_dimension', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithDateParameterFromDimension);
        expect(config).toEqual({
            spotlight: {
                default_visibility: 'show',
            },
            parameters: {
                order_date: {
                    label: 'Order Date',
                    type: 'date',
                    options_from_dimension: {
                        model: 'orders',
                        dimension: 'order_date',
                    },
                },
            },
        });
    });
    it('should load config with custom_granularities', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithCustomGranularities);
        expect(config.custom_granularities).toBeDefined();
        expect(config.custom_granularities.slt_week.label).toBe('SLT Week');
        expect(config.custom_granularities.slt_week.type).toBeUndefined();
        expect(config.custom_granularities.fiscal_quarter.type).toBe('string');
    });
    it('should reject custom_granularity without sql', async () => {
        await expect((0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.invalidConfigCustomGranularityNoSql)).rejects.toThrow(errors_1.ParseError);
    });
    it('should reject custom_granularity without label', async () => {
        await expect((0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.invalidConfigCustomGranularityNoLabel)).rejects.toThrow(errors_1.ParseError);
    });
    it('should reject custom_granularity that conflicts with standard TimeFrames', async () => {
        const promise = (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.invalidConfigCustomGranularityConflictsWithTimeFrames);
        await expect(promise).rejects.toThrow(errors_1.LightdashProjectConfigError);
        await expect(promise).rejects.toThrow(/conflict.*standard time intervals/i);
    });
    it('should load config without custom_granularities', async () => {
        const config = await (0, loadLightdashProjectConfig_1.loadLightdashProjectConfig)(loadLightdashProjectConfig_mock_1.validConfigWithoutCustomGranularities);
        expect(config.custom_granularities).toBeUndefined();
    });
});
//# sourceMappingURL=loadLightdashProjectConfig.test.js.map