fix: stabilize competition results flow
This commit is contained in:
1 parent
3bd3120eb1
commit
a88562b208
20 files changed
+411
-65
No files matched your search
@@ -66,7 +66,10 @@ describe('CompetitionCommandService', () => {
|
|||||||
$inc: { revision: 1 },
|
$inc: { revision: 1 },
|
||||||
$set: { projection: PROJECTION },
|
$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.abortTransaction).toHaveBeenCalledTimes(1);
|
||||||
expect(harness.session.commitTransaction).not.toHaveBeenCalled();
|
expect(harness.session.commitTransaction).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ export class CompetitionCommandService {
|
|||||||
phase: projection.phase,
|
phase: projection.phase,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ new: true, runValidators: true, session },
|
{ returnDocument: 'after', runValidators: true, session },
|
||||||
)
|
)
|
||||||
.lean()
|
.lean()
|
||||||
.exec();
|
.exec();
|
||||||
@@ -475,7 +475,7 @@ export class CompetitionCommandService {
|
|||||||
phase: projection.phase,
|
phase: projection.phase,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ new: true, runValidators: true, session },
|
{ returnDocument: 'after', runValidators: true, session },
|
||||||
)
|
)
|
||||||
.lean()
|
.lean()
|
||||||
.exec();
|
.exec();
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { ConflictException, ForbiddenException } from '@nestjs/common';
|
import {
|
||||||
|
ConflictException,
|
||||||
|
ForbiddenException,
|
||||||
|
NotFoundException,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { Types } from 'mongoose';
|
import { Types } from 'mongoose';
|
||||||
import { ConnectionService } from '../global/database/connection.service';
|
import { ConnectionService } from '../global/database/connection.service';
|
||||||
import { CompetitionQueryService } from './competition-query.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 () => {
|
it('does not reveal a team view to an authenticated non-participant', async () => {
|
||||||
const service = createService(createHarness());
|
const service = createService(createHarness());
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,17 @@ export interface CompetitionScope {
|
|||||||
matchId: mongoose.Types.ObjectId;
|
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 {
|
interface CompetitionProjectionSource {
|
||||||
series?: Array<Record<string, unknown>>;
|
series?: Array<Record<string, unknown>>;
|
||||||
gameSlots?: Array<Record<string, unknown>>;
|
gameSlots?: Array<Record<string, unknown>>;
|
||||||
@@ -68,15 +79,21 @@ export class CompetitionQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getTeamView(
|
public async getTeamView(
|
||||||
scope: CompetitionScope & { userId: mongoose.Types.ObjectId },
|
scope: TeamViewScope,
|
||||||
): Promise<TeamCompetitionViewResponse> {
|
): Promise<TeamCompetitionViewResponse> {
|
||||||
const competition = (await this.getCompetition(scope)) as Competition & {
|
const competition = (await this.getCompetition(scope)) as Competition & {
|
||||||
_id: PersistenceId;
|
_id: PersistenceId;
|
||||||
};
|
};
|
||||||
const team = competition.teams.find(({ members }) =>
|
const requestedTeamId = scope.teamId;
|
||||||
members.some(({ userId }) => sameId(userId, scope.userId)),
|
const team = requestedTeamId
|
||||||
);
|
? competition.teams.find(({ teamId }) => sameId(teamId, requestedTeamId))
|
||||||
|
: competition.teams.find(({ members }) =>
|
||||||
|
members.some(({ userId }) => sameId(userId, scope.userId)),
|
||||||
|
);
|
||||||
if (!team) {
|
if (!team) {
|
||||||
|
if (requestedTeamId) {
|
||||||
|
throw new NotFoundException('Competition team not found.');
|
||||||
|
}
|
||||||
throw new ForbiddenException(
|
throw new ForbiddenException(
|
||||||
'Only a Competition team member may access the team view.',
|
'Only a Competition team member may access the team view.',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { CompetitionController } from './competition.controller';
|
|||||||
import { CompetitionQueryService } from './competition-query.service';
|
import { CompetitionQueryService } from './competition-query.service';
|
||||||
|
|
||||||
describe('CompetitionController', () => {
|
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 { controller, queryService } = createHarness();
|
||||||
const response = { setHeader: jest.fn() };
|
const response = { setHeader: jest.fn() };
|
||||||
|
|
||||||
@@ -17,18 +17,14 @@ describe('CompetitionController', () => {
|
|||||||
response as never,
|
response as never,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
for (const method of ['getDetail', 'getTeamView'] as const) {
|
||||||
Reflect.getMetadata(
|
expect(
|
||||||
METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED,
|
Reflect.getMetadata(
|
||||||
CompetitionController.prototype.getDetail,
|
METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED,
|
||||||
),
|
CompetitionController.prototype[method],
|
||||||
).toBe(true);
|
),
|
||||||
expect(
|
).toBe(true);
|
||||||
Reflect.getMetadata(
|
}
|
||||||
METADATA_KEY_IS_PUBLIC_ACCESS_ALLOWED,
|
|
||||||
CompetitionController.prototype.getTeamView,
|
|
||||||
),
|
|
||||||
).not.toBe(true);
|
|
||||||
expect(response.setHeader).toHaveBeenCalledWith('ETag', '"7"');
|
expect(response.setHeader).toHaveBeenCalledWith('ETag', '"7"');
|
||||||
expect(result).toMatchObject({ revision: 7 });
|
expect(result).toMatchObject({ revision: 7 });
|
||||||
expect(queryService.getCompetition).toHaveBeenCalledWith({
|
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', () => {
|
it('protects audit and mutation endpoints with admin roles', () => {
|
||||||
for (const method of [
|
for (const method of [
|
||||||
'listFacts',
|
'listFacts',
|
||||||
|
|||||||
@@ -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')
|
@Get('team')
|
||||||
|
@AllowPublicAccess()
|
||||||
public async getTeamView(
|
public async getTeamView(
|
||||||
@CurrentUser() currentUser: UserDocument,
|
@CurrentUser() currentUser: UserDocument | undefined,
|
||||||
@Param('communityId', ParseObjectIdPipe)
|
@Param('communityId', ParseObjectIdPipe)
|
||||||
communityId: mongoose.Types.ObjectId,
|
communityId: mongoose.Types.ObjectId,
|
||||||
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
@Param('matchId', ParseObjectIdPipe) matchId: mongoose.Types.ObjectId,
|
||||||
|
@Query('teamId') requestedTeamId?: string,
|
||||||
@Res({ passthrough: true }) response?: Response,
|
@Res({ passthrough: true }) response?: Response,
|
||||||
): Promise<TeamCompetitionViewResponse> {
|
): Promise<TeamCompetitionViewResponse> {
|
||||||
return this.translate(async () => {
|
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({
|
const result = await this.queryService.getTeamView({
|
||||||
communityId,
|
communityId,
|
||||||
matchId,
|
matchId,
|
||||||
userId: currentUser._id,
|
...(teamId ? { teamId } : { userId: currentUser!._id }),
|
||||||
});
|
});
|
||||||
response?.setHeader('ETag', revisionEtag(result.revision));
|
response?.setHeader('ETag', revisionEtag(result.revision));
|
||||||
return result;
|
return result;
|
||||||
@@ -298,6 +314,21 @@ function requireCommandHeaders(
|
|||||||
return revision;
|
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 {
|
function requireRevisionHeader(ifMatch: string | undefined): number {
|
||||||
const revision = parseRevision(ifMatch);
|
const revision = parseRevision(ifMatch);
|
||||||
if (revision === undefined) {
|
if (revision === undefined) {
|
||||||
|
|||||||
@@ -1,9 +1,75 @@
|
|||||||
|
import mongoose from 'mongoose';
|
||||||
import {
|
import {
|
||||||
|
ConnectionService,
|
||||||
resolveMongoAppName,
|
resolveMongoAppName,
|
||||||
resolveMongoConnectionOptions,
|
resolveMongoConnectionOptions,
|
||||||
resolveMongoDbName,
|
resolveMongoDbName,
|
||||||
} from './connection.service';
|
} from './connection.service';
|
||||||
|
|
||||||
|
function createFakeConnection(connectionId: string) {
|
||||||
|
const models: Record<string, unknown> = {};
|
||||||
|
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', () => {
|
describe('resolveMongoDbName', () => {
|
||||||
it('uses production database only for prod', () => {
|
it('uses production database only for prod', () => {
|
||||||
expect(resolveMongoDbName('prod')).toBe('lolympus');
|
expect(resolveMongoDbName('prod')).toBe('lolympus');
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export function resolveMongoConnectionOptions(
|
|||||||
export class ConnectionService implements OnModuleInit {
|
export class ConnectionService implements OnModuleInit {
|
||||||
private readonly logger = new Logger(ConnectionService.name);
|
private readonly logger = new Logger(ConnectionService.name);
|
||||||
private connection: mongoose.Connection | null = null;
|
private connection: mongoose.Connection | null = null;
|
||||||
|
private connectionPromise: Promise<mongoose.Connection> | null = null;
|
||||||
constructor(private readonly secretService: SecretService) {}
|
constructor(private readonly secretService: SecretService) {}
|
||||||
|
|
||||||
private tournamentModels: Map<string, mongoose.Model<any>> | null = null;
|
private tournamentModels: Map<string, mongoose.Model<any>> | null = null;
|
||||||
@@ -51,35 +52,49 @@ export class ConnectionService implements OnModuleInit {
|
|||||||
return this.connection;
|
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<mongoose.Connection> {
|
||||||
const connectionString = await this.secretService.get(
|
const connectionString = await this.secretService.get(
|
||||||
'MONGODB_CONNECTION_STRING',
|
'MONGODB_CONNECTION_STRING',
|
||||||
);
|
);
|
||||||
const dbName = resolveMongoDbName();
|
const dbName = resolveMongoDbName();
|
||||||
const appName = resolveMongoAppName();
|
const appName = resolveMongoAppName();
|
||||||
const connectionOptions = resolveMongoConnectionOptions(dbName, appName);
|
const connectionOptions = resolveMongoConnectionOptions(dbName, appName);
|
||||||
const defaultConnection = await mongoose
|
const connection = await mongoose
|
||||||
.createConnection(connectionString, connectionOptions)
|
.createConnection(connectionString, connectionOptions)
|
||||||
.asPromise();
|
.asPromise();
|
||||||
this.connection = defaultConnection;
|
|
||||||
|
this.connection = connection;
|
||||||
|
this.tournamentModels = null;
|
||||||
this.logger.log(
|
this.logger.log(
|
||||||
`MongoDB connection created. dbName=${dbName} appName=${appName} autoIndex=${
|
`MongoDB connection created. dbName=${dbName} appName=${appName} autoIndex=${
|
||||||
connectionOptions.autoIndex === true
|
connectionOptions.autoIndex === true
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getModel<K extends keyof TournamentModelTypes>(
|
public async getModel<K extends keyof TournamentModelTypes>(
|
||||||
modelKey: K,
|
modelKey: K,
|
||||||
): Promise<mongoose.Model<TournamentModelTypes[K]>> {
|
): Promise<mongoose.Model<TournamentModelTypes[K]>> {
|
||||||
|
const connection = await this.getConnection();
|
||||||
if (this.tournamentModels)
|
if (this.tournamentModels)
|
||||||
return this.tournamentModels.get(modelKey) as mongoose.Model<
|
return this.tournamentModels.get(modelKey) as mongoose.Model<
|
||||||
TournamentModelTypes[K]
|
TournamentModelTypes[K]
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const models = new Map<K, mongoose.Model<TournamentModelTypes[K]>>();
|
const models = new Map<K, mongoose.Model<TournamentModelTypes[K]>>();
|
||||||
const connection = await this.getConnection();
|
|
||||||
|
|
||||||
tournamentModelDefinitions.forEach((modelDefinition) => {
|
tournamentModelDefinitions.forEach((modelDefinition) => {
|
||||||
applyMongoosePerformancePlugin(modelDefinition.schema);
|
applyMongoosePerformancePlugin(modelDefinition.schema);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ describe('CompetitionAssignmentProvisioner', () => {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
new: true,
|
returnDocument: 'after',
|
||||||
session: harness.session,
|
session: harness.session,
|
||||||
sort: { expiresAt: 1 },
|
sort: { expiresAt: 1 },
|
||||||
}),
|
}),
|
||||||
@@ -122,14 +122,14 @@ describe('CompetitionAssignmentProvisioner', () => {
|
|||||||
expect(harness.assignmentModel.findOneAndUpdate).toHaveBeenCalledWith(
|
expect(harness.assignmentModel.findOneAndUpdate).toHaveBeenCalledWith(
|
||||||
{ _id: assignmentId, state: 'reserved' },
|
{ _id: assignmentId, state: 'reserved' },
|
||||||
{ $set: expect.objectContaining({ state: 'released' }) },
|
{ $set: expect.objectContaining({ state: 'released' }) },
|
||||||
{ new: true, session: harness.session },
|
{ returnDocument: 'after', session: harness.session },
|
||||||
);
|
);
|
||||||
expect(harness.codeModel.findOneAndUpdate).toHaveBeenCalledWith(
|
expect(harness.codeModel.findOneAndUpdate).toHaveBeenCalledWith(
|
||||||
{ _id: harness.codeId, state: 'reserved' },
|
{ _id: harness.codeId, state: 'reserved' },
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
$set: expect.objectContaining({ state: 'released' }),
|
$set: expect.objectContaining({ state: 'released' }),
|
||||||
}),
|
}),
|
||||||
{ new: true, session: harness.session },
|
{ returnDocument: 'after', session: harness.session },
|
||||||
);
|
);
|
||||||
expect(harness.matchModel.updateOne).toHaveBeenCalledWith(
|
expect(harness.matchModel.updateOne).toHaveBeenCalledWith(
|
||||||
{ _id: harness.matchId },
|
{ _id: harness.matchId },
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export class CompetitionAssignmentProvisioner {
|
|||||||
const assignment = (await params.AssignmentModel.findOneAndUpdate(
|
const assignment = (await params.AssignmentModel.findOneAndUpdate(
|
||||||
{ _id: params.assignment._id, state: 'reserved' },
|
{ _id: params.assignment._id, state: 'reserved' },
|
||||||
{ $set: { state: 'released', releasedAt } },
|
{ $set: { state: 'released', releasedAt } },
|
||||||
{ new: true, session },
|
{ returnDocument: 'after', session },
|
||||||
).exec()) as AssignmentRecord | null;
|
).exec()) as AssignmentRecord | null;
|
||||||
if (!assignment) {
|
if (!assignment) {
|
||||||
await session.commitTransaction();
|
await session.commitTransaction();
|
||||||
@@ -173,7 +173,7 @@ export class CompetitionAssignmentProvisioner {
|
|||||||
reservedAt: 1,
|
reservedAt: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ new: true, session },
|
{ returnDocument: 'after', session },
|
||||||
).exec()) as CodeRecord | null;
|
).exec()) as CodeRecord | null;
|
||||||
if (!code) {
|
if (!code) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -354,7 +354,7 @@ export class CompetitionAssignmentProvisioner {
|
|||||||
gameNumber: params.displayNumber,
|
gameNumber: params.displayNumber,
|
||||||
},
|
},
|
||||||
{ $set: { gameNumber: params.displayNumber } },
|
{ $set: { gameNumber: params.displayNumber } },
|
||||||
{ new: true, session: params.session },
|
{ returnDocument: 'after', session: params.session },
|
||||||
).exec()) as CodeRecord | null;
|
).exec()) as CodeRecord | null;
|
||||||
if (promoted) return promoted;
|
if (promoted) return promoted;
|
||||||
}
|
}
|
||||||
@@ -377,7 +377,11 @@ export class CompetitionAssignmentProvisioner {
|
|||||||
reservedAt: new Date(),
|
reservedAt: new Date(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ new: true, session: params.session, sort: { expiresAt: 1 } },
|
{
|
||||||
|
returnDocument: 'after',
|
||||||
|
session: params.session,
|
||||||
|
sort: { expiresAt: 1 },
|
||||||
|
},
|
||||||
).exec()) as CodeRecord | null;
|
).exec()) as CodeRecord | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export class CompetitionOutboxProcessor
|
|||||||
$unset: { lastError: 1 },
|
$unset: { lastError: 1 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
new: true,
|
returnDocument: 'after',
|
||||||
sort: { availableAt: 1, revision: 1, _id: 1 },
|
sort: { availableAt: 1, revision: 1, _id: 1 },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -257,12 +257,15 @@ export function useCompetition(
|
|||||||
export function useTeamCompetition(
|
export function useTeamCompetition(
|
||||||
matchId: string | undefined,
|
matchId: string | undefined,
|
||||||
communityId = DEFAULT_COMMUNITY_ID,
|
communityId = DEFAULT_COMMUNITY_ID,
|
||||||
|
teamId?: string,
|
||||||
) {
|
) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['competition-team', communityId, matchId ?? null],
|
queryKey: ['competition-team', communityId, matchId ?? null, teamId ?? null],
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
apiFetch<TeamCompetitionViewResponse>(
|
apiFetch<TeamCompetitionViewResponse>(
|
||||||
`/communities/${communityId}/matches/${matchId}/competition/team`,
|
`/communities/${communityId}/matches/${matchId}/competition/team${
|
||||||
|
teamId ? `?teamId=${encodeURIComponent(teamId)}` : ''
|
||||||
|
}`,
|
||||||
),
|
),
|
||||||
enabled: Boolean(communityId && matchId),
|
enabled: Boolean(communityId && matchId),
|
||||||
retry: false,
|
retry: false,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function CompetitionResults({
|
|||||||
to={`/match/${competition.matchId}/team`}
|
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"
|
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"
|
||||||
>
|
>
|
||||||
내 팀 진행
|
팀 진행
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
DoubleEliminationBracketLayout,
|
DoubleEliminationBracketLayout,
|
||||||
} from "./double-elimination-bracket-layout";
|
} from "./double-elimination-bracket-layout";
|
||||||
import { DOUBLE_ELIMINATION_BRACKET_GEOMETRY } 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 { DoubleEliminationMobileBracket } from "./DoubleEliminationMobileBracket";
|
||||||
import { SeriesScoreCard } from "./SeriesScoreCard";
|
import { SeriesScoreCard } from "./SeriesScoreCard";
|
||||||
|
|
||||||
@@ -57,7 +58,9 @@ function DesktopBracket({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="hidden xl:block">
|
<div
|
||||||
|
className={`hidden xl:block ${DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS}`}
|
||||||
|
>
|
||||||
<div className="mb-2 flex flex-wrap items-center justify-between gap-3 text-xs text-content-muted">
|
<div className="mb-2 flex flex-wrap items-center justify-between gap-3 text-xs text-content-muted">
|
||||||
<p>
|
<p>
|
||||||
승자조와 패자조는 같은 시간축을 공유하며 오른쪽 결승에서 합류합니다.
|
승자조와 패자조는 같은 시간축을 공유하며 오른쪽 결승에서 합류합니다.
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import type {
|
import type { CompetitionDetailResponse } from "@lolympus/contracts";
|
||||||
CompetitionDetailResponse,
|
|
||||||
MatchGameMode,
|
|
||||||
} from "@lolympus/contracts";
|
|
||||||
import { createDoubleEliminationBracketLayout } from "./double-elimination-bracket-layout.ts";
|
import { createDoubleEliminationBracketLayout } from "./double-elimination-bracket-layout.ts";
|
||||||
|
|
||||||
export function matchPageMaxWidthClass(gameMode: MatchGameMode): string {
|
export const MATCH_PAGE_MAX_WIDTH_CLASS = "max-w-5xl";
|
||||||
return gameMode === "double-elimination" ? "max-w-[1600px]" : "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(
|
export function createCompetitionBracketLayout(
|
||||||
competition: CompetitionDetailResponse,
|
competition: CompetitionDetailResponse,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
import { RankBadge } from "../components/RankBadge";
|
import { RankBadge } from "../components/RankBadge";
|
||||||
import { CompetitionAdminControls } from "../components/competition/CompetitionAdminControls";
|
import { CompetitionAdminControls } from "../components/competition/CompetitionAdminControls";
|
||||||
import { CompetitionResults } from "../components/competition/CompetitionResults";
|
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 { DEFAULT_COMMUNITY_ID, useAuthUserId } from "../config";
|
||||||
import { apiFetch, ApiError } from "../lib/api";
|
import { apiFetch, ApiError } from "../lib/api";
|
||||||
import { profileIconUrl } from "../lib/ddragon";
|
import { profileIconUrl } from "../lib/ddragon";
|
||||||
@@ -1795,7 +1795,7 @@ export default function MatchDetailPage() {
|
|||||||
return (
|
return (
|
||||||
<main
|
<main
|
||||||
className={`mx-auto px-4 py-6 sm:px-6 ${
|
className={`mx-auto px-4 py-6 sm:px-6 ${
|
||||||
matchPageMaxWidthClass(matchQuery.data.gameMode)
|
MATCH_PAGE_MAX_WIDTH_CLASS
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
|
import type { CompetitionDetailResponse } from "@lolympus/contracts";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { Link, useParams } from "react-router";
|
import { Link, useParams, useSearchParams } from "react-router";
|
||||||
import { useCompetition, useTeamCompetition } from "../api/hooks";
|
import { useCompetition, useTeamCompetition } from "../api/hooks";
|
||||||
import { SeriesScoreCard } from "../components/competition/SeriesScoreCard";
|
import { SeriesScoreCard } from "../components/competition/SeriesScoreCard";
|
||||||
import { DEFAULT_COMMUNITY_ID } from "../config";
|
import { DEFAULT_COMMUNITY_ID } from "../config";
|
||||||
import {
|
import {
|
||||||
getTeamProgressErrorContent,
|
getTeamProgressErrorContent,
|
||||||
isConsistentTeamProgressSnapshot,
|
isConsistentTeamProgressSnapshot,
|
||||||
|
shouldOfferTeamSelection,
|
||||||
type TeamProgressErrorContent,
|
type TeamProgressErrorContent,
|
||||||
} from "./match-team-progress-state";
|
} from "./match-team-progress-state";
|
||||||
|
|
||||||
export default function MatchTeamProgressPage() {
|
export default function MatchTeamProgressPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const selectedTeamId = searchParams.get("teamId") ?? undefined;
|
||||||
|
const isSelectingTeam = !selectedTeamId && searchParams.get("select") === "1";
|
||||||
const competitionQuery = useCompetition(id, DEFAULT_COMMUNITY_ID);
|
const competitionQuery = useCompetition(id, DEFAULT_COMMUNITY_ID);
|
||||||
const teamQuery = useTeamCompetition(id, DEFAULT_COMMUNITY_ID);
|
const teamQuery = useTeamCompetition(
|
||||||
|
id,
|
||||||
|
DEFAULT_COMMUNITY_ID,
|
||||||
|
selectedTeamId,
|
||||||
|
);
|
||||||
const refetchCompetition = competitionQuery.refetch;
|
const refetchCompetition = competitionQuery.refetch;
|
||||||
const refetchTeam = teamQuery.refetch;
|
const refetchTeam = teamQuery.refetch;
|
||||||
const [copiedSlotId, setCopiedSlotId] = useState<string | null>(null);
|
const [copiedSlotId, setCopiedSlotId] = useState<string | null>(null);
|
||||||
@@ -63,11 +72,24 @@ export default function MatchTeamProgressPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSelectingTeam && competition) {
|
||||||
|
return <TeamSelectionState competition={competition} matchId={id} />;
|
||||||
|
}
|
||||||
|
|
||||||
if (competitionQuery.isLoading || teamQuery.isLoading) {
|
if (competitionQuery.isLoading || teamQuery.isLoading) {
|
||||||
return <TeamProgressLoadingState />;
|
return <TeamProgressLoadingState />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasQueryError) {
|
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 <TeamSelectionState competition={competition} matchId={id} />;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<TeamProgressProblemState
|
<TeamProgressProblemState
|
||||||
content={getTeamProgressErrorContent(
|
content={getTeamProgressErrorContent(
|
||||||
@@ -142,12 +164,20 @@ export default function MatchTeamProgressPage() {
|
|||||||
|
|
||||||
<header className="mb-6 border-b border-base-content/10 pb-5">
|
<header className="mb-6 border-b border-base-content/10 pb-5">
|
||||||
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
||||||
My Competition
|
{selectedTeamId ? "Team Competition" : "My Competition"}
|
||||||
</p>
|
</p>
|
||||||
<h1 className="mt-1 text-2xl font-black">{team?.name ?? "내 팀"}</h1>
|
<h1 className="mt-1 text-2xl font-black">
|
||||||
|
{team?.name ?? (selectedTeamId ? "팀" : "내 팀")}
|
||||||
|
</h1>
|
||||||
<p className="mt-1 text-sm text-base-content/45">
|
<p className="mt-1 text-sm text-base-content/45">
|
||||||
우리 팀의 공식 대진과 토너먼트 코드는 이 페이지에서만 표시됩니다.
|
해당 팀의 공식 대진과 토너먼트 코드가 표시됩니다.
|
||||||
</p>
|
</p>
|
||||||
|
<Link
|
||||||
|
to={`/match/${id}/team?select=1`}
|
||||||
|
className="mt-2 inline-flex text-xs text-base-content/40 hover:text-primary"
|
||||||
|
>
|
||||||
|
다른 팀 보기
|
||||||
|
</Link>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section className="mb-6" aria-labelledby="active-series-heading">
|
<section className="mb-6" aria-labelledby="active-series-heading">
|
||||||
@@ -279,6 +309,57 @@ export default function MatchTeamProgressPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TeamSelectionState({
|
||||||
|
competition,
|
||||||
|
matchId,
|
||||||
|
}: {
|
||||||
|
competition: CompetitionDetailResponse;
|
||||||
|
matchId: string | undefined;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<main className="mx-auto max-w-5xl px-4 py-6 sm:px-6">
|
||||||
|
<Link
|
||||||
|
to={`/match/${matchId}`}
|
||||||
|
className="mb-5 inline-flex text-xs text-base-content/40 hover:text-base-content"
|
||||||
|
>
|
||||||
|
← 내전 상세로
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<header className="mb-6 border-b border-base-content/10 pb-5">
|
||||||
|
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
||||||
|
Team Competition
|
||||||
|
</p>
|
||||||
|
<h1 className="mt-1 text-2xl font-black">팀 선택</h1>
|
||||||
|
<p className="mt-1 text-sm text-base-content/45">
|
||||||
|
진행 상황과 토너먼트 코드를 확인할 팀을 선택해 주세요.
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{competition.teams.length > 0 ? (
|
||||||
|
<ul className="grid gap-3 sm:grid-cols-2">
|
||||||
|
{competition.teams.map((team) => (
|
||||||
|
<li key={team.teamId}>
|
||||||
|
<Link
|
||||||
|
to={`/match/${matchId}/team?teamId=${team.teamId}`}
|
||||||
|
className="flex items-center justify-between gap-3 border border-base-content/10 bg-base-100 px-4 py-4 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
||||||
|
>
|
||||||
|
<span className="min-w-0 truncate text-sm font-bold">
|
||||||
|
{team.name}
|
||||||
|
</span>
|
||||||
|
<span className="shrink-0 text-xs text-base-content/35">
|
||||||
|
{team.members.length}명
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : (
|
||||||
|
<EmptyState message="구성된 팀이 없습니다." />
|
||||||
|
)}
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function TeamProgressLoadingState() {
|
function TeamProgressLoadingState() {
|
||||||
return (
|
return (
|
||||||
<main
|
<main
|
||||||
|
|||||||
@@ -26,15 +26,24 @@ export function isConsistentTeamProgressSnapshot(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A visitor who is not signed in (401) — or is signed in but belongs to no team
|
||||||
|
* in this Competition (403) — can still read a team view by naming the team.
|
||||||
|
* Offer the team picker instead of an error until they have named one.
|
||||||
|
*/
|
||||||
|
export function shouldOfferTeamSelection(
|
||||||
|
errors: readonly unknown[],
|
||||||
|
selectedTeamId: string | undefined,
|
||||||
|
): boolean {
|
||||||
|
if (selectedTeamId) return false;
|
||||||
|
const statuses = errorStatuses(errors);
|
||||||
|
return statuses.includes(401) || statuses.includes(403);
|
||||||
|
}
|
||||||
|
|
||||||
export function getTeamProgressErrorContent(
|
export function getTeamProgressErrorContent(
|
||||||
errors: readonly unknown[],
|
errors: readonly unknown[],
|
||||||
): TeamProgressErrorContent {
|
): TeamProgressErrorContent {
|
||||||
const statuses = errors.flatMap((error) => {
|
const statuses = errorStatuses(errors);
|
||||||
if (typeof error !== "object" || error === null || !("status" in error)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return typeof error.status === "number" ? [error.status] : [];
|
|
||||||
});
|
|
||||||
|
|
||||||
if (statuses.includes(401)) {
|
if (statuses.includes(401)) {
|
||||||
return {
|
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 {
|
function isNetworkError(error: unknown): boolean {
|
||||||
return (
|
return (
|
||||||
error instanceof TypeError ||
|
error instanceof TypeError ||
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ import type {
|
|||||||
TeamId,
|
TeamId,
|
||||||
} from "@lolympus/contracts";
|
} from "@lolympus/contracts";
|
||||||
import {
|
import {
|
||||||
|
DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS,
|
||||||
|
MATCH_PAGE_MAX_WIDTH_CLASS,
|
||||||
createCompetitionBracketLayout,
|
createCompetitionBracketLayout,
|
||||||
matchPageMaxWidthClass,
|
|
||||||
} from "../src/components/competition/competition-display-layout.ts";
|
} from "../src/components/competition/competition-display-layout.ts";
|
||||||
import {
|
import {
|
||||||
createDoubleEliminationBracketLayout,
|
createDoubleEliminationBracketLayout,
|
||||||
@@ -83,10 +84,13 @@ test("places the canonical four-team DAG in shared time columns", () => {
|
|||||||
assert.equal(nodeFor(layout, ids.GF).lane, "final");
|
assert.equal(nodeFor(layout, ids.GF).lane, "final");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("selects the wide page grid only for double-elimination matches", () => {
|
test("keeps the match page narrow and gives only the desktop bracket a wide viewport", () => {
|
||||||
assert.equal(matchPageMaxWidthClass("double-elimination"), "max-w-[1600px]");
|
assert.equal(MATCH_PAGE_MAX_WIDTH_CLASS, "max-w-5xl");
|
||||||
assert.equal(matchPageMaxWidthClass("pair"), "max-w-5xl");
|
assert.match(DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS, /max-w-\[1600px\]/);
|
||||||
assert.equal(matchPageMaxWidthClass("round-robin"), "max-w-5xl");
|
assert.match(
|
||||||
|
DOUBLE_ELIMINATION_BRACKET_VIEWPORT_CLASS,
|
||||||
|
/w-\[calc\(100vw-3rem\)\]/,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("selects the bracket only for a coherent double-elimination snapshot", () => {
|
test("selects the bracket only for a coherent double-elimination snapshot", () => {
|
||||||
|
|||||||
@@ -3,8 +3,20 @@ import test from "node:test";
|
|||||||
import {
|
import {
|
||||||
getTeamProgressErrorContent,
|
getTeamProgressErrorContent,
|
||||||
isConsistentTeamProgressSnapshot,
|
isConsistentTeamProgressSnapshot,
|
||||||
|
shouldOfferTeamSelection,
|
||||||
} from "../src/pages/match-team-progress-state.ts";
|
} 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", () => {
|
test("only accepts Competition and team snapshots with the same revision", () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
isConsistentTeamProgressSnapshot({ revision: 7 }, { revision: 7 }),
|
isConsistentTeamProgressSnapshot({ revision: 7 }, { revision: 7 }),
|
||||||
|
|||||||
Reference in new issue
Block a user