435 lines
12 KiB
TypeScript
435 lines
12 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import type {
|
|
BracketRoundView,
|
|
CompetitionTeamMemberView,
|
|
CompetitionFactId,
|
|
GameSlotId,
|
|
SeriesId,
|
|
SeriesProjection,
|
|
TeamId,
|
|
TeamTournamentCodeView,
|
|
} from "@lolympus/contracts";
|
|
import {
|
|
copyTournamentCode,
|
|
createTeamSeriesGroups,
|
|
getTeamSeriesDisplayLabel,
|
|
getTeamSeriesPresentation,
|
|
getNextTournamentCodeExpiryDelay,
|
|
getTournamentCodeExpiryLabel,
|
|
getTournamentCodeCopyLabel,
|
|
getTournamentCodePresentation,
|
|
sortCompletedTeamSeries,
|
|
sortTeamMembersForRoster,
|
|
} from "../src/pages/match-team-progress-view.ts";
|
|
|
|
const TEAM_A = "team-a" as TeamId;
|
|
const TEAM_B = "team-b" as TeamId;
|
|
|
|
test("groups only matching tournament codes under each active Series", () => {
|
|
const earlier = readySeries("series-earlier", 1);
|
|
const later = readySeries("series-later", 2);
|
|
const groups = createTeamSeriesGroups(
|
|
[later, earlier],
|
|
[
|
|
tournamentCode("later-2", later.seriesId, 2, 20),
|
|
tournamentCode("orphan", "series-orphan" as SeriesId, 1, 99),
|
|
tournamentCode("earlier-1", earlier.seriesId, 1, 17),
|
|
tournamentCode("later-1", later.seriesId, 1, 19),
|
|
],
|
|
);
|
|
|
|
assert.deepEqual(
|
|
groups.map(({ series, codes }) => ({
|
|
seriesId: series.seriesId,
|
|
gameSlotIds: codes.map(({ gameSlotId }) => gameSlotId),
|
|
})),
|
|
[
|
|
{ seriesId: earlier.seriesId, gameSlotIds: ["earlier-1"] },
|
|
{ seriesId: later.seriesId, gameSlotIds: ["later-1", "later-2"] },
|
|
],
|
|
);
|
|
});
|
|
|
|
test("uses Korean round names while keeping global game numbers secondary", () => {
|
|
const opening = readySeries("upper-opening-2", 1, "WB_R1_M2");
|
|
const final = readySeries("upper-final", 3, "WB_FINAL");
|
|
const rounds: BracketRoundView[] = [
|
|
round("upper", 1, 1, ["upper-opening-1", opening.seriesId]),
|
|
round("upper", 3, 3, [final.seriesId]),
|
|
];
|
|
|
|
assert.equal(
|
|
getTeamSeriesDisplayLabel(opening, rounds),
|
|
"승자조 1라운드 · 2경기",
|
|
);
|
|
assert.equal(getTeamSeriesDisplayLabel(final, rounds), "승자조 결승");
|
|
|
|
const assignment = tournamentCode("final-1", final.seriesId, 1, 19);
|
|
assert.equal(
|
|
getTournamentCodeCopyLabel(assignment, "승자조 결승"),
|
|
"승자조 결승 1세트 토너먼트 코드 복사 (전체 19번 게임)",
|
|
);
|
|
});
|
|
|
|
test("hides misleading scores before play and for adjudicated outcomes", () => {
|
|
const ready = readySeries("ready", 1);
|
|
const walkover = completedSeries(
|
|
"walkover",
|
|
"2026-07-13T10:00:00.000Z",
|
|
2,
|
|
);
|
|
const played: Extract<SeriesProjection, { status: "completed" }> = {
|
|
...walkover,
|
|
code: "PLAYED",
|
|
entries: [
|
|
{ slot: "A", teamId: TEAM_A, gameWins: 2 },
|
|
{ slot: "B", teamId: TEAM_B, gameWins: 1 },
|
|
],
|
|
outcome: {
|
|
type: "played",
|
|
winnerTeamId: TEAM_A,
|
|
loserTeamId: TEAM_B,
|
|
decidedByGameIds: [],
|
|
completedAt: "2026-07-13T11:00:00.000Z",
|
|
},
|
|
};
|
|
|
|
assert.deepEqual(getTeamSeriesPresentation(ready), {
|
|
label: "경기 가능",
|
|
tone: "ready",
|
|
showScore: false,
|
|
});
|
|
for (const [status, expected] of [
|
|
["inactive", { label: "비활성", tone: "muted", showScore: false }],
|
|
["waiting", { label: "대진 대기", tone: "muted", showScore: false }],
|
|
["in-progress", { label: "진행 중", tone: "live", showScore: true }],
|
|
] as const) {
|
|
assert.deepEqual(
|
|
getTeamSeriesPresentation({ ...ready, status } as SeriesProjection),
|
|
expected,
|
|
);
|
|
}
|
|
assert.deepEqual(getTeamSeriesPresentation(walkover), {
|
|
label: "부전승",
|
|
tone: "adjudicated",
|
|
showScore: false,
|
|
});
|
|
assert.deepEqual(getTeamSeriesPresentation(played), {
|
|
label: "종료",
|
|
tone: "completed",
|
|
showScore: true,
|
|
});
|
|
|
|
const adjudicatedOutcomes = [
|
|
["forfeit", "기권승"],
|
|
["administrative", "판정승"],
|
|
] as const;
|
|
for (const [type, label] of adjudicatedOutcomes) {
|
|
const series: Extract<SeriesProjection, { status: "completed" }> = {
|
|
...walkover,
|
|
outcome: {
|
|
...walkover.outcome,
|
|
type,
|
|
},
|
|
};
|
|
assert.deepEqual(getTeamSeriesPresentation(series), {
|
|
label,
|
|
tone: "adjudicated",
|
|
showScore: false,
|
|
});
|
|
}
|
|
|
|
for (const basis of ["played", "administrative"] as const) {
|
|
const draw: Extract<SeriesProjection, { status: "completed" }> = {
|
|
...walkover,
|
|
entries: [
|
|
{ slot: "A", teamId: TEAM_A, gameWins: 1 },
|
|
{ slot: "B", teamId: TEAM_B, gameWins: 1 },
|
|
],
|
|
outcome: {
|
|
type: "draw",
|
|
basis:
|
|
basis === "played"
|
|
? { type: basis, decidedByGameIds: [] }
|
|
: {
|
|
type: basis,
|
|
decisionFactId: "draw-fact" as CompetitionFactId,
|
|
},
|
|
completedAt: "2026-07-13T12:00:00.000Z",
|
|
},
|
|
};
|
|
assert.deepEqual(getTeamSeriesPresentation(draw), {
|
|
label: "무승부",
|
|
tone: basis === "played" ? "completed" : "adjudicated",
|
|
showScore: basis === "played",
|
|
});
|
|
}
|
|
});
|
|
|
|
test("distinguishes pending, available, expired, and used code states", () => {
|
|
const now = Date.parse("2026-07-13T12:00:00.000Z");
|
|
const pending = tournamentCode("pending", "series-a" as SeriesId, 1, 1, {
|
|
state: "pending",
|
|
code: null,
|
|
});
|
|
const available = tournamentCode(
|
|
"available",
|
|
"series-a" as SeriesId,
|
|
2,
|
|
2,
|
|
{ expiresAt: "2026-07-13T13:00:00.000Z" },
|
|
);
|
|
const expired = tournamentCode(
|
|
"expired",
|
|
"series-a" as SeriesId,
|
|
3,
|
|
3,
|
|
{ expiresAt: "2026-07-13T11:00:00.000Z" },
|
|
);
|
|
const used = tournamentCode("used", "series-a" as SeriesId, 4, 4, {
|
|
state: "used",
|
|
expiresAt: "2026-07-13T11:00:00.000Z",
|
|
});
|
|
const expiresNow = tournamentCode(
|
|
"expires-now",
|
|
"series-a" as SeriesId,
|
|
5,
|
|
5,
|
|
{ expiresAt: "2026-07-13T12:00:00.000Z" },
|
|
);
|
|
const noExpiry = tournamentCode(
|
|
"no-expiry",
|
|
"series-a" as SeriesId,
|
|
6,
|
|
6,
|
|
);
|
|
const invalidExpiry = tournamentCode(
|
|
"invalid-expiry",
|
|
"series-a" as SeriesId,
|
|
7,
|
|
7,
|
|
{ expiresAt: "not-a-date" },
|
|
);
|
|
|
|
assert.deepEqual(getTournamentCodePresentation(pending, now), {
|
|
label: "발급 대기",
|
|
tone: "pending",
|
|
canCopy: false,
|
|
});
|
|
assert.deepEqual(getTournamentCodePresentation(available, now), {
|
|
label: "사용 가능",
|
|
tone: "available",
|
|
canCopy: true,
|
|
});
|
|
assert.deepEqual(getTournamentCodePresentation(expired, now), {
|
|
label: "만료",
|
|
tone: "expired",
|
|
canCopy: false,
|
|
});
|
|
assert.deepEqual(getTournamentCodePresentation(used, now), {
|
|
label: "사용 완료",
|
|
tone: "used",
|
|
canCopy: false,
|
|
});
|
|
assert.deepEqual(getTournamentCodePresentation(expiresNow, now), {
|
|
label: "만료",
|
|
tone: "expired",
|
|
canCopy: false,
|
|
});
|
|
assert.deepEqual(getTournamentCodePresentation(noExpiry, now), {
|
|
label: "사용 가능",
|
|
tone: "available",
|
|
canCopy: true,
|
|
});
|
|
assert.deepEqual(getTournamentCodePresentation(invalidExpiry, now), {
|
|
label: "만료 정보 오류",
|
|
tone: "expired",
|
|
canCopy: false,
|
|
});
|
|
});
|
|
|
|
test("describes tournament-code expiry according to its current state", () => {
|
|
const beforeExpiry = Date.parse("2026-07-13T12:00:00.000Z");
|
|
const atExpiry = Date.parse("2026-07-13T13:00:00.000Z");
|
|
const expiresAt = "2026-07-13T13:00:00.000Z";
|
|
const formatter = new Intl.DateTimeFormat("ko-KR", {
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
timeZone: "Asia/Seoul",
|
|
timeZoneName: "short",
|
|
});
|
|
const formatted = formatter.format(new Date(expiresAt));
|
|
|
|
assert.equal(
|
|
getTournamentCodeExpiryLabel(expiresAt, beforeExpiry),
|
|
`${formatted}까지 사용 가능`,
|
|
);
|
|
assert.equal(
|
|
getTournamentCodeExpiryLabel(expiresAt, atExpiry),
|
|
`${formatted}에 만료됨`,
|
|
);
|
|
assert.equal(
|
|
getTournamentCodeExpiryLabel("not-a-date", beforeExpiry),
|
|
"만료 시각 정보 없음",
|
|
);
|
|
});
|
|
|
|
test("schedules the next code-state refresh at the nearest future expiry", () => {
|
|
const now = Date.parse("2026-07-13T12:00:00.000Z");
|
|
const first = tournamentCode("first", "series-a" as SeriesId, 1, 1, {
|
|
expiresAt: "2026-07-13T12:01:00.000Z",
|
|
});
|
|
const later = tournamentCode("later", "series-a" as SeriesId, 2, 2, {
|
|
expiresAt: "2026-07-13T13:00:00.000Z",
|
|
});
|
|
const alreadyExpired = tournamentCode(
|
|
"expired",
|
|
"series-a" as SeriesId,
|
|
3,
|
|
3,
|
|
{ expiresAt: "2026-07-13T11:00:00.000Z" },
|
|
);
|
|
|
|
assert.equal(
|
|
getNextTournamentCodeExpiryDelay([later, alreadyExpired, first], now),
|
|
60_000,
|
|
);
|
|
assert.equal(
|
|
getNextTournamentCodeExpiryDelay([alreadyExpired], now),
|
|
null,
|
|
);
|
|
});
|
|
|
|
test("returns explicit game-specific clipboard success and failure feedback", async () => {
|
|
const writes: string[] = [];
|
|
const success = await copyTournamentCode(
|
|
async (value) => {
|
|
writes.push(value);
|
|
},
|
|
"KR-CODE-19",
|
|
"승자조 결승 1세트",
|
|
);
|
|
const failure = await copyTournamentCode(
|
|
async () => {
|
|
throw new Error("clipboard denied");
|
|
},
|
|
"KR-CODE-20",
|
|
"승자조 결승 2세트",
|
|
);
|
|
|
|
assert.deepEqual(writes, ["KR-CODE-19"]);
|
|
assert.deepEqual(success, {
|
|
kind: "success",
|
|
message: "승자조 결승 1세트 코드를 복사했습니다.",
|
|
});
|
|
assert.deepEqual(failure, {
|
|
kind: "error",
|
|
message:
|
|
"승자조 결승 2세트 코드를 복사하지 못했습니다. 코드를 직접 선택해 복사해 주세요.",
|
|
});
|
|
});
|
|
|
|
test("sorts completed Series by most recent decision time", () => {
|
|
const older = completedSeries("older", "2026-07-12T10:00:00.000Z", 1);
|
|
const newer = completedSeries("newer", "2026-07-13T10:00:00.000Z", 2);
|
|
|
|
assert.deepEqual(
|
|
sortCompletedTeamSeries([older, newer]).map(({ seriesId }) => seriesId),
|
|
[newer.seriesId, older.seriesId],
|
|
);
|
|
});
|
|
|
|
test("orders the roster by the canonical League positions", () => {
|
|
const members: CompetitionTeamMemberView[] = [
|
|
{ userId: "support" as never, displayName: "Support", assignedPosition: "SUP" },
|
|
{ userId: "top" as never, displayName: "Top", assignedPosition: "TOP" },
|
|
{ userId: "unknown" as never, displayName: "Unknown" },
|
|
{ userId: "mid" as never, displayName: "Mid", assignedPosition: "MID" },
|
|
{ userId: "jungle" as never, displayName: "Jungle", assignedPosition: "JGL" },
|
|
{ userId: "adc" as never, displayName: "Adc", assignedPosition: "ADC" },
|
|
];
|
|
|
|
assert.deepEqual(
|
|
sortTeamMembersForRoster(members).map(({ displayName }) => displayName),
|
|
["Top", "Jungle", "Mid", "Adc", "Support", "Unknown"],
|
|
);
|
|
});
|
|
|
|
function readySeries(
|
|
id: string,
|
|
displayOrder: number,
|
|
code = id.toUpperCase(),
|
|
): SeriesProjection {
|
|
return {
|
|
seriesId: id as SeriesId,
|
|
code,
|
|
stage: { type: "upper", roundNumber: displayOrder, displayOrder },
|
|
rule: { type: "first-to", winsRequired: 2, maxGames: 3 },
|
|
status: "ready",
|
|
entries: [
|
|
{ slot: "A", teamId: TEAM_A, gameWins: 0 },
|
|
{ slot: "B", teamId: TEAM_B, gameWins: 0 },
|
|
],
|
|
};
|
|
}
|
|
|
|
function completedSeries(
|
|
id: string,
|
|
completedAt: string,
|
|
displayOrder: number,
|
|
): Extract<SeriesProjection, { status: "completed" }> {
|
|
return {
|
|
...readySeries(id, displayOrder),
|
|
status: "completed",
|
|
entries: [
|
|
{ slot: "A", teamId: TEAM_A, gameWins: 0 },
|
|
{ slot: "B", teamId: TEAM_B, gameWins: 0 },
|
|
],
|
|
outcome: {
|
|
type: "walkover",
|
|
winnerTeamId: TEAM_A,
|
|
loserTeamId: TEAM_B,
|
|
decisionFactId: `${id}-fact` as CompetitionFactId,
|
|
completedAt,
|
|
},
|
|
};
|
|
}
|
|
|
|
function tournamentCode(
|
|
id: string,
|
|
seriesId: SeriesId,
|
|
ordinal: number,
|
|
displayNumber: number,
|
|
overrides: Partial<TeamTournamentCodeView> = {},
|
|
): TeamTournamentCodeView {
|
|
return {
|
|
gameSlotId: id as GameSlotId,
|
|
seriesId,
|
|
ordinal,
|
|
displayNumber,
|
|
state: "reserved",
|
|
code: `KR-${id}`,
|
|
expiresAt: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function round(
|
|
stage: BracketRoundView["stage"],
|
|
roundNumber: number,
|
|
displayOrder: number,
|
|
seriesIds: Array<string | SeriesId>,
|
|
): BracketRoundView {
|
|
return {
|
|
stage,
|
|
roundNumber,
|
|
displayOrder,
|
|
label: `${stage}-${roundNumber}`,
|
|
seriesIds: seriesIds.map((id) => id as SeriesId),
|
|
};
|
|
}
|