/* @vitest-environment node */

import { describe, it, expect } from "vitest";
import { buildDatePresets, DATE_PRESET_KEY } from "./datePresets.js";

describe("lib/frontend/search/datePresets", () => {
	it("builds stable ISO ranges for a fixed date", () => {
		const now = new Date(2026, 0, 15); // 2026-01-15 (local)
		const presets = buildDatePresets({ now });

		const byKey = Object.fromEntries(presets.map((p) => [p.key, p]));

		expect(byKey[DATE_PRESET_KEY.TODAY]).toMatchObject({
			from: "2026-01-15",
			to: "2026-01-15",
		});

		expect(byKey[DATE_PRESET_KEY.YESTERDAY]).toMatchObject({
			from: "2026-01-14",
			to: "2026-01-14",
		});

		expect(byKey[DATE_PRESET_KEY.LAST_7_DAYS]).toMatchObject({
			from: "2026-01-09",
			to: "2026-01-15",
		});

		expect(byKey[DATE_PRESET_KEY.THIS_MONTH]).toMatchObject({
			from: "2026-01-01",
			to: "2026-01-15",
		});

		expect(byKey[DATE_PRESET_KEY.LAST_MONTH]).toMatchObject({
			from: "2025-12-01",
			to: "2025-12-31",
		});

		expect(byKey[DATE_PRESET_KEY.THIS_YEAR]).toMatchObject({
			from: "2026-01-01",
			to: "2026-01-15",
		});
	});
});
