"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const field_1 = require("../types/field");
const timeFrames_1 = require("../types/timeFrames");
const normalizeCellRawForFilter_1 = require("./normalizeCellRawForFilter");
const buildTimeIntervalDim = (baseType) => ({
    fieldType: field_1.FieldType.DIMENSION,
    type: field_1.DimensionType.DATE,
    name: 'created_at_month',
    table: 'orders',
    tableLabel: 'Orders',
    label: 'Created at month',
    sql: '',
    hidden: false,
    timeInterval: timeFrames_1.TimeFrames.MONTH,
    timeIntervalBaseDimensionName: 'created_at',
    timeIntervalBaseDimensionType: baseType,
});
const stringDim = {
    fieldType: field_1.FieldType.DIMENSION,
    type: field_1.DimensionType.STRING,
    name: 'status',
    table: 'orders',
    tableLabel: 'Orders',
    label: 'Status',
    sql: '',
    hidden: false,
};
// Paris Nov 2024 — UTC instant emitted by the DATE_TRUNC round-trip on a
// TIMESTAMP-base interval.
const parisNovInstant = '2024-10-31T23:00:00Z';
// DATE interval value (calendar date encoded at UTC midnight).
const dateBaseNov = '2024-11-01T00:00:00Z';
describe('normalizeCellRawForFilter', () => {
    // GLITCH-452: a day-or-coarser TIMESTAMP-base trunc now compiles to a real
    // DATE, so the drilled value is already a calendar date — returned as-is
    // regardless of the project timezone, exactly like a DATE-base interval.
    test('TIMESTAMP-base (GLITCH-452): real DATE returned as-is (positive offset)', () => {
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(dateBaseNov, buildTimeIntervalDim(field_1.DimensionType.TIMESTAMP), 'Europe/Paris')).toBe(dateBaseNov);
    });
    test('TIMESTAMP-base (GLITCH-452): real DATE returned as-is (negative offset)', () => {
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(dateBaseNov, buildTimeIntervalDim(field_1.DimensionType.TIMESTAMP), 'America/New_York')).toBe(dateBaseNov);
    });
    test('DATE-base: negative offset must NOT shift the calendar date back', () => {
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(dateBaseNov, buildTimeIntervalDim(field_1.DimensionType.DATE), 'America/New_York')).toBe(dateBaseNov);
    });
    test('DATE-base: positive offset is left unchanged', () => {
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(dateBaseNov, buildTimeIntervalDim(field_1.DimensionType.DATE), 'Asia/Tokyo')).toBe(dateBaseNov);
    });
    test('non-time-interval dim is left unchanged', () => {
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)('pending', stringDim, 'Europe/Paris')).toBe('pending');
    });
    test('null / undefined raw is returned as-is', () => {
        const field = buildTimeIntervalDim(field_1.DimensionType.TIMESTAMP);
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(null, field, 'Europe/Paris')).toBeNull();
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(undefined, field, 'Europe/Paris')).toBeUndefined();
    });
    test('missing field returns the raw value unchanged', () => {
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(parisNovInstant, undefined, 'Europe/Paris')).toBe(parisNovInstant);
    });
    test('TIMESTAMP-base with no timezone returns raw value unchanged', () => {
        expect((0, normalizeCellRawForFilter_1.normalizeCellRawForFilter)(parisNovInstant, buildTimeIntervalDim(field_1.DimensionType.TIMESTAMP), undefined)).toBe(parisNovInstant);
    });
});
//# sourceMappingURL=normalizeCellRawForFilter.test.js.map