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();
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const now = new Date('2026-05-02T00:00:00.000Z');
|
||||
jest.useFakeTimers().setSystemTime(now);
|
||||
|
||||
@@ -26,6 +26,7 @@ import { TournamentCodeService } from '../tournament-code/tournament-code.servic
|
||||
import { TournamentResultService } from '../tournament-result/tournament-result.service';
|
||||
|
||||
const AUCTION_MAX_TEAM_SIZE = 5;
|
||||
const AUCTION_MIN_BID_POINTS = 10;
|
||||
const AUCTION_BACKGROUND_ENRICHMENT_CONCURRENCY = 1;
|
||||
const AUCTION_ENRICHMENT_COOLDOWN_MS = 3 * 60 * 60 * 1000;
|
||||
const AUCTION_CHAT_MAX_MESSAGES = 200;
|
||||
@@ -318,6 +319,11 @@ export class AuctionService {
|
||||
throw new BadRequestException('Bid exceeds team points.');
|
||||
}
|
||||
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);
|
||||
@@ -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 {
|
||||
const userIds = new Set<string>([team.captainUserId.toString()]);
|
||||
for (const member of team.members) {
|
||||
|
||||
Reference in new issue
Block a user