"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const periodOverPeriodComparison_1 = require("./periodOverPeriodComparison");
const timeFrames_1 = require("./timeFrames");
describe('periodOverPeriodComparison helpers', () => {
    test('getPopComparisonConfigKey is deterministic for same inputs', () => {
        const a = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        });
        const b = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        });
        expect(a).toEqual(b);
    });
    test('getPopComparisonConfigKey changes when any field changes', () => {
        const base = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        });
        expect((0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 2,
        })).not.toEqual(base);
        expect((0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_week',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        })).not.toEqual(base);
        expect((0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.WEEK,
            periodOffset: 1,
        })).not.toEqual(base);
    });
    test('hashPopComparisonConfigKeyToSuffix is deterministic and fixed length', () => {
        const key = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        });
        const a = (0, periodOverPeriodComparison_1.hashPopComparisonConfigKeyToSuffix)(key);
        const b = (0, periodOverPeriodComparison_1.hashPopComparisonConfigKeyToSuffix)(key);
        expect(a).toEqual(b);
        expect(a).toHaveLength(8);
        expect(a).toMatch(/^[0-9a-z]{8}$/);
    });
    test('hashPopComparisonConfigKeyToSuffix differs for different config keys', () => {
        const k1 = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        });
        const k2 = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 2,
        });
        expect(k1).not.toEqual(k2);
        expect((0, periodOverPeriodComparison_1.hashPopComparisonConfigKeyToSuffix)(k1)).not.toEqual((0, periodOverPeriodComparison_1.hashPopComparisonConfigKeyToSuffix)(k2));
    });
    test('getPopComparisonConfigKey is delimiter-safe (timeDimensionId can contain "|")', () => {
        const normal = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders_order_date_month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        });
        const withPipe = (0, periodOverPeriodComparison_1.getPopComparisonConfigKey)({
            timeDimensionId: 'orders|order_date|month',
            granularity: timeFrames_1.TimeFrames.MONTH,
            periodOffset: 1,
        });
        expect(withPipe).not.toEqual(normal);
    });
});
//# sourceMappingURL=periodOverPeriodComparison.test.js.map