refactor: remove legacy round-robin repair
This commit is contained in:
1 parent
7399968fe8
commit
ade5735dc2
3 files changed
+39
-54
No files matched your search
@@ -10,9 +10,9 @@ type TournamentCodeServiceInternals = TournamentCodeService & {
|
|||||||
ensureGameSchedule(match: MatchDocument): void;
|
ensureGameSchedule(match: MatchDocument): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function createService(connectionService = {} as never) {
|
function createService() {
|
||||||
return new TournamentCodeService(
|
return new TournamentCodeService(
|
||||||
connectionService,
|
{} as never,
|
||||||
) as unknown as TournamentCodeServiceInternals;
|
) as unknown as TournamentCodeServiceInternals;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,6 @@ interface MatchOverrides {
|
|||||||
teamAIndex: number;
|
teamAIndex: number;
|
||||||
teamBIndex: number;
|
teamBIndex: number;
|
||||||
}>;
|
}>;
|
||||||
tournamentCodeIds?: unknown[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMatch(overrides: MatchOverrides): MatchDocument {
|
function createMatch(overrides: MatchOverrides): MatchDocument {
|
||||||
@@ -218,7 +217,7 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rebuilds legacy round-robin schedules without round numbers before reservation', () => {
|
it('leaves legacy round-robin schedules without round numbers unchanged', () => {
|
||||||
const service = createService();
|
const service = createService();
|
||||||
const roundRobin = createMatch({
|
const roundRobin = createMatch({
|
||||||
gameMode: 'round-robin',
|
gameMode: 'round-robin',
|
||||||
@@ -226,7 +225,6 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
|||||||
teams: Array.from({ length: 6 }, (_, index) => ({
|
teams: Array.from({ length: 6 }, (_, index) => ({
|
||||||
teamIndex: index + 1,
|
teamIndex: index + 1,
|
||||||
})),
|
})),
|
||||||
tournamentCodeIds: [],
|
|
||||||
gameSchedule: [
|
gameSchedule: [
|
||||||
{ gameNumber: 1, teamAIndex: 2, teamBIndex: 5 },
|
{ gameNumber: 1, teamAIndex: 2, teamBIndex: 5 },
|
||||||
{ gameNumber: 2, teamAIndex: 1, teamBIndex: 2 },
|
{ gameNumber: 2, teamAIndex: 1, teamBIndex: 2 },
|
||||||
@@ -237,26 +235,22 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const persisted = [...roundRobin.gameSchedule];
|
||||||
service.ensureGameSchedule(roundRobin);
|
service.ensureGameSchedule(roundRobin);
|
||||||
|
|
||||||
for (const roundNumber of [1, 2, 3, 4, 5]) {
|
expect(roundRobin.gameSchedule).toEqual(persisted);
|
||||||
const round = roundRobin.gameSchedule.filter(
|
|
||||||
(game) => game.roundNumber === roundNumber,
|
|
||||||
);
|
|
||||||
expect(round).toHaveLength(3);
|
|
||||||
expect(new Set(round.flatMap((game) => [game.teamAIndex, game.teamBIndex])).size)
|
|
||||||
.toBe(6);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses regenerated round refs for pending legacy round-robin slots', async () => {
|
it('does not expose round numbers for legacy round-robin slots', async () => {
|
||||||
const codeFindExec = jest.fn().mockResolvedValue([]);
|
const codeFindExec = jest.fn().mockResolvedValue([]);
|
||||||
const connectionService = {
|
const connectionService = {
|
||||||
getModel: jest.fn().mockResolvedValue({
|
getModel: jest.fn().mockResolvedValue({
|
||||||
find: jest.fn().mockReturnValue({ exec: codeFindExec }),
|
find: jest.fn().mockReturnValue({ exec: codeFindExec }),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
const service = createService(connectionService as never);
|
const service = new TournamentCodeService(
|
||||||
|
connectionService as never,
|
||||||
|
) as unknown as TournamentCodeServiceInternals;
|
||||||
|
|
||||||
const slots = await service.buildSlots(
|
const slots = await service.buildSlots(
|
||||||
createMatch({
|
createMatch({
|
||||||
@@ -265,7 +259,6 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
|||||||
teams: Array.from({ length: 6 }, (_, index) => ({
|
teams: Array.from({ length: 6 }, (_, index) => ({
|
||||||
teamIndex: index + 1,
|
teamIndex: index + 1,
|
||||||
})),
|
})),
|
||||||
tournamentCodeIds: [],
|
|
||||||
gameSchedule: [
|
gameSchedule: [
|
||||||
{ gameNumber: 1, teamAIndex: 2, teamBIndex: 5 },
|
{ gameNumber: 1, teamAIndex: 2, teamBIndex: 5 },
|
||||||
{ gameNumber: 2, teamAIndex: 1, teamBIndex: 2 },
|
{ gameNumber: 2, teamAIndex: 1, teamBIndex: 2 },
|
||||||
@@ -286,12 +279,16 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const roundNumber of [1, 2, 3, 4, 5]) {
|
expect(slots).toHaveLength(15);
|
||||||
const round = slots.filter((slot) => slot.roundNumber === roundNumber);
|
expect(slots[0]).toEqual(
|
||||||
expect(round).toHaveLength(3);
|
expect.objectContaining({
|
||||||
expect(new Set(round.flatMap((slot) => [slot.teamAIndex, slot.teamBIndex])).size)
|
gameNumber: 1,
|
||||||
.toBe(6);
|
roundNumber: undefined,
|
||||||
}
|
teamAIndex: 2,
|
||||||
|
teamBIndex: 5,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(slots.every((slot) => slot.roundNumber === undefined)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not expose fallback round-robin slots before the schedule is persisted', async () => {
|
it('does not expose fallback round-robin slots before the schedule is persisted', async () => {
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ export class TournamentCodeService {
|
|||||||
const gameMode = match.gameMode ?? 'pair';
|
const gameMode = match.gameMode ?? 'pair';
|
||||||
|
|
||||||
if (gameMode === 'round-robin') {
|
if (gameMode === 'round-robin') {
|
||||||
if (this.shouldUsePersistedRoundRobinSchedule(match)) {
|
if ((match.gameSchedule?.length ?? 0) > 0) {
|
||||||
return match.gameSchedule.length;
|
return match.gameSchedule.length;
|
||||||
}
|
}
|
||||||
return this.buildRoundRobinGameSchedule(match).length;
|
return this.buildRoundRobinGameSchedule(match).length;
|
||||||
@@ -422,12 +422,10 @@ export class TournamentCodeService {
|
|||||||
(entry) => entry.gameNumber === gameNumber,
|
(entry) => entry.gameNumber === gameNumber,
|
||||||
);
|
);
|
||||||
if (persisted) {
|
if (persisted) {
|
||||||
if (this.shouldUsePersistedRoundRobinSchedule(match)) {
|
return {
|
||||||
return {
|
teamAIndex: persisted.teamAIndex,
|
||||||
teamAIndex: persisted.teamAIndex,
|
teamBIndex: persisted.teamBIndex,
|
||||||
teamBIndex: persisted.teamBIndex,
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fallback = this.buildRoundRobinGameSchedule(match).find(
|
const fallback = this.buildRoundRobinGameSchedule(match).find(
|
||||||
@@ -454,10 +452,10 @@ export class TournamentCodeService {
|
|||||||
|
|
||||||
private ensureGameSchedule(match: MatchDocument): void {
|
private ensureGameSchedule(match: MatchDocument): void {
|
||||||
if ((match.gameMode ?? 'pair') !== 'round-robin') return;
|
if ((match.gameMode ?? 'pair') !== 'round-robin') return;
|
||||||
|
if ((match.gameSchedule?.length ?? 0) > 0) return;
|
||||||
|
|
||||||
const teamCount = resolveRoundRobinTeamCount(match);
|
const teamCount = resolveRoundRobinTeamCount(match);
|
||||||
if (teamCount < 2) return;
|
if (teamCount < 2) return;
|
||||||
if (this.shouldUsePersistedRoundRobinSchedule(match)) return;
|
|
||||||
|
|
||||||
match.gameSchedule = this.buildRoundRobinGameSchedule(match);
|
match.gameSchedule = this.buildRoundRobinGameSchedule(match);
|
||||||
}
|
}
|
||||||
@@ -471,33 +469,13 @@ export class TournamentCodeService {
|
|||||||
const persisted = match.gameSchedule?.find(
|
const persisted = match.gameSchedule?.find(
|
||||||
(entry) => entry.gameNumber === gameNumber,
|
(entry) => entry.gameNumber === gameNumber,
|
||||||
);
|
);
|
||||||
if (persisted) {
|
if (persisted) return persisted.roundNumber;
|
||||||
if (persisted.roundNumber) return persisted.roundNumber;
|
|
||||||
if (this.shouldUsePersistedRoundRobinSchedule(match)) return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.buildRoundRobinGameSchedule(match).find(
|
return this.buildRoundRobinGameSchedule(match).find(
|
||||||
(entry) => entry.gameNumber === gameNumber,
|
(entry) => entry.gameNumber === gameNumber,
|
||||||
)?.roundNumber;
|
)?.roundNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
private shouldUsePersistedRoundRobinSchedule(match: MatchDocument): boolean {
|
|
||||||
const schedule = match.gameSchedule ?? [];
|
|
||||||
if (schedule.length === 0) return false;
|
|
||||||
if (schedule.every((entry) => typeof entry.roundNumber === 'number')) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !this.canRegenerateRoundRobinSchedule(match);
|
|
||||||
}
|
|
||||||
|
|
||||||
private canRegenerateRoundRobinSchedule(match: MatchDocument): boolean {
|
|
||||||
return (
|
|
||||||
(match.tournamentCodeIds?.length ?? 0) === 0 &&
|
|
||||||
(match.result?.games?.length ?? 0) === 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildRoundRobinGameSchedule(
|
private buildRoundRobinGameSchedule(
|
||||||
match: MatchDocument,
|
match: MatchDocument,
|
||||||
shuffleTeams = false,
|
shuffleTeams = false,
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import type {
|
|||||||
ApiPositionPreference,
|
ApiPositionPreference,
|
||||||
ApiTierInfo,
|
ApiTierInfo,
|
||||||
ManualTournamentResultCollectResponse,
|
ManualTournamentResultCollectResponse,
|
||||||
|
MatchGameMode,
|
||||||
Position,
|
Position,
|
||||||
TeamSide,
|
TeamSide,
|
||||||
TournamentCodeSlotView,
|
TournamentCodeSlotView,
|
||||||
@@ -1458,7 +1459,13 @@ function TournamentCodeDisplay({ slot }: { slot: TournamentCodeSlotView }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TournamentCodeList({ slots }: { slots: TournamentCodeSlotView[] }) {
|
function TournamentCodeList({
|
||||||
|
slots,
|
||||||
|
gameMode,
|
||||||
|
}: {
|
||||||
|
slots: TournamentCodeSlotView[];
|
||||||
|
gameMode: MatchGameMode;
|
||||||
|
}) {
|
||||||
if (slots.length === 0) {
|
if (slots.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div className="border border-dashed border-base-content/10 px-3 py-3 text-xs text-base-content/30">
|
<div className="border border-dashed border-base-content/10 px-3 py-3 text-xs text-base-content/30">
|
||||||
@@ -1469,7 +1476,7 @@ function TournamentCodeList({ slots }: { slots: TournamentCodeSlotView[] }) {
|
|||||||
|
|
||||||
function renderSlot(slot: TournamentCodeSlotView) {
|
function renderSlot(slot: TournamentCodeSlotView) {
|
||||||
const shouldShowTeamLabel =
|
const shouldShowTeamLabel =
|
||||||
Boolean(slot.roundNumber) || slot.teamAIndex > 1 || slot.teamBIndex > 2;
|
gameMode === "round-robin" || slot.teamAIndex > 1 || slot.teamBIndex > 2;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={slot.gameNumber} className="flex items-start gap-2">
|
<div key={slot.gameNumber} className="flex items-start gap-2">
|
||||||
@@ -2829,7 +2836,10 @@ export default function MatchDetailPage() {
|
|||||||
{(match.status === "team-built" ||
|
{(match.status === "team-built" ||
|
||||||
match.status === "in-progress") && (
|
match.status === "in-progress") && (
|
||||||
<SideCard title="토너먼트 코드">
|
<SideCard title="토너먼트 코드">
|
||||||
<TournamentCodeList slots={match.tournamentCodes} />
|
<TournamentCodeList
|
||||||
|
slots={match.tournamentCodes}
|
||||||
|
gameMode={match.gameMode}
|
||||||
|
/>
|
||||||
<PoolStatsHint enabled={canManageAuction} />
|
<PoolStatsHint enabled={canManageAuction} />
|
||||||
</SideCard>
|
</SideCard>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in new issue
Block a user