"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const dbt_1 = require("../types/dbt");
const field_1 = require("../types/field");
const timeFrames_1 = require("../types/timeFrames");
const timeFrames_2 = require("./timeFrames");
describe('TimeFrames', () => {
    describe('getSqlForTruncatedDate', () => {
        test('should get sql where stat of the week is Wednesday', async () => {
            expect(timeFrames_2.timeFrameConfigs[timeFrames_1.TimeFrames.WEEK].getSql(dbt_1.SupportedDbtAdapter.POSTGRES, timeFrames_1.TimeFrames.WEEK, '${TABLE}.created', field_1.DimensionType.TIMESTAMP, timeFrames_2.WeekDay.WEDNESDAY)).toEqual("(DATE_TRUNC('WEEK', (${TABLE}.created - interval '2 days')) + interval '2 days')");
            expect(timeFrames_2.timeFrameConfigs[timeFrames_1.TimeFrames.WEEK].getSql(dbt_1.SupportedDbtAdapter.REDSHIFT, timeFrames_1.TimeFrames.WEEK, '${TABLE}.created', field_1.DimensionType.TIMESTAMP, timeFrames_2.WeekDay.WEDNESDAY)).toEqual("(DATE_TRUNC('WEEK', (${TABLE}.created - interval '2 days')) + interval '2 days')");
            expect(timeFrames_2.timeFrameConfigs[timeFrames_1.TimeFrames.WEEK].getSql(dbt_1.SupportedDbtAdapter.BIGQUERY, timeFrames_1.TimeFrames.WEEK, '${TABLE}.created', field_1.DimensionType.TIMESTAMP, timeFrames_2.WeekDay.WEDNESDAY)).toEqual('TIMESTAMP_TRUNC(${TABLE}.created, WEEK(WEDNESDAY))');
            expect(timeFrames_2.timeFrameConfigs[timeFrames_1.TimeFrames.WEEK].getSql(dbt_1.SupportedDbtAdapter.DATABRICKS, timeFrames_1.TimeFrames.WEEK, '${TABLE}.created', field_1.DimensionType.TIMESTAMP, timeFrames_2.WeekDay.WEDNESDAY)).toEqual("DATEADD(DAY, 2, DATE_TRUNC('WEEK', DATEADD(DAY, -2, ${TABLE}.created)))");
            expect(timeFrames_2.timeFrameConfigs[timeFrames_1.TimeFrames.WEEK].getSql(dbt_1.SupportedDbtAdapter.SNOWFLAKE, timeFrames_1.TimeFrames.WEEK, '${TABLE}.created', field_1.DimensionType.TIMESTAMP, timeFrames_2.WeekDay.WEDNESDAY)).toEqual("DATE_TRUNC('WEEK', ${TABLE}.created)");
        });
    });
    describe('getDateDimension', () => {
        test('should parse dates', async () => {
            // Invalid date granularities
            expect((0, timeFrames_2.getDateDimension)('dimension_hour')).toEqual({});
            expect((0, timeFrames_2.getDateDimension)('dimension')).toEqual({});
            expect((0, timeFrames_2.getDateDimension)('dimension_date')).toEqual({});
            expect((0, timeFrames_2.getDateDimension)('dimension_raw')).toEqual({});
            // Valid date granularities
            expect((0, timeFrames_2.getDateDimension)('dimension_day')).toEqual({
                baseDimensionId: `dimension`,
                newTimeFrame: timeFrames_1.TimeFrames.DAY,
            });
            expect((0, timeFrames_2.getDateDimension)('table_my_dimension_day')).toEqual({
                baseDimensionId: `table_my_dimension`,
                newTimeFrame: timeFrames_1.TimeFrames.DAY,
            });
            expect((0, timeFrames_2.getDateDimension)('dimension_week')).toEqual({
                baseDimensionId: `dimension`,
                newTimeFrame: timeFrames_1.TimeFrames.WEEK,
            });
            expect((0, timeFrames_2.getDateDimension)('dimension_month')).toEqual({
                baseDimensionId: `dimension`,
                newTimeFrame: timeFrames_1.TimeFrames.MONTH,
            });
            expect((0, timeFrames_2.getDateDimension)('dimension_quarter')).toEqual({
                baseDimensionId: `dimension`,
                newTimeFrame: timeFrames_1.TimeFrames.QUARTER,
            });
            expect((0, timeFrames_2.getDateDimension)('dimension_year')).toEqual({
                baseDimensionId: `dimension`,
                newTimeFrame: timeFrames_1.TimeFrames.YEAR,
            });
        });
    });
});
//# sourceMappingURL=timeFrames.test.js.map