/* @vitest-environment node */

import { describe, it, expect } from "vitest";
import { mapQsirchItemToSearchItem } from "./pathMapping.js";

describe("lib/search/pathMapping", () => {
	it("maps a valid Qsirch item into our search item format", () => {
		const item = {
			path: "Niederlassungen/NL20/2025/12/18",
			name: "Test_File",
			extension: "pdf",
		};

		const mapped = mapQsirchItemToSearchItem(item, {
			pathPrefix: "/Niederlassungen",
		});

		expect(mapped).toEqual({
			branch: "NL20",
			date: "2025-12-18",
			year: "2025",
			month: "12",
			day: "18",
			filename: "Test_File.pdf",
			relativePath: "NL20/2025/12/18/Test_File.pdf",
		});
	});

	it("rejects unexpected paths outside prefix", () => {
		const item = {
			path: "Public/NL20/2025/12/18",
			name: "Test",
			extension: "pdf",
		};

		expect(
			mapQsirchItemToSearchItem(item, { pathPrefix: "/Niederlassungen" })
		).toBe(null);
	});

	it("rejects paths not matching NLxx/YYYY/MM/DD", () => {
		const item = {
			path: "Niederlassungen/NL20/2025/12",
			name: "Test",
			extension: "pdf",
		};

		expect(
			mapQsirchItemToSearchItem(item, { pathPrefix: "/Niederlassungen" })
		).toBe(null);
	});
});
