import { describe, expect, test } from "vitest";
import { buildAppJumpParam, parseAppJumpParam, validatePublicAppJumpParam } from "@/shared/app-jump/appJumpConfig.js";

describe("public app jump config", () => {
    test("builds and parses room window jump", () => {
        const param = buildAppJumpParam({
            giftId: "gift_9",
            roomId: "room_1",
            target: "room_window",
            window: "gift_panel",
        });

        expect(param).toBe('{"type":"room_window","room_id":"room_1","window":"gift_panel","gift_id":"gift_9"}');
        expect(parseAppJumpParam(param)).toMatchObject({
            giftId: "gift_9",
            roomId: "room_1",
            target: "room_window",
            window: "gift_panel",
        });
    });

    test("validates required fields for public app jumps", () => {
        expect(validatePublicAppJumpParam('{"type":"wallet"}').valid).toBe(true);
        expect(validatePublicAppJumpParam('{"type":"room_game","room_id":"room_1","game_id":"dice"}').valid).toBe(true);
        expect(validatePublicAppJumpParam('{"type":"explore_game","game_code":"game_rock"}').valid).toBe(true);
        expect(validatePublicAppJumpParam('{"type":"room_game","room_id":"room_1"}')).toMatchObject({
            valid: false,
        });
        expect(validatePublicAppJumpParam('{"type":"room_window","room_id":"room_1"}')).toMatchObject({
            valid: false,
        });
        expect(validatePublicAppJumpParam('{"type":"explore_game","game_code":"unknown"}')).toMatchObject({
            valid: false,
        });
        expect(validatePublicAppJumpParam("not json")).toMatchObject({ valid: false });
    });

    test("builds and parses explore game jump", () => {
        const param = buildAppJumpParam({
            gameCode: "game_dice",
            target: "explore_game",
        });

        expect(param).toBe('{"type":"explore_game","game_code":"game_dice"}');
        expect(parseAppJumpParam(param)).toMatchObject({
            gameCode: "game_dice",
            target: "explore_game",
        });
    });
});
