import { describe, it, expect } from "vitest";
import { transformScoresAPIResponse } from "./index";
describe("transformScoresAPIResponse", () => {
    it("returns an empty object if data or scoresMenu is undefined", () => {
        // @ts-expect-error-next-line
        const result = transformScoresAPIResponse(undefined, undefined);
        expect(result).toEqual({});
    });
    it("transforms scores correctly from API response", () => {
        const data = {
            location: {
                shopping: { value: 5, text: "Shopping" },
                pedestrian_friendly: { value: 3, text: "Pedestrian friendly" },
            },
            geographies: [
                {
                    geog_id: "g10_1",
                },
                {
                    geog_id: "g30_2",
                    name: "G30 Score",
                    scores: { shopping: { value: 4 }, pedestrian_friendly: { value: 2 } },
                },
            ],
        };
        const scoresMenu = {
            categories: [
                ["amenities", { scores: [["shopping", {}]] }],
                ["transport", { scores: [["pedestrian_friendly", {}]] }],
            ],
        };
        // @ts-expect-error-next-line
        const result = transformScoresAPIResponse(data, scoresMenu);
        expect(result).toEqual({
            shopping: {
                text: "Shopping",
                value: 10,
                geographies: {
                    g30: { text: "G30 Score", value: 8 },
                },
                categoryKey: "amenities",
                categoryOptions: { scores: [["shopping", {}]] },
            },
            pedestrian_friendly: {
                text: "Pedestrian friendly",
                value: 6,
                geographies: {
                    g30: { text: "G30 Score", value: 4 },
                },
                categoryKey: "transport",
                categoryOptions: { scores: [["pedestrian_friendly", {}]] },
            },
        });
    });
    it("handles missing scores gracefully", () => {
        const data = { location: {}, geographies: [{}, {}] };
        const scoresMenu = { categories: [] };
        // @ts-expect-error-next-line
        const result = transformScoresAPIResponse(data, scoresMenu);
        expect(result).toEqual({});
    });
    it("includes categoryKey and categoryOptions in each score item", () => {
        const data = {
            location: { pedestrian_friendly: { value: 5 } },
            geographies: [{}, {}],
        };
        const scoresMenu = {
            categories: [
                ["transport", { scores: [["pedestrian_friendly", {}]], order: 1 }],
            ],
        };
        // @ts-expect-error-next-line
        const result = transformScoresAPIResponse(data, scoresMenu);
        expect(result.pedestrian_friendly.categoryKey).toBe("transport");
        expect(result.pedestrian_friendly.categoryOptions).toEqual({
            scores: [["pedestrian_friendly", {}]],
            order: 1,
        });
    });
});
//# sourceMappingURL=index.test.js.map