fix: reserve auction points for remaining slots

This commit is contained in:
dahyeon committed 2026-06-22 04:37:06 -07:00
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);