This commit is contained in:
dahyeon committed 2026-04-26 04:55:25 -07:00
1 parent ec2315cc3d
commit dfcfe9e4ad
3 files changed
+116 -3

No files matched your search

@@ -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();
@@ -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<string>([team.captainUserId.toString()]);
for (const member of team.members) {
userIds.add(member.userId.toString());
}
return userIds.size;
}
private async syncMatchTeamsFromAuction(
auction: AuctionDocument,
): Promise<void> {