campaign-creator-tui/tools/lib/mission-markdown_test.ts

91 lines
2.6 KiB
TypeScript

import { assertEquals } from "@std/assert";
import {
buildBeatLeaderUrlFromLeaderboard,
buildBeatSaverUrl,
extractLeaderboardId,
pickLeaderboardForMission,
pickPreferredLeaderboard,
} from "./mission-markdown.ts";
Deno.test("buildBeatSaverUrl uses map key when songid present", () => {
assertEquals(buildBeatSaverUrl("abc123", undefined), "https://beatsaver.com/maps/abc123");
});
Deno.test("buildBeatSaverUrl falls back to hash search", () => {
const h = "a".repeat(40);
assertEquals(
buildBeatSaverUrl(undefined, h),
`https://beatsaver.com/search/hash/${h}`,
);
});
Deno.test("buildBeatSaverUrl returns null without key or hash", () => {
assertEquals(buildBeatSaverUrl(undefined, undefined), null);
assertEquals(buildBeatSaverUrl("", "not-a-hash"), null);
});
Deno.test("extractLeaderboardId reads camelCase and PascalCase", () => {
assertEquals(extractLeaderboardId({ id: 42 }), "42");
assertEquals(extractLeaderboardId({ leaderboardId: "x" }), "x");
assertEquals(extractLeaderboardId({ Id: "y" }), "y");
assertEquals(extractLeaderboardId({ LeaderboardId: "z" }), "z");
assertEquals(extractLeaderboardId({}), null);
});
Deno.test("buildBeatLeaderUrlFromLeaderboard prefers global id", () => {
assertEquals(
buildBeatLeaderUrlFromLeaderboard({ id: "99" }, "deadbeef"),
"https://beatleader.com/leaderboard/global/99",
);
});
Deno.test("buildBeatLeaderUrlFromLeaderboard search fallback uses hash", () => {
assertEquals(
buildBeatLeaderUrlFromLeaderboard(null, "abc"),
"https://beatleader.com/leaderboards?search=abc",
);
});
Deno.test("pickLeaderboardForMission prefers exact characteristic+difficulty", () => {
const lbs = [
{
id: "1",
difficulty: {
modeName: "Standard",
difficultyName: "Expert",
},
},
{
id: "2",
difficulty: {
modeName: "Standard",
difficultyName: "ExpertPlus",
},
},
{
id: "3",
difficulty: {
modeName: "OneSaber",
difficultyName: "ExpertPlus",
},
},
];
const picked = pickLeaderboardForMission(lbs, "Standard", 4); // ExpertPlus index 4
assertEquals(extractLeaderboardId(picked), "2");
});
Deno.test("pickPreferredLeaderboard chooses ExpertPlus in Standard pool", () => {
const lbs = [
{
id: "a",
difficulty: { modeName: "Standard", difficultyName: "Hard" },
},
{
id: "b",
difficulty: { modeName: "Standard", difficultyName: "ExpertPlus" },
},
];
const picked = pickPreferredLeaderboard(lbs);
assertEquals(extractLeaderboardId(picked), "b");
});