From dfcfe9e4addd78f2d16d3290ca3695ee031f65d9 Mon Sep 17 00:00:00 2001 From: dahyeon Date: Sun, 26 Apr 2026 04:55:25 -0700 Subject: [PATCH] . --- .../modules/auction/auction.service.spec.ts | 65 +++++++++++++++++++ .../src/modules/auction/auction.service.ts | 27 ++++++++ apps/web/src/pages/AuctionPage.tsx | 27 +++++++- 3 files changed, 116 insertions(+), 3 deletions(-) diff --git a/apps/api/src/modules/auction/auction.service.spec.ts b/apps/api/src/modules/auction/auction.service.spec.ts index 298f361e..4770a993 100644 --- a/apps/api/src/modules/auction/auction.service.spec.ts +++ b/apps/api/src/modules/auction/auction.service.spec.ts @@ -20,6 +20,71 @@ describe('AuctionService', () => { }; } + function createFullTeam(side: 'blue' | 'red') { + return { + side, + captainUserId: new mongoose.Types.ObjectId(), + points: 100, + members: Array.from({ length: 4 }, () => ({ + userId: new mongoose.Types.ObjectId(), + assignedPosition: 'MID', + cost: 10, + })), + }; + } + + it('rejects bids when the team already has 5 members including captain', async () => { + const matchId = new mongoose.Types.ObjectId(); + const auction = { + phase: 'bidding', + teams: [createFullTeam('blue'), createFullTeam('red')], + currentBid: 10, + save: jest.fn().mockResolvedValue(undefined), + }; + const { service } = createService({ + auction: { + findOne: jest.fn().mockResolvedValue(auction), + }, + }); + + await expect( + service.placeBid({ + matchId, + side: 'blue', + amount: 20, + }), + ).rejects.toThrow('Team already has maximum members.'); + expect(auction.save).not.toHaveBeenCalled(); + }); + + it('rejects sold confirmation when the winning team is already full', async () => { + const matchId = new mongoose.Types.ObjectId(); + const auction = { + phase: 'bidding', + currentBidder: 'blue', + currentBid: 20, + currentIndex: 0, + order: [ + { + userId: new mongoose.Types.ObjectId(), + preferredPositions: [{ position: 'ADC', priority: 1 }], + }, + ], + teams: [createFullTeam('blue'), createFullTeam('red')], + save: jest.fn().mockResolvedValue(undefined), + }; + const { service } = createService({ + auction: { + findOne: jest.fn().mockResolvedValue(auction), + }, + }); + + await expect(service.markSold({ matchId })).rejects.toThrow( + 'Team already has maximum members.', + ); + expect(auction.save).not.toHaveBeenCalled(); + }); + it('syncs completed auction teams into the match document', async () => { const matchId = new mongoose.Types.ObjectId(); const blueCaptainId = new mongoose.Types.ObjectId(); diff --git a/apps/api/src/modules/auction/auction.service.ts b/apps/api/src/modules/auction/auction.service.ts index 3968e475..e8c5122c 100644 --- a/apps/api/src/modules/auction/auction.service.ts +++ b/apps/api/src/modules/auction/auction.service.ts @@ -9,12 +9,15 @@ import { ConnectionService } from '../global/database/connection.service'; import { AuctionDocument, AuctionPlayerSnapshot, + AuctionTeam, MatchTeamMember, Position, TeamSide, } from '../global/database/schema'; import { RiotAccountEnrichmentService } from '../riot/riot-account-enrichment.service'; +const AUCTION_MAX_TEAM_SIZE = 5; + interface StartAuctionParams { matchId: mongoose.Types.ObjectId; communityId: mongoose.Types.ObjectId; @@ -71,6 +74,14 @@ export class AuctionService { 'Both captains must be participants of the match.', ); } + if ( + match.participants.length > + params.captains.length * AUCTION_MAX_TEAM_SIZE + ) { + throw new BadRequestException( + 'Auction supports up to 5 members per team including captains.', + ); + } const basePlayerUsers = await UserModel.find({ _id: { @@ -204,6 +215,7 @@ export class AuctionService { if (params.amount > team.points) { throw new BadRequestException('Bid exceeds team points.'); } + this.assertTeamHasSlot(team); // 임시 운영용: 클라이언트에서 선택한 팀장 모드를 신뢰하고 실제 로그인 사용자 검증은 건너뛴다. auction.currentBid = params.amount; @@ -231,6 +243,7 @@ export class AuctionService { } const team = auction.teams.find((t) => t.side === auction.currentBidder); if (!team) throw new BadRequestException('Winning team not found.'); + this.assertTeamHasSlot(team); const current = auction.order[auction.currentIndex]; if (!current) throw new BadRequestException('No current player.'); @@ -327,6 +340,20 @@ export class AuctionService { return Math.max(5, remainingSeconds); } + private assertTeamHasSlot(team: AuctionTeam): void { + if (this.countTeamMembersIncludingCaptain(team) >= AUCTION_MAX_TEAM_SIZE) { + throw new BadRequestException('Team already has maximum members.'); + } + } + + private countTeamMembersIncludingCaptain(team: AuctionTeam): number { + const userIds = new Set([team.captainUserId.toString()]); + for (const member of team.members) { + userIds.add(member.userId.toString()); + } + return userIds.size; + } + private async syncMatchTeamsFromAuction( auction: AuctionDocument, ): Promise { diff --git a/apps/web/src/pages/AuctionPage.tsx b/apps/web/src/pages/AuctionPage.tsx index 8332f6c0..d0cae437 100644 --- a/apps/web/src/pages/AuctionPage.tsx +++ b/apps/web/src/pages/AuctionPage.tsx @@ -26,6 +26,7 @@ function formatPoints(value: number) { return value.toLocaleString(); } +const AUCTION_MAX_TEAM_SIZE = 5; const LANE_ROWS: Position[] = ['TOP', 'JGL', 'MID', 'ADC', 'SUP']; const POSITION_TO_RIOT_LANE = { TOP: 'TOP', @@ -194,6 +195,8 @@ function TeamPanel({ const accentBar = team.side === 'blue' ? 'bg-blue-500' : 'bg-red-500'; const sideColor = team.side === 'blue' ? 'text-blue-400' : 'text-red-400'; const headerBg = team.side === 'blue' ? 'bg-blue-500/8' : 'bg-red-500/8'; + const teamSize = team.members.length + 1; + const isFull = teamSize >= AUCTION_MAX_TEAM_SIZE; return (
+
+ + 팀장 포함 {teamSize}/{AUCTION_MAX_TEAM_SIZE} + + {isFull && 정원 완료} +
@@ -247,7 +256,9 @@ function TeamPanel({ )) )} - {Array.from({ length: Math.max(0, 4 - team.members.length) }).map((_, index) => ( + {Array.from({ + length: Math.max(0, AUCTION_MAX_TEAM_SIZE - 1 - team.members.length), + }).map((_, index) => (
= AUCTION_MAX_TEAM_SIZE; useEffect(() => { setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10)); @@ -420,6 +433,7 @@ function BidControls({
);