.
This commit is contained in:
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> {
|
||||
|
||||
@@ -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 (
|
||||
<div
|
||||
@@ -216,6 +219,12 @@ function TeamPanel({
|
||||
{formatPoints(team.points)}P
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-1 flex items-center justify-between text-[10px]">
|
||||
<span className="text-base-content/25">
|
||||
팀장 포함 {teamSize}/{AUCTION_MAX_TEAM_SIZE}
|
||||
</span>
|
||||
{isFull && <span className="font-bold text-amber-400">정원 완료</span>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="divide-y divide-base-content/5">
|
||||
@@ -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) => (
|
||||
<div
|
||||
key={`empty-${team.side}-${index}`}
|
||||
className="px-3 py-1.5 h-[34px] flex items-center"
|
||||
@@ -396,6 +407,8 @@ function BidControls({
|
||||
: captainSide === 'red'
|
||||
? state.teams[1]
|
||||
: null;
|
||||
const activeTeamSize = activeTeam ? activeTeam.members.length + 1 : 0;
|
||||
const isActiveTeamFull = activeTeamSize >= AUCTION_MAX_TEAM_SIZE;
|
||||
|
||||
useEffect(() => {
|
||||
setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10));
|
||||
@@ -420,6 +433,7 @@ function BidControls({
|
||||
<button
|
||||
key={preset}
|
||||
onClick={() => setBidAmount(Math.max(minBid, preset))}
|
||||
disabled={isActiveTeamFull}
|
||||
className={`text-[11px] px-2.5 py-1 border transition-colors ${
|
||||
bidAmount === preset
|
||||
? 'border-primary/40 bg-primary/10 text-primary'
|
||||
@@ -436,19 +450,26 @@ function BidControls({
|
||||
setBidAmount(Math.max(minBid, Number(event.target.value)))
|
||||
}
|
||||
min={minBid}
|
||||
disabled={isActiveTeamFull}
|
||||
className="w-24 text-xs px-2 py-1 border border-base-content/10 bg-transparent text-base-content tabular-nums text-right focus:outline-none focus:border-primary/30"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => onBid(activeTeam.side, bidAmount)}
|
||||
disabled={bidAmount > activeTeam.points || bidAmount <= state.currentBid}
|
||||
disabled={
|
||||
isActiveTeamFull ||
|
||||
bidAmount > activeTeam.points ||
|
||||
bidAmount <= state.currentBid
|
||||
}
|
||||
className={`w-full py-2 text-xs font-bold uppercase tracking-wide border transition-colors disabled:opacity-30 disabled:cursor-not-allowed ${
|
||||
activeTeam.side === 'blue'
|
||||
? 'border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20'
|
||||
: 'border-red-500/30 bg-red-500/10 text-red-400 hover:bg-red-500/20'
|
||||
}`}
|
||||
>
|
||||
{activeTeam.side === 'blue' ? '블루팀' : '레드팀'} 입찰 ({formatPoints(bidAmount)}P)
|
||||
{isActiveTeamFull
|
||||
? `${activeTeam.side === 'blue' ? '블루팀' : '레드팀'} 정원 완료 (${activeTeamSize}/${AUCTION_MAX_TEAM_SIZE})`
|
||||
: `${activeTeam.side === 'blue' ? '블루팀' : '레드팀'} 입찰 (${formatPoints(bidAmount)}P)`}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user