fix: reserve auction points for remaining slots
This commit is contained in:
1 parent
bac29ac933
commit
b0dc857463
3 files changed
+175
-20
No files matched your search
@@ -459,6 +459,91 @@ describe('AuctionService', () => {
|
|||||||
expect(auction.save).not.toHaveBeenCalled();
|
expect(auction.save).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('rejects bids that do not reserve minimum points for remaining team slots', async () => {
|
||||||
|
const matchId = new mongoose.Types.ObjectId();
|
||||||
|
const auction = {
|
||||||
|
_id: new mongoose.Types.ObjectId(),
|
||||||
|
matchId,
|
||||||
|
phase: 'bidding',
|
||||||
|
teams: [
|
||||||
|
{
|
||||||
|
teamIndex: 1,
|
||||||
|
captainUserId: new mongoose.Types.ObjectId(),
|
||||||
|
points: 1000,
|
||||||
|
members: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
currentBid: 100,
|
||||||
|
currentDeadline: new Date(),
|
||||||
|
maxTimerSeconds: 30,
|
||||||
|
bidExtensionSeconds: 5,
|
||||||
|
bids: [],
|
||||||
|
save: jest.fn().mockResolvedValue(undefined),
|
||||||
|
toObject: jest.fn().mockReturnValue({ _id: 'auction', matchId }),
|
||||||
|
};
|
||||||
|
const { service } = createService({
|
||||||
|
auction: {
|
||||||
|
findOne: jest.fn().mockResolvedValue(auction),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.placeBid({
|
||||||
|
matchId,
|
||||||
|
teamIndex: 1,
|
||||||
|
amount: 980,
|
||||||
|
}),
|
||||||
|
).rejects.toThrow('Bid must reserve minimum points for remaining slots.');
|
||||||
|
expect(auction.save).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows bids up to the maximum after reserving minimum points', async () => {
|
||||||
|
const matchId = new mongoose.Types.ObjectId();
|
||||||
|
const captainUserId = new mongoose.Types.ObjectId();
|
||||||
|
const auction = {
|
||||||
|
_id: new mongoose.Types.ObjectId(),
|
||||||
|
matchId,
|
||||||
|
phase: 'bidding',
|
||||||
|
teams: [
|
||||||
|
{
|
||||||
|
teamIndex: 1,
|
||||||
|
captainUserId,
|
||||||
|
points: 1000,
|
||||||
|
members: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
currentBid: 100,
|
||||||
|
currentDeadline: new Date(),
|
||||||
|
maxTimerSeconds: 30,
|
||||||
|
bidExtensionSeconds: 5,
|
||||||
|
bids: [],
|
||||||
|
save: jest.fn().mockResolvedValue(undefined),
|
||||||
|
toObject: jest.fn().mockReturnValue({ _id: 'auction', matchId }),
|
||||||
|
};
|
||||||
|
const { service } = createService({
|
||||||
|
auction: {
|
||||||
|
findOne: jest.fn().mockResolvedValue(auction),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await service.placeBid({
|
||||||
|
matchId,
|
||||||
|
teamIndex: 1,
|
||||||
|
amount: 970,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(auction.currentBid).toBe(970);
|
||||||
|
expect(auction.currentBidderTeamIndex).toBe(1);
|
||||||
|
expect(auction.bids).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
teamIndex: 1,
|
||||||
|
amount: 970,
|
||||||
|
bidderUserId: captainUserId,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
expect(auction.save).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('extends a short bid deadline using the configured bid extension seconds', async () => {
|
it('extends a short bid deadline using the configured bid extension seconds', async () => {
|
||||||
const now = new Date('2026-05-02T00:00:00.000Z');
|
const now = new Date('2026-05-02T00:00:00.000Z');
|
||||||
jest.useFakeTimers().setSystemTime(now);
|
jest.useFakeTimers().setSystemTime(now);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { TournamentCodeService } from '../tournament-code/tournament-code.servic
|
|||||||
import { TournamentResultService } from '../tournament-result/tournament-result.service';
|
import { TournamentResultService } from '../tournament-result/tournament-result.service';
|
||||||
|
|
||||||
const AUCTION_MAX_TEAM_SIZE = 5;
|
const AUCTION_MAX_TEAM_SIZE = 5;
|
||||||
|
const AUCTION_MIN_BID_POINTS = 10;
|
||||||
const AUCTION_BACKGROUND_ENRICHMENT_CONCURRENCY = 1;
|
const AUCTION_BACKGROUND_ENRICHMENT_CONCURRENCY = 1;
|
||||||
const AUCTION_ENRICHMENT_COOLDOWN_MS = 3 * 60 * 60 * 1000;
|
const AUCTION_ENRICHMENT_COOLDOWN_MS = 3 * 60 * 60 * 1000;
|
||||||
const AUCTION_CHAT_MAX_MESSAGES = 200;
|
const AUCTION_CHAT_MAX_MESSAGES = 200;
|
||||||
@@ -318,6 +319,11 @@ export class AuctionService {
|
|||||||
throw new BadRequestException('Bid exceeds team points.');
|
throw new BadRequestException('Bid exceeds team points.');
|
||||||
}
|
}
|
||||||
this.assertTeamHasSlot(team);
|
this.assertTeamHasSlot(team);
|
||||||
|
if (params.amount > this.calculateMaxBidForTeam(team)) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Bid must reserve minimum points for remaining slots.',
|
||||||
|
);
|
||||||
|
}
|
||||||
// 임시 운영용: 클라이언트에서 선택한 팀장 모드를 신뢰하고 실제 로그인 사용자 검증은 건너뛴다.
|
// 임시 운영용: 클라이언트에서 선택한 팀장 모드를 신뢰하고 실제 로그인 사용자 검증은 건너뛴다.
|
||||||
|
|
||||||
await this.recordSnapshot(auction, 'bid', params.bidderUserId);
|
await this.recordSnapshot(auction, 'bid', params.bidderUserId);
|
||||||
@@ -809,6 +815,16 @@ export class AuctionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private calculateMaxBidForTeam(team: AuctionTeam): number {
|
||||||
|
const remainingSlotsAfterCurrentBid = Math.max(
|
||||||
|
0,
|
||||||
|
AUCTION_MAX_TEAM_SIZE - this.countTeamMembersIncludingCaptain(team) - 1,
|
||||||
|
);
|
||||||
|
const reservedPoints =
|
||||||
|
remainingSlotsAfterCurrentBid * AUCTION_MIN_BID_POINTS;
|
||||||
|
return Math.max(0, team.points - reservedPoints);
|
||||||
|
}
|
||||||
|
|
||||||
private countTeamMembersIncludingCaptain(team: AuctionTeam): number {
|
private countTeamMembersIncludingCaptain(team: AuctionTeam): number {
|
||||||
const userIds = new Set<string>([team.captainUserId.toString()]);
|
const userIds = new Set<string>([team.captainUserId.toString()]);
|
||||||
for (const member of team.members) {
|
for (const member of team.members) {
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ function pickLatestAuction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AUCTION_MAX_TEAM_SIZE = 5;
|
const AUCTION_MAX_TEAM_SIZE = 5;
|
||||||
|
const AUCTION_MIN_BID_POINTS = 10;
|
||||||
const LANE_ROWS: Position[] = ['TOP', 'JGL', 'MID', 'ADC', 'SUP'];
|
const LANE_ROWS: Position[] = ['TOP', 'JGL', 'MID', 'ADC', 'SUP'];
|
||||||
const POSITION_TO_RIOT_LANE = {
|
const POSITION_TO_RIOT_LANE = {
|
||||||
TOP: 'TOP',
|
TOP: 'TOP',
|
||||||
@@ -134,6 +135,24 @@ const POSITION_TO_RIOT_LANE = {
|
|||||||
SUP: 'UTILITY',
|
SUP: 'UTILITY',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
function getAuctionTeamSize(team: AuctionStateView['teams'][number]) {
|
||||||
|
return team.members.length + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getReservedPointsAfterCurrentBid(
|
||||||
|
team: AuctionStateView['teams'][number],
|
||||||
|
) {
|
||||||
|
const remainingSlotsAfterCurrentBid = Math.max(
|
||||||
|
0,
|
||||||
|
AUCTION_MAX_TEAM_SIZE - getAuctionTeamSize(team) - 1,
|
||||||
|
);
|
||||||
|
return remainingSlotsAfterCurrentBid * AUCTION_MIN_BID_POINTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMaxBidForTeam(team: AuctionStateView['teams'][number]) {
|
||||||
|
return Math.max(0, team.points - getReservedPointsAfterCurrentBid(team));
|
||||||
|
}
|
||||||
|
|
||||||
function PosBadge({ pos }: { pos: Position }) {
|
function PosBadge({ pos }: { pos: Position }) {
|
||||||
return (
|
return (
|
||||||
<span className="inline-flex items-center gap-1.5 text-xs font-medium px-1.5 py-0.5 border border-primary/20 text-primary bg-primary/5">
|
<span className="inline-flex items-center gap-1.5 text-xs font-medium px-1.5 py-0.5 border border-primary/20 text-primary bg-primary/5">
|
||||||
@@ -291,7 +310,7 @@ function TeamPanel({
|
|||||||
}) {
|
}) {
|
||||||
const { data: ddragon } = useDdragonManifest();
|
const { data: ddragon } = useDdragonManifest();
|
||||||
const tone = teamIndexColorClasses(team.teamIndex);
|
const tone = teamIndexColorClasses(team.teamIndex);
|
||||||
const teamSize = team.members.length + 1;
|
const teamSize = getAuctionTeamSize(team);
|
||||||
const isFull = teamSize >= AUCTION_MAX_TEAM_SIZE;
|
const isFull = teamSize >= AUCTION_MAX_TEAM_SIZE;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -553,16 +572,22 @@ function BidControls({
|
|||||||
onBid: (teamIndex: number, amount: number) => void;
|
onBid: (teamIndex: number, amount: number) => void;
|
||||||
}) {
|
}) {
|
||||||
const [bidAmount, setBidAmount] = useState(100);
|
const [bidAmount, setBidAmount] = useState(100);
|
||||||
const minBid = state.currentBid + 10;
|
const minBid = state.currentBid + AUCTION_MIN_BID_POINTS;
|
||||||
const activeTeam = captainRole
|
const activeTeam = captainRole
|
||||||
? state.teams.find((team) => team.teamIndex === captainRole.teamIndex)
|
? state.teams.find((team) => team.teamIndex === captainRole.teamIndex)
|
||||||
: null;
|
: null;
|
||||||
const activeTeamSize = activeTeam ? activeTeam.members.length + 1 : 0;
|
const activeTeamSize = activeTeam ? getAuctionTeamSize(activeTeam) : 0;
|
||||||
const isActiveTeamFull = activeTeamSize >= AUCTION_MAX_TEAM_SIZE;
|
const isActiveTeamFull = activeTeamSize >= AUCTION_MAX_TEAM_SIZE;
|
||||||
|
const reservedPoints = activeTeam
|
||||||
|
? getReservedPointsAfterCurrentBid(activeTeam)
|
||||||
|
: 0;
|
||||||
|
const maxBid = activeTeam ? getMaxBidForTeam(activeTeam) : 0;
|
||||||
|
const canAffordNextBid = !isActiveTeamFull && maxBid >= minBid;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10));
|
const nextBid = Math.max(minBid, Math.ceil(minBid / 10) * 10);
|
||||||
}, [state.currentBid, minBid]);
|
setBidAmount(activeTeam ? Math.min(maxBid, nextBid) : nextBid);
|
||||||
|
}, [activeTeam, maxBid, minBid]);
|
||||||
|
|
||||||
if (state.phase !== 'bidding') return null;
|
if (state.phase !== 'bidding') return null;
|
||||||
|
|
||||||
@@ -578,16 +603,40 @@ function BidControls({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border border-base-content/10 bg-base-100 p-4">
|
<div className="border border-base-content/10 bg-base-100 p-4">
|
||||||
|
<div className="mb-3 grid grid-cols-2 gap-2 text-xs sm:grid-cols-3">
|
||||||
|
<div className="border border-base-content/10 px-2.5 py-2">
|
||||||
|
<div className="text-base-content/30">보유</div>
|
||||||
|
<div className="mt-0.5 font-bold tabular-nums text-base-content">
|
||||||
|
{formatPoints(activeTeam.points)}P
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="border border-primary/20 bg-primary/5 px-2.5 py-2">
|
||||||
|
<div className="text-primary/70">이번 최대</div>
|
||||||
|
<div className="mt-0.5 font-black tabular-nums text-primary">
|
||||||
|
{formatPoints(maxBid)}P
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="border border-base-content/10 px-2.5 py-2 text-base-content/45"
|
||||||
|
title={`현재 선수를 낙찰받은 뒤 남은 자리를 채우도록 자리당 ${AUCTION_MIN_BID_POINTS}P씩 보존합니다.`}
|
||||||
|
aria-label={`보존 ${reservedPoints}P. 현재 선수를 낙찰받은 뒤 남은 자리를 채우도록 자리당 ${AUCTION_MIN_BID_POINTS}P씩 보존합니다.`}
|
||||||
|
>
|
||||||
|
<div>보존</div>
|
||||||
|
<div className="mt-0.5 font-bold tabular-nums">
|
||||||
|
{formatPoints(reservedPoints)}P
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div className="flex items-center gap-2 mb-3 flex-wrap">
|
<div className="flex items-center gap-2 mb-3 flex-wrap">
|
||||||
{presets.map((preset) => (
|
{presets.map((preset) => (
|
||||||
<button
|
<button
|
||||||
key={preset}
|
key={preset}
|
||||||
onClick={() => setBidAmount(Math.max(minBid, preset))}
|
onClick={() => setBidAmount(Math.min(maxBid, Math.max(minBid, preset)))}
|
||||||
disabled={isActiveTeamFull}
|
disabled={!canAffordNextBid || Math.max(minBid, preset) > maxBid}
|
||||||
className={`text-xs px-2.5 py-1 border transition-colors ${
|
className={`text-xs px-2.5 py-1 border transition-colors ${
|
||||||
bidAmount === preset
|
bidAmount === preset
|
||||||
? 'border-primary/40 bg-primary/10 text-primary'
|
? 'border-primary/40 bg-primary/10 text-primary'
|
||||||
: 'border-base-content/10 text-base-content/40 hover:border-base-content/20'
|
: 'border-base-content/10 text-base-content/40 hover:border-base-content/20 disabled:opacity-30 disabled:cursor-not-allowed'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{preset}P
|
{preset}P
|
||||||
@@ -597,18 +646,19 @@ function BidControls({
|
|||||||
type="number"
|
type="number"
|
||||||
value={bidAmount}
|
value={bidAmount}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setBidAmount(Math.max(minBid, Number(event.target.value)))
|
setBidAmount(Math.min(maxBid, Math.max(minBid, Number(event.target.value))))
|
||||||
}
|
}
|
||||||
min={minBid}
|
min={minBid}
|
||||||
disabled={isActiveTeamFull}
|
max={maxBid}
|
||||||
|
disabled={!canAffordNextBid}
|
||||||
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"
|
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>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => onBid(activeTeam.teamIndex, bidAmount)}
|
onClick={() => onBid(activeTeam.teamIndex, bidAmount)}
|
||||||
disabled={
|
disabled={
|
||||||
isActiveTeamFull ||
|
!canAffordNextBid ||
|
||||||
bidAmount > activeTeam.points ||
|
bidAmount > maxBid ||
|
||||||
bidAmount <= state.currentBid
|
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 ${
|
className={`w-full py-2 text-xs font-bold uppercase tracking-wide border transition-colors disabled:opacity-30 disabled:cursor-not-allowed ${
|
||||||
@@ -617,6 +667,8 @@ function BidControls({
|
|||||||
>
|
>
|
||||||
{isActiveTeamFull
|
{isActiveTeamFull
|
||||||
? `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 정원 완료 (${activeTeamSize}/${AUCTION_MAX_TEAM_SIZE})`
|
? `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 정원 완료 (${activeTeamSize}/${AUCTION_MAX_TEAM_SIZE})`
|
||||||
|
: !canAffordNextBid
|
||||||
|
? `입찰 불가 (다음 ${formatPoints(minBid)}P · 최대 ${formatPoints(maxBid)}P)`
|
||||||
: `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 입찰 (${formatPoints(bidAmount)}P)`}
|
: `${teamIndexLabel(activeTeam.teamIndex, activeTeam.name)} 입찰 (${formatPoints(bidAmount)}P)`}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -624,10 +676,12 @@ function BidControls({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
||||||
const endRef = useRef<HTMLDivElement>(null);
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
const scrollContainer = scrollRef.current;
|
||||||
|
if (!scrollContainer) return;
|
||||||
|
scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
||||||
}, [bids.length]);
|
}, [bids.length]);
|
||||||
|
|
||||||
if (bids.length === 0) return null;
|
if (bids.length === 0) return null;
|
||||||
@@ -639,7 +693,7 @@ function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
|||||||
입찰 기록
|
입찰 기록
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="max-h-28 overflow-y-auto p-2 space-y-0.5">
|
<div ref={scrollRef} className="max-h-28 overflow-y-auto p-2 space-y-0.5">
|
||||||
{bids.map((bid, index) => (
|
{bids.map((bid, index) => (
|
||||||
<div key={`${bid.teamIndex}-${bid.timestamp}-${index}`} className="flex items-center gap-2 text-xs">
|
<div key={`${bid.teamIndex}-${bid.timestamp}-${index}`} className="flex items-center gap-2 text-xs">
|
||||||
<span
|
<span
|
||||||
@@ -653,7 +707,6 @@ function BidLog({ bids }: { bids: AuctionStateView['bids'] }) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<div ref={endRef} />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -1391,13 +1444,15 @@ function ChatPanel({
|
|||||||
className?: string;
|
className?: string;
|
||||||
}) {
|
}) {
|
||||||
const [draft, setDraft] = useState('');
|
const [draft, setDraft] = useState('');
|
||||||
const messagesEndRef = useRef<HTMLDivElement | null>(null);
|
const messagesScrollRef = useRef<HTMLDivElement | null>(null);
|
||||||
const trimmedDraft = draft.trim();
|
const trimmedDraft = draft.trim();
|
||||||
const isConnected = connectionStatus === 'connected';
|
const isConnected = connectionStatus === 'connected';
|
||||||
const canSend = isConnected && trimmedDraft.length > 0;
|
const canSend = isConnected && trimmedDraft.length > 0;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
messagesEndRef.current?.scrollIntoView({ block: 'end' });
|
const scrollContainer = messagesScrollRef.current;
|
||||||
|
if (!scrollContainer) return;
|
||||||
|
scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
||||||
}, [messages.length]);
|
}, [messages.length]);
|
||||||
|
|
||||||
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
||||||
@@ -1439,7 +1494,7 @@ function ChatPanel({
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 min-h-0 overflow-y-auto px-3 py-3">
|
<div ref={messagesScrollRef} className="flex-1 min-h-0 overflow-y-auto px-3 py-3">
|
||||||
{messages.length === 0 ? (
|
{messages.length === 0 ? (
|
||||||
<div className="flex h-full items-center justify-center text-center text-xs text-base-content/25">
|
<div className="flex h-full items-center justify-center text-center text-xs text-base-content/25">
|
||||||
아직 메시지가 없습니다
|
아직 메시지가 없습니다
|
||||||
@@ -1463,7 +1518,6 @@ function ChatPanel({
|
|||||||
))}
|
))}
|
||||||
</ol>
|
</ol>
|
||||||
)}
|
)}
|
||||||
<div ref={messagesEndRef} />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="border-t border-base-content/10 p-2 space-y-2">
|
<form onSubmit={handleSubmit} className="border-t border-base-content/10 p-2 space-y-2">
|
||||||
|
|||||||
Reference in new issue
Block a user