diff --git a/apps/api/src/modules/competition/competition-command.service.spec.ts b/apps/api/src/modules/competition/competition-command.service.spec.ts index d4a9a75c..1db0db1e 100644 --- a/apps/api/src/modules/competition/competition-command.service.spec.ts +++ b/apps/api/src/modules/competition/competition-command.service.spec.ts @@ -66,7 +66,10 @@ describe('CompetitionCommandService', () => { $inc: { revision: 1 }, $set: { projection: PROJECTION }, }); - expect(casOptions).toMatchObject({ new: true, session: harness.session }); + expect(casOptions).toMatchObject({ + returnDocument: 'after', + session: harness.session, + }); expect(harness.session.abortTransaction).toHaveBeenCalledTimes(1); expect(harness.session.commitTransaction).not.toHaveBeenCalled(); }); diff --git a/apps/api/src/modules/competition/competition-command.service.ts b/apps/api/src/modules/competition/competition-command.service.ts index 7567f2af..9a7c86fc 100644 --- a/apps/api/src/modules/competition/competition-command.service.ts +++ b/apps/api/src/modules/competition/competition-command.service.ts @@ -321,7 +321,7 @@ export class CompetitionCommandService { phase: projection.phase, }, }, - { new: true, runValidators: true, session }, + { returnDocument: 'after', runValidators: true, session }, ) .lean() .exec(); @@ -475,7 +475,7 @@ export class CompetitionCommandService { phase: projection.phase, }, }, - { new: true, runValidators: true, session }, + { returnDocument: 'after', runValidators: true, session }, ) .lean() .exec(); diff --git a/apps/api/src/modules/competition/competition-query.service.spec.ts b/apps/api/src/modules/competition/competition-query.service.spec.ts index 13211b94..37f21c07 100644 --- a/apps/api/src/modules/competition/competition-query.service.spec.ts +++ b/apps/api/src/modules/competition/competition-query.service.spec.ts @@ -1,4 +1,8 @@ -import { ConflictException, ForbiddenException } from '@nestjs/common'; +import { + ConflictException, + ForbiddenException, + NotFoundException, +} from '@nestjs/common'; import { Types } from 'mongoose'; import { ConnectionService } from '../global/database/connection.service'; import { CompetitionQueryService } from './competition-query.service'; @@ -55,6 +59,38 @@ describe('CompetitionQueryService', () => { }); }); + it('resolves a team view from an explicit team id without a caller identity', async () => { + const harness = createHarness(); + const service = createService(harness); + + const result = await service.getTeamView({ + communityId: COMMUNITY_ID, + matchId: MATCH_ID, + teamId: TEAM_A_ID, + }); + + expect(result).toMatchObject({ + teamId: TEAM_A_ID.toHexString(), + activeSeries: [expect.objectContaining({ seriesId: SERIES_ID })], + tournamentCodes: [ + expect.objectContaining({ code: 'TEAM-A-SECRET-CODE' }), + ], + }); + expect(JSON.stringify(result)).not.toContain('OPPONENT-SECRET-CODE'); + }); + + it('does not resolve a team view for an unknown team id', async () => { + const service = createService(createHarness()); + + await expect( + service.getTeamView({ + communityId: COMMUNITY_ID, + matchId: MATCH_ID, + teamId: new Types.ObjectId('64c000000000000000000098'), + }), + ).rejects.toBeInstanceOf(NotFoundException); + }); + it('does not reveal a team view to an authenticated non-participant', async () => { const service = createService(createHarness()); diff --git a/apps/api/src/modules/competition/competition-query.service.ts b/apps/api/src/modules/competition/competition-query.service.ts index b20c4815..d5fc5b05 100644 --- a/apps/api/src/modules/competition/competition-query.service.ts +++ b/apps/api/src/modules/competition/competition-query.service.ts @@ -22,6 +22,17 @@ export interface CompetitionScope { matchId: mongoose.Types.ObjectId; } +/** + * A team view is addressed either by the caller's membership (signed-in) or by + * an explicit team id. The explicit form exists so that the team progress page + * stays usable while community members have not all signed in yet. + */ +export type TeamViewScope = CompetitionScope & + ( + | { userId: mongoose.Types.ObjectId; teamId?: undefined } + | { teamId: mongoose.Types.ObjectId; userId?: undefined } + ); + interface CompetitionProjectionSource { series?: Array>; gameSlots?: Array>; @@ -68,15 +79,21 @@ export class CompetitionQueryService { } public async getTeamView( - scope: CompetitionScope & { userId: mongoose.Types.ObjectId }, + scope: TeamViewScope, ): Promise { const competition = (await this.getCompetition(scope)) as Competition & { _id: PersistenceId; }; - const team = competition.teams.find(({ members }) => - members.some(({ userId }) => sameId(userId, scope.userId)), - ); + const requestedTeamId = scope.teamId; + const team = requestedTeamId + ? competition.teams.find(({ teamId }) => sameId(teamId, requestedTeamId)) + : competition.teams.find(({ members }) => + members.some(({ userId }) => sameId(userId, scope.userId)), + ); if (!team) { + if (requestedTeamId) { + throw new NotFoundException('Competition team not found.'); + } throw new ForbiddenException( 'Only a Competition team member may access the team view.', ); diff --git a/apps/api/src/modules/competition/competition.controller.spec.ts b/apps/api/src/modules/competition/competition.controller.spec.ts index db56b6fc..9b98e109 100644 --- a/apps/api/src/modules/competition/competition.controller.spec.ts +++ b/apps/api/src/modules/competition/competition.controller.spec.ts @@ -7,7 +7,7 @@ import { CompetitionController } from './competition.controller'; import { CompetitionQueryService } from './competition-query.service'; describe('CompetitionController', () => { - it('marks only the detail endpoint public and writes a revision ETag', async () => { + it('marks the read endpoints public and writes a revision ETag', async () => { const { controller, queryService } = createHarness(); const response = { setHeader: jest.fn() }; @@ -17,18 +17,14 @@ describe('CompetitionController', () => { response as never, ); - expect( - Reflect.getMetadata( - METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED, - CompetitionController.prototype.getDetail, - ), - ).toBe(true); - expect( - Reflect.getMetadata( - METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED, - CompetitionController.prototype.getTeamView, - ), - ).not.toBe(true); + for (const method of ['getDetail', 'getTeamView'] as const) { + expect( + Reflect.getMetadata( + METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED, + CompetitionController.prototype[method], + ), + ).toBe(true); + } expect(response.setHeader).toHaveBeenCalledWith('ETag', '"7"'); expect(result).toMatchObject({ revision: 7 }); expect(queryService.getCompetition).toHaveBeenCalledWith({ @@ -37,6 +33,65 @@ describe('CompetitionController', () => { }); }); + it('reads a team view by explicit team id without an authenticated caller', async () => { + const { controller, queryService } = createHarness(); + queryService.getTeamView.mockResolvedValue({ revision: 7 }); + const response = { setHeader: jest.fn() }; + + const result = await controller.getTeamView( + undefined, + COMMUNITY_ID, + MATCH_ID, + TEAM_A_ID.toHexString(), + response as never, + ); + + expect(queryService.getTeamView).toHaveBeenCalledWith({ + communityId: COMMUNITY_ID, + matchId: MATCH_ID, + teamId: TEAM_A_ID, + }); + expect(response.setHeader).toHaveBeenCalledWith('ETag', '"7"'); + expect(result).toMatchObject({ revision: 7 }); + }); + + it('falls back to the membership-scoped team view for a signed-in caller', async () => { + const { controller, queryService } = createHarness(); + queryService.getTeamView.mockResolvedValue({ revision: 7 }); + + await controller.getTeamView(adminUser(), COMMUNITY_ID, MATCH_ID); + + expect(queryService.getTeamView).toHaveBeenCalledWith({ + communityId: COMMUNITY_ID, + matchId: MATCH_ID, + userId: ADMIN_ID, + }); + }); + + it('rejects an anonymous team view request that names no team', async () => { + const { controller, queryService } = createHarness(); + + await expect( + controller.getTeamView(undefined, COMMUNITY_ID, MATCH_ID), + ).rejects.toMatchObject({ + status: 401, + response: { error: { code: 'COMPETITION_TEAM_UNIDENTIFIED' } }, + }); + expect(queryService.getTeamView).not.toHaveBeenCalled(); + }); + + it('rejects a malformed team id', async () => { + const { controller, queryService } = createHarness(); + + await expect( + controller.getTeamView(undefined, COMMUNITY_ID, MATCH_ID, 'not-an-id'), + ).rejects.toMatchObject({ + status: 422, + response: { error: { code: 'INVALID_COMPETITION_REQUEST' } }, + }); + expect(queryService.getTeamView).not.toHaveBeenCalled(); + }); + it('protects audit and mutation endpoints with admin roles', () => { for (const method of [ 'listFacts', diff --git a/apps/api/src/modules/competition/competition.controller.ts b/apps/api/src/modules/competition/competition.controller.ts index 7504a807..d717357a 100644 --- a/apps/api/src/modules/competition/competition.controller.ts +++ b/apps/api/src/modules/competition/competition.controller.ts @@ -63,20 +63,36 @@ export class CompetitionController { }); } + // Temporarily public: community members are not all signed in yet, so the + // team progress page addresses a team through an explicit `teamId` instead of + // the caller's identity. A signed-in caller with no `teamId` keeps the + // membership-scoped behaviour. @Get('team') + @AllowPublicAccess() public async getTeamView( - @CurrentUser() currentUser: UserDocument, + @CurrentUser() currentUser: UserDocument | undefined, @Param('communityId', ParseObjectIdPipe) communityId: mongoose.Types.ObjectId, @Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId, + @Query('teamId') requestedTeamId?: string, @Res({ passthrough: true }) response?: Response, ): Promise { return this.translate(async () => { - assertSameCommunity(currentUser, communityId); + const teamId = parseOptionalObjectId(requestedTeamId, 'teamId'); + if (!teamId) { + if (!currentUser) { + throw apiHttpError( + 401, + 'COMPETITION_TEAM_UNIDENTIFIED', + 'Sign in or provide a teamId query parameter to read a team view.', + ); + } + assertSameCommunity(currentUser, communityId); + } const result = await this.queryService.getTeamView({ communityId, matchId, - userId: currentUser._id, + ...(teamId ? { teamId } : { userId: currentUser!._id }), }); response?.setHeader('ETag', revisionEtag(result.revision)); return result; @@ -298,6 +314,21 @@ function requireCommandHeaders( return revision; } +function parseOptionalObjectId( + value: string | undefined, + field: string, +): mongoose.Types.ObjectId | undefined { + if (value === undefined || value.trim().length === 0) return undefined; + if (!mongoose.isValidObjectId(value)) { + throw apiHttpError( + 422, + 'INVALID_COMPETITION_REQUEST', + `The ${field} query parameter must be a valid ObjectId.`, + ); + } + return new mongoose.Types.ObjectId(value); +} + function requireRevisionHeader(ifMatch: string | undefined): number { const revision = parseRevision(ifMatch); if (revision === undefined) { diff --git a/apps/api/src/modules/global/database/connection.service.spec.ts b/apps/api/src/modules/global/database/connection.service.spec.ts index 110d9220..8bbd9a59 100644 --- a/apps/api/src/modules/global/database/connection.service.spec.ts +++ b/apps/api/src/modules/global/database/connection.service.spec.ts @@ -1,9 +1,75 @@ +import mongoose from 'mongoose'; import { + ConnectionService, resolveMongoAppName, resolveMongoConnectionOptions, resolveMongoDbName, } from './connection.service'; +function createFakeConnection(connectionId: string) { + const models: Record = {}; + return { + readyState: mongoose.ConnectionStates.connected, + models, + model: jest.fn((name: string) => { + const model = { connectionId, modelName: name }; + models[name] = model; + return model; + }), + }; +} + +describe('ConnectionService', () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('shares one MongoDB connection across concurrent initialization calls', async () => { + const connection = createFakeConnection('shared'); + const createConnection = jest + .spyOn(mongoose, 'createConnection') + .mockReturnValue({ + asPromise: jest.fn().mockResolvedValue(connection), + } as never); + const service = new ConnectionService({ + get: jest.fn().mockResolvedValue('mongodb://localhost/test'), + } as never); + + const [first, second] = await Promise.all([ + service.getConnection(), + service.getConnection(), + ]); + + expect(first).toBe(connection); + expect(second).toBe(connection); + expect(createConnection).toHaveBeenCalledTimes(1); + }); + + it('rebuilds models from the replacement connection after disconnect', async () => { + const firstConnection = createFakeConnection('first'); + const secondConnection = createFakeConnection('second'); + jest + .spyOn(mongoose, 'createConnection') + .mockReturnValueOnce({ + asPromise: jest.fn().mockResolvedValue(firstConnection), + } as never) + .mockReturnValueOnce({ + asPromise: jest.fn().mockResolvedValue(secondConnection), + } as never); + const service = new ConnectionService({ + get: jest.fn().mockResolvedValue('mongodb://localhost/test'), + } as never); + + const firstModel = await service.getModel('match'); + firstConnection.readyState = mongoose.ConnectionStates.disconnected; + const secondModel = await service.getModel('match'); + + expect(firstModel).toMatchObject({ connectionId: 'first' }); + expect(secondModel).toMatchObject({ connectionId: 'second' }); + expect(secondModel).not.toBe(firstModel); + }); +}); + describe('resolveMongoDbName', () => { it('uses production database only for prod', () => { expect(resolveMongoDbName('prod')).toBe('lolympus'); diff --git a/apps/api/src/modules/global/database/connection.service.ts b/apps/api/src/modules/global/database/connection.service.ts index eaf8ff53..f9981d9f 100644 --- a/apps/api/src/modules/global/database/connection.service.ts +++ b/apps/api/src/modules/global/database/connection.service.ts @@ -39,6 +39,7 @@ export function resolveMongoConnectionOptions( export class ConnectionService implements OnModuleInit { private readonly logger = new Logger(ConnectionService.name); private connection: mongoose.Connection | null = null; + private connectionPromise: Promise | null = null; constructor(private readonly secretService: SecretService) {} private tournamentModels: Map> | null = null; @@ -51,35 +52,49 @@ export class ConnectionService implements OnModuleInit { return this.connection; } + const pendingConnection = this.connectionPromise ?? this.openConnection(); + this.connectionPromise = pendingConnection; + try { + return await pendingConnection; + } finally { + if (this.connectionPromise === pendingConnection) { + this.connectionPromise = null; + } + } + } + + private async openConnection(): Promise { const connectionString = await this.secretService.get( 'MONGODB_CONNECTION_STRING', ); const dbName = resolveMongoDbName(); const appName = resolveMongoAppName(); const connectionOptions = resolveMongoConnectionOptions(dbName, appName); - const defaultConnection = await mongoose + const connection = await mongoose .createConnection(connectionString, connectionOptions) .asPromise(); - this.connection = defaultConnection; + + this.connection = connection; + this.tournamentModels = null; this.logger.log( `MongoDB connection created. dbName=${dbName} appName=${appName} autoIndex=${ connectionOptions.autoIndex === true }`, ); - return this.connection; + return connection; } public async getModel( modelKey: K, ): Promise> { + const connection = await this.getConnection(); if (this.tournamentModels) return this.tournamentModels.get(modelKey) as mongoose.Model< TournamentModelTypes[K] >; const models = new Map>(); - const connection = await this.getConnection(); tournamentModelDefinitions.forEach((modelDefinition) => { applyMongoosePerformancePlugin(modelDefinition.schema); diff --git a/apps/api/src/modules/tournament-result/competition-assignment.provisioner.spec.ts b/apps/api/src/modules/tournament-result/competition-assignment.provisioner.spec.ts index ebc19e9e..c903a0d8 100644 --- a/apps/api/src/modules/tournament-result/competition-assignment.provisioner.spec.ts +++ b/apps/api/src/modules/tournament-result/competition-assignment.provisioner.spec.ts @@ -36,7 +36,7 @@ describe('CompetitionAssignmentProvisioner', () => { }), }, expect.objectContaining({ - new: true, + returnDocument: 'after', session: harness.session, sort: { expiresAt: 1 }, }), @@ -122,14 +122,14 @@ describe('CompetitionAssignmentProvisioner', () => { expect(harness.assignmentModel.findOneAndUpdate).toHaveBeenCalledWith( { _id: assignmentId, state: 'reserved' }, { $set: expect.objectContaining({ state: 'released' }) }, - { new: true, session: harness.session }, + { returnDocument: 'after', session: harness.session }, ); expect(harness.codeModel.findOneAndUpdate).toHaveBeenCalledWith( { _id: harness.codeId, state: 'reserved' }, expect.objectContaining({ $set: expect.objectContaining({ state: 'released' }), }), - { new: true, session: harness.session }, + { returnDocument: 'after', session: harness.session }, ); expect(harness.matchModel.updateOne).toHaveBeenCalledWith( { _id: harness.matchId }, diff --git a/apps/api/src/modules/tournament-result/competition-assignment.provisioner.ts b/apps/api/src/modules/tournament-result/competition-assignment.provisioner.ts index 8a6a4c34..2eb3304a 100644 --- a/apps/api/src/modules/tournament-result/competition-assignment.provisioner.ts +++ b/apps/api/src/modules/tournament-result/competition-assignment.provisioner.ts @@ -156,7 +156,7 @@ export class CompetitionAssignmentProvisioner { const assignment = (await params.AssignmentModel.findOneAndUpdate( { _id: params.assignment._id, state: 'reserved' }, { $set: { state: 'released', releasedAt } }, - { new: true, session }, + { returnDocument: 'after', session }, ).exec()) as AssignmentRecord | null; if (!assignment) { await session.commitTransaction(); @@ -173,7 +173,7 @@ export class CompetitionAssignmentProvisioner { reservedAt: 1, }, }, - { new: true, session }, + { returnDocument: 'after', session }, ).exec()) as CodeRecord | null; if (!code) { throw new Error( @@ -354,7 +354,7 @@ export class CompetitionAssignmentProvisioner { gameNumber: params.displayNumber, }, { $set: { gameNumber: params.displayNumber } }, - { new: true, session: params.session }, + { returnDocument: 'after', session: params.session }, ).exec()) as CodeRecord | null; if (promoted) return promoted; } @@ -377,7 +377,11 @@ export class CompetitionAssignmentProvisioner { reservedAt: new Date(), }, }, - { new: true, session: params.session, sort: { expiresAt: 1 } }, + { + returnDocument: 'after', + session: params.session, + sort: { expiresAt: 1 }, + }, ).exec()) as CodeRecord | null; } diff --git a/apps/api/src/modules/tournament-result/competition-outbox.processor.ts b/apps/api/src/modules/tournament-result/competition-outbox.processor.ts index 768597ac..c515c650 100644 --- a/apps/api/src/modules/tournament-result/competition-outbox.processor.ts +++ b/apps/api/src/modules/tournament-result/competition-outbox.processor.ts @@ -110,7 +110,7 @@ export class CompetitionOutboxProcessor $unset: { lastError: 1 }, }, { - new: true, + returnDocument: 'after', sort: { availableAt: 1, revision: 1, _id: 1 }, }, ) diff --git a/apps/web/src/api/hooks.ts b/apps/web/src/api/hooks.ts index 9cb15d64..d434d5cf 100644 --- a/apps/web/src/api/hooks.ts +++ b/apps/web/src/api/hooks.ts @@ -257,12 +257,15 @@ export function useCompetition( export function useTeamCompetition( matchId: string | undefined, communityId = DEFAULT_COMMUNITY_ID, + teamId?: string, ) { return useQuery({ - queryKey: ['competition-team', communityId, matchId ?? null], + queryKey: ['competition-team', communityId, matchId ?? null, teamId ?? null], queryFn: () => apiFetch( - `/communities/${communityId}/matches/${matchId}/competition/team`, + `/communities/${communityId}/matches/${matchId}/competition/team${ + teamId ? `?teamId=${encodeURIComponent(teamId)}` : '' + }`, ), enabled: Boolean(communityId && matchId), retry: false, diff --git a/apps/web/src/components/competition/CompetitionResults.tsx b/apps/web/src/components/competition/CompetitionResults.tsx index 8aef7392..d1530d6f 100644 --- a/apps/web/src/components/competition/CompetitionResults.tsx +++ b/apps/web/src/components/competition/CompetitionResults.tsx @@ -45,7 +45,7 @@ export function CompetitionResults({ to={`/match/${competition.matchId}/team`} className="border border-base-content/10 px-2.5 py-1.5 text-xs font-bold text-base-content/55 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary" > - 내 팀 진행 + 팀 진행 diff --git a/apps/web/src/components/competition/DoubleEliminationBracket.tsx b/apps/web/src/components/competition/DoubleEliminationBracket.tsx index 4653f90e..d7d6a19d 100644 --- a/apps/web/src/components/competition/DoubleEliminationBracket.tsx +++ b/apps/web/src/components/competition/DoubleEliminationBracket.tsx @@ -8,6 +8,7 @@ import type { DoubleEliminationBracketLayout, } from "./double-elimination-bracket-layout"; import { DOUBLE_ELIMINATION_BRACKET_GEOMETRY } from "./double-elimination-bracket-layout"; +import { DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS } from "./competition-display-layout"; import { DoubleEliminationMobileBracket } from "./DoubleEliminationMobileBracket"; import { SeriesScoreCard } from "./SeriesScoreCard"; @@ -57,7 +58,9 @@ function DesktopBracket({ ); return ( -
+

승자조와 패자조는 같은 시간축을 공유하며 오른쪽 결승에서 합류합니다. diff --git a/apps/web/src/components/competition/competition-display-layout.ts b/apps/web/src/components/competition/competition-display-layout.ts index 4f0a3c35..1cc2aa2a 100644 --- a/apps/web/src/components/competition/competition-display-layout.ts +++ b/apps/web/src/components/competition/competition-display-layout.ts @@ -1,12 +1,10 @@ -import type { - CompetitionDetailResponse, - MatchGameMode, -} from "@lolympus/contracts"; +import type { CompetitionDetailResponse } from "@lolympus/contracts"; import { createDoubleEliminationBracketLayout } from "./double-elimination-bracket-layout.ts"; -export function matchPageMaxWidthClass(gameMode: MatchGameMode): string { - return gameMode === "double-elimination" ? "max-w-[1600px]" : "max-w-5xl"; -} +export const MATCH_PAGE_MAX_WIDTH_CLASS = "max-w-5xl"; + +export const DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS = + "relative left-1/2 w-[calc(100vw-3rem)] max-w-[1600px] -translate-x-1/2"; export function createCompetitionBracketLayout( competition: CompetitionDetailResponse, diff --git a/apps/web/src/pages/MatchDetailPage.tsx b/apps/web/src/pages/MatchDetailPage.tsx index 8a351945..6f2b5a01 100644 --- a/apps/web/src/pages/MatchDetailPage.tsx +++ b/apps/web/src/pages/MatchDetailPage.tsx @@ -28,7 +28,7 @@ import { import { RankBadge } from "../components/RankBadge"; import { CompetitionAdminControls } from "../components/competition/CompetitionAdminControls"; import { CompetitionResults } from "../components/competition/CompetitionResults"; -import { matchPageMaxWidthClass } from "../components/competition/competition-display-layout"; +import { MATCH_PAGE_MAX_WIDTH_CLASS } from "../components/competition/competition-display-layout"; import { DEFAULT_COMMUNITY_ID, useAuthUserId } from "../config"; import { apiFetch, ApiError } from "../lib/api"; import { profileIconUrl } from "../lib/ddragon"; @@ -1795,7 +1795,7 @@ export default function MatchDetailPage() { return (

(null); @@ -63,11 +72,24 @@ export default function MatchTeamProgressPage() { ); } + if (isSelectingTeam && competition) { + return ; + } + if (competitionQuery.isLoading || teamQuery.isLoading) { return ; } if (hasQueryError) { + // The caller could not be resolved to a team from their identity — let them + // name the team instead, so the page stays usable without signing in. + if ( + competition && + !competitionQuery.error && + shouldOfferTeamSelection([teamQuery.error], selectedTeamId) + ) { + return ; + } return (

- My Competition + {selectedTeamId ? "Team Competition" : "My Competition"}

-

{team?.name ?? "내 팀"}

+

+ {team?.name ?? (selectedTeamId ? "팀" : "내 팀")} +

- 우리 팀의 공식 대진과 토너먼트 코드는 이 페이지에서만 표시됩니다. + 해당 팀의 공식 대진과 토너먼트 코드가 표시됩니다.

+ + 다른 팀 보기 +
@@ -279,6 +309,57 @@ export default function MatchTeamProgressPage() { ); } +function TeamSelectionState({ + competition, + matchId, +}: { + competition: CompetitionDetailResponse; + matchId: string | undefined; +}) { + return ( +
+ + ← 내전 상세로 + + +
+

+ Team Competition +

+

팀 선택

+

+ 진행 상황과 토너먼트 코드를 확인할 팀을 선택해 주세요. +

+
+ + {competition.teams.length > 0 ? ( +
    + {competition.teams.map((team) => ( +
  • + + + {team.name} + + + {team.members.length}명 + + +
  • + ))} +
+ ) : ( + + )} +
+ ); +} + function TeamProgressLoadingState() { return (
{ - if (typeof error !== "object" || error === null || !("status" in error)) { - return []; - } - return typeof error.status === "number" ? [error.status] : []; - }); + const statuses = errorStatuses(errors); if (statuses.includes(401)) { return { @@ -86,6 +95,15 @@ export function getTeamProgressErrorContent( }; } +function errorStatuses(errors: readonly unknown[]): number[] { + return errors.flatMap((error) => { + if (typeof error !== "object" || error === null || !("status" in error)) { + return []; + } + return typeof error.status === "number" ? [error.status] : []; + }); +} + function isNetworkError(error: unknown): boolean { return ( error instanceof TypeError || diff --git a/apps/web/test/double-elimination-bracket-layout.test.ts b/apps/web/test/double-elimination-bracket-layout.test.ts index 53f8f4b1..7882b530 100644 --- a/apps/web/test/double-elimination-bracket-layout.test.ts +++ b/apps/web/test/double-elimination-bracket-layout.test.ts @@ -10,8 +10,9 @@ import type { TeamId, } from "@lolympus/contracts"; import { + DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS, + MATCH_PAGE_MAX_WIDTH_CLASS, createCompetitionBracketLayout, - matchPageMaxWidthClass, } from "../src/components/competition/competition-display-layout.ts"; import { createDoubleEliminationBracketLayout, @@ -83,10 +84,13 @@ test("places the canonical four-team DAG in shared time columns", () => { assert.equal(nodeFor(layout, ids.GF).lane, "final"); }); -test("selects the wide page grid only for double-elimination matches", () => { - assert.equal(matchPageMaxWidthClass("double-elimination"), "max-w-[1600px]"); - assert.equal(matchPageMaxWidthClass("pair"), "max-w-5xl"); - assert.equal(matchPageMaxWidthClass("round-robin"), "max-w-5xl"); +test("keeps the match page narrow and gives only the desktop bracket a wide viewport", () => { + assert.equal(MATCH_PAGE_MAX_WIDTH_CLASS, "max-w-5xl"); + assert.match(DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS, /max-w-\[1600px\]/); + assert.match( + DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS, + /w-\[calc\(100vw-3rem\)\]/, + ); }); test("selects the bracket only for a coherent double-elimination snapshot", () => { diff --git a/apps/web/test/match-team-progress-state.test.ts b/apps/web/test/match-team-progress-state.test.ts index e63b5553..8347d9ef 100644 --- a/apps/web/test/match-team-progress-state.test.ts +++ b/apps/web/test/match-team-progress-state.test.ts @@ -3,8 +3,20 @@ import test from "node:test"; import { getTeamProgressErrorContent, isConsistentTeamProgressSnapshot, + shouldOfferTeamSelection, } from "../src/pages/match-team-progress-state.ts"; +test("offers team selection when the caller cannot be resolved to a team", () => { + assert.equal(shouldOfferTeamSelection([{ status: 401 }], undefined), true); + assert.equal(shouldOfferTeamSelection([{ status: 403 }], undefined), true); +}); + +test("does not offer team selection once a team is named or the failure is unrelated", () => { + assert.equal(shouldOfferTeamSelection([{ status: 401 }], "team-a"), false); + assert.equal(shouldOfferTeamSelection([{ status: 404 }], undefined), false); + assert.equal(shouldOfferTeamSelection([{ status: 503 }], undefined), false); +}); + test("only accepts Competition and team snapshots with the same revision", () => { assert.equal( isConsistentTeamProgressSnapshot({ revision: 7 }, { revision: 7 }),