Files
lolympus-tournament-support/apps/api/src/modules/match/match-public.presenter.spec.ts
T

119 lines
3.7 KiB
TypeScript

import { Types } from 'mongoose';
import { presentPublicMatch } from './match-public.presenter';
describe('presentPublicMatch', () => {
it('whitelists recruiting fields and excludes result/code internals', () => {
const response = presentPublicMatch({
_id: oid('1'),
communityId: oid('2'),
competitionId: oid('3'),
shortCode: '33NW',
title: '내전',
joined: false,
description: '설명',
mapId: 11,
status: 'in-progress',
scheduledAt: new Date('2026-07-12T10:00:00.000Z'),
maxParticipants: 20,
gameCount: 3,
gameMode: 'double-elimination',
roundRobinMaxRounds: undefined,
hostUserId: oid('4'),
participants: [
{
userId: oid('5'),
puuid: 'public-roster-snapshot',
gameName: '선수',
tagLine: 'KR1',
profileIconId: 1,
tier: {
queueType: 'RANKED_SOLO_5x5',
tier: 'GOLD',
rank: 'I',
leaguePoints: 42,
wins: 10,
losses: 5,
fetchedAt: new Date('2026-07-10T00:00:00.000Z'),
puuid: 'secret-tier-puuid',
},
preferredPositions: [
{ position: 'MID', priority: 1 },
{ position: 'SUP', priority: 2 },
],
joinedAt: new Date('2026-07-01T00:00:00.000Z'),
excluded: false,
},
],
teams: [
{
teamIndex: 8,
name: '똥칼라파워',
captainUserId: oid('5'),
members: [{ userId: oid('5'), assignedPosition: 'MID', cost: 42 }],
},
],
prizes: ['상품'],
notices: ['안내'],
schedule: [{ time: '20:00', label: '시작' }],
createdAt: new Date('2026-07-01T00:00:00.000Z'),
updatedAt: new Date('2026-07-12T00:00:00.000Z'),
tournamentCodeIds: [oid('6')],
tournamentCodes: [{ code: 'SECRET' }],
result: { winnerTeamIndex: 3, games: [], seriesResults: [] },
doubleElimination: { bracketMatches: [{ winnerTeamIndex: 3 }] },
resultPollState: { state: 'polling' },
legacyImportSource: { triggeringPuuid: 'secret' },
});
expect(response).toMatchObject({
_id: oid('1').toString(),
communityId: oid('2').toString(),
competitionId: oid('3').toString(),
title: '내전',
doubleEliminationResetFinalEnabled: false,
scheduledAt: '2026-07-12T10:00:00.000Z',
participants: [
expect.objectContaining({
userId: oid('5').toString(),
joinedAt: '2026-07-01T00:00:00.000Z',
tier: {
queueType: 'RANKED_SOLO_5x5',
tier: 'GOLD',
rank: 'I',
leaguePoints: 42,
wins: 10,
losses: 5,
fetchedAt: '2026-07-10T00:00:00.000Z',
},
}),
],
teams: [
{
teamIndex: 8,
name: '똥칼라파워',
captainUserId: oid('5').toString(),
members: [
{
userId: oid('5').toString(),
assignedPosition: 'MID',
cost: 42,
},
],
},
],
});
expect(response).not.toHaveProperty('tournamentCodeIds');
expect(response).not.toHaveProperty('tournamentCodes');
expect(response).not.toHaveProperty('result');
expect(response).not.toHaveProperty('doubleElimination');
expect(response).not.toHaveProperty('resultPollState');
expect(response).not.toHaveProperty('legacyImportSource');
expect(response.participants[0]).not.toHaveProperty('puuid');
expect(response.participants[0]?.tier).not.toHaveProperty('puuid');
});
});
function oid(suffix: string) {
return new Types.ObjectId(suffix.padStart(24, '0'));
}