This commit is contained in:
dahyeon committed 2026-05-02 22:14:19 -07:00
1 parent 09286e7711
commit feeb30c6a9
8 files changed
+196 -22

No files matched your search

@@ -54,6 +54,7 @@ export class AuctionController {
})),
initialPoints: body.initialPoints ?? 1000,
maxTimerSeconds: body.maxTimerSeconds ?? 30,
bidExtensionSeconds: body.bidExtensionSeconds ?? 5,
topTierThreshold: body.topTierThreshold ?? 'NONE',
manualTopTierUserIds: (body.manualTopTierUserIds ?? []).map(
(userId) => new mongoose.Types.ObjectId(userId),
@@ -65,6 +65,10 @@ describe('AuctionService', () => {
};
}
afterEach(() => {
jest.useRealTimers();
});
it('rejects bids when the team already has 5 members including captain', async () => {
const matchId = new mongoose.Types.ObjectId();
const auction = {
@@ -89,6 +93,50 @@ describe('AuctionService', () => {
expect(auction.save).not.toHaveBeenCalled();
});
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);
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: 10,
currentDeadline: new Date(now.getTime() + 2000),
maxTimerSeconds: 30,
bidExtensionSeconds: 12,
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: 20,
});
expect(auction.currentDeadline).toEqual(
new Date(now.getTime() + 12000),
);
expect(auction.save).toHaveBeenCalledTimes(1);
});
it('rejects sold confirmation when the winning team is already full', async () => {
const matchId = new mongoose.Types.ObjectId();
const auction = {
@@ -37,6 +37,7 @@ interface StartAuctionParams {
}[];
initialPoints: number;
maxTimerSeconds: number;
bidExtensionSeconds: number;
topTierThreshold: AuctionTopTierThreshold;
manualTopTierUserIds: mongoose.Types.ObjectId[];
}
@@ -188,6 +189,7 @@ export class AuctionService {
bids: [],
currentBid: 0,
maxTimerSeconds: params.maxTimerSeconds,
bidExtensionSeconds: params.bidExtensionSeconds,
initialPoints: params.initialPoints,
topTierThreshold: params.topTierThreshold,
manualTopTierUserIds:
@@ -750,14 +752,24 @@ export class AuctionService {
}
private resolveBidExtensionSeconds(auction: AuctionDocument): number {
const maxTimerSeconds = Math.max(5, auction.maxTimerSeconds ?? 30);
const bidExtensionSeconds = Math.max(0, auction.bidExtensionSeconds ?? 5);
const minimumRemainingSeconds = Math.min(
maxTimerSeconds,
bidExtensionSeconds,
);
if (!auction.currentDeadline) {
return auction.maxTimerSeconds;
return maxTimerSeconds;
}
const remainingSeconds = Math.ceil(
(auction.currentDeadline.getTime() - Date.now()) / 1000,
);
return Math.max(5, remainingSeconds);
return Math.min(
maxTimerSeconds,
Math.max(minimumRemainingSeconds, remainingSeconds),
);
}
private assertTeamHasSlot(team: AuctionTeam): void {
@@ -59,6 +59,11 @@ export class StartAuctionDto {
@IsInt()
@Min(5)
maxTimerSeconds?: number;
@IsOptional()
@IsInt()
@Min(0)
bidExtensionSeconds?: number;
}
export class PlaceBidDto {
@@ -533,6 +533,7 @@ export interface Auction extends MongooseTimestamps {
currentBid: number;
currentBidderTeamIndex?: number;
maxTimerSeconds: number;
bidExtensionSeconds: number;
currentDeadline?: Date;
initialPoints: number;
topTierThreshold: AuctionTopTierThreshold;
@@ -1300,6 +1301,7 @@ export const AuctionSchema = new Schema<Auction>(
currentBid: { type: Number, required: true, default: 0 },
currentBidderTeamIndex: { type: Number, required: false, min: 1 },
maxTimerSeconds: { type: Number, required: true, default: 30 },
bidExtensionSeconds: { type: Number, required: true, default: 5, min: 0 },
currentDeadline: { type: Date, required: false },
initialPoints: { type: Number, required: true, default: 1000 },
topTierThreshold: {