.
This commit is contained in:
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: {
|
||||
|
||||
@@ -130,6 +130,7 @@ export interface AuctionStateView {
|
||||
currentBidder: { teamIndex: number } | null;
|
||||
timer: number;
|
||||
maxTimer: number;
|
||||
bidExtensionSeconds: number;
|
||||
deadline?: string;
|
||||
}
|
||||
|
||||
@@ -521,6 +522,7 @@ export function mapApiAuctionToAuctionState(
|
||||
: null,
|
||||
timer,
|
||||
maxTimer: auction.maxTimerSeconds,
|
||||
bidExtensionSeconds: auction.bidExtensionSeconds ?? 5,
|
||||
deadline: auction.currentDeadline,
|
||||
};
|
||||
}
|
||||
@@ -269,6 +269,7 @@ export interface ApiAuction {
|
||||
currentBid: number;
|
||||
currentBidderTeamIndex?: number;
|
||||
maxTimerSeconds: number;
|
||||
bidExtensionSeconds: number;
|
||||
currentDeadline?: string;
|
||||
initialPoints: number;
|
||||
topTierThreshold: AuctionTopTierThreshold;
|
||||
|
||||
@@ -46,6 +46,10 @@ type CaptainSelection = {
|
||||
initialPoints: string;
|
||||
};
|
||||
|
||||
const DEFAULT_AUCTION_MAX_TIMER_SECONDS = 30;
|
||||
const DEFAULT_AUCTION_BID_EXTENSION_SECONDS = 5;
|
||||
const MAX_AUCTION_TIMER_SECONDS = 3600;
|
||||
|
||||
function captainSlotKey(slot: CaptainSelectionSlot) {
|
||||
return String(slot.teamIndex);
|
||||
}
|
||||
@@ -59,6 +63,19 @@ function parseInitialPointsInput(value: string) {
|
||||
return points;
|
||||
}
|
||||
|
||||
function parseAuctionSecondsInput(value: string, min: number) {
|
||||
if (!value.trim()) return null;
|
||||
const seconds = Number(value);
|
||||
if (
|
||||
!Number.isInteger(seconds) ||
|
||||
seconds < min ||
|
||||
seconds > MAX_AUCTION_TIMER_SECONDS
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return seconds;
|
||||
}
|
||||
|
||||
function buildAuctionParticipantPool(participants: ApiMatchParticipant[]) {
|
||||
const ordered = [...participants].sort(
|
||||
(left, right) =>
|
||||
@@ -969,6 +986,12 @@ export default function MatchDetailPage() {
|
||||
const [manualTopTierUserIds, setManualTopTierUserIds] = useState<string[]>(
|
||||
[],
|
||||
);
|
||||
const [maxTimerSeconds, setMaxTimerSeconds] = useState(
|
||||
String(DEFAULT_AUCTION_MAX_TIMER_SECONDS),
|
||||
);
|
||||
const [bidExtensionSeconds, setBidExtensionSeconds] = useState(
|
||||
String(DEFAULT_AUCTION_BID_EXTENSION_SECONDS),
|
||||
);
|
||||
const pollTournamentResultMutation =
|
||||
usePollTournamentResult(DEFAULT_COMMUNITY_ID);
|
||||
|
||||
@@ -1016,7 +1039,12 @@ export default function MatchDetailPage() {
|
||||
topTierThreshold,
|
||||
manualTopTierUserIds:
|
||||
topTierThreshold === "MANUAL" ? selectedManualTopTierUserIds : [],
|
||||
maxTimerSeconds: 30,
|
||||
maxTimerSeconds:
|
||||
parseAuctionSecondsInput(maxTimerSeconds, 5) ??
|
||||
DEFAULT_AUCTION_MAX_TIMER_SECONDS,
|
||||
bidExtensionSeconds:
|
||||
parseAuctionSecondsInput(bidExtensionSeconds, 0) ??
|
||||
DEFAULT_AUCTION_BID_EXTENSION_SECONDS,
|
||||
}),
|
||||
}),
|
||||
onSuccess: async () => {
|
||||
@@ -1157,6 +1185,13 @@ export default function MatchDetailPage() {
|
||||
const selectedManualTopTierUserIds = manualTopTierUserIds.filter((userId) =>
|
||||
manualPriorityCandidateIds.has(userId),
|
||||
);
|
||||
const parsedMaxTimerSeconds = parseAuctionSecondsInput(maxTimerSeconds, 5);
|
||||
const parsedBidExtensionSeconds = parseAuctionSecondsInput(
|
||||
bidExtensionSeconds,
|
||||
0,
|
||||
);
|
||||
const hasValidAuctionTimerSettings =
|
||||
parsedMaxTimerSeconds !== null && parsedBidExtensionSeconds !== null;
|
||||
const waitingParticipantCount =
|
||||
matchQuery.data.participants.length - auctionParticipantPool.length;
|
||||
const canStartAuction =
|
||||
@@ -1165,7 +1200,8 @@ export default function MatchDetailPage() {
|
||||
auctionParticipantPool.length >= 10 &&
|
||||
auctionNotStarted &&
|
||||
hasUniqueCaptainSelections &&
|
||||
hasValidCaptainInitialPoints;
|
||||
hasValidCaptainInitialPoints &&
|
||||
hasValidAuctionTimerSettings;
|
||||
|
||||
return (
|
||||
<main className="max-w-5xl mx-auto px-4 sm:px-6 py-6">
|
||||
@@ -1384,24 +1420,91 @@ export default function MatchDetailPage() {
|
||||
경매를 시작하려면 최소 10명이 필요합니다.
|
||||
</div>
|
||||
)}
|
||||
<label className="block text-xs text-base-content/45">
|
||||
상위 티어 우선 등장
|
||||
<select
|
||||
className="mt-1 w-full max-w-xs border border-base-content/10 bg-transparent px-2 py-2 text-sm"
|
||||
value={topTierThreshold}
|
||||
onChange={(event) =>
|
||||
setTopTierThreshold(
|
||||
event.target.value as AuctionTopTierThreshold,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="NONE">없음</option>
|
||||
<option value="EMERALD">EMERALD+</option>
|
||||
<option value="DIAMOND">DIAMOND+</option>
|
||||
<option value="MASTER">MASTER+</option>
|
||||
<option value="MANUAL">수동 선택</option>
|
||||
</select>
|
||||
</label>
|
||||
<div className="grid gap-x-3 gap-y-4 sm:grid-cols-2">
|
||||
<label className="block text-xs text-base-content/45">
|
||||
경매 제한 시간
|
||||
<div className="mt-1 flex items-center border border-base-content/10 bg-transparent focus-within:border-primary/30">
|
||||
<input
|
||||
type="number"
|
||||
min={5}
|
||||
max={MAX_AUCTION_TIMER_SECONDS}
|
||||
step={5}
|
||||
className="min-w-0 flex-1 bg-transparent px-2 py-2 text-sm tabular-nums focus:outline-none"
|
||||
value={maxTimerSeconds}
|
||||
onChange={(event) =>
|
||||
setMaxTimerSeconds(event.target.value)
|
||||
}
|
||||
onBlur={() => {
|
||||
if (
|
||||
parseAuctionSecondsInput(maxTimerSeconds, 5)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setMaxTimerSeconds(
|
||||
String(DEFAULT_AUCTION_MAX_TIMER_SECONDS),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<span className="shrink-0 px-2 text-[11px] text-base-content/30">
|
||||
초
|
||||
</span>
|
||||
</div>
|
||||
</label>
|
||||
<label className="block text-xs text-base-content/45">
|
||||
최저 입찰 보장 시간
|
||||
<div className="mt-1 flex items-center border border-base-content/10 bg-transparent focus-within:border-primary/30">
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
max={MAX_AUCTION_TIMER_SECONDS}
|
||||
step={1}
|
||||
className="min-w-0 flex-1 bg-transparent px-2 py-2 text-sm tabular-nums focus:outline-none"
|
||||
value={bidExtensionSeconds}
|
||||
onChange={(event) =>
|
||||
setBidExtensionSeconds(event.target.value)
|
||||
}
|
||||
onBlur={() => {
|
||||
if (
|
||||
parseAuctionSecondsInput(
|
||||
bidExtensionSeconds,
|
||||
0,
|
||||
) !== null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setBidExtensionSeconds(
|
||||
String(DEFAULT_AUCTION_BID_EXTENSION_SECONDS),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<span className="shrink-0 px-2 text-[11px] text-base-content/30">
|
||||
초
|
||||
</span>
|
||||
</div>
|
||||
<span className="mt-1 block text-[11px] text-base-content/30">
|
||||
남은 시간이 이 값보다 적을 때 입찰하면 이 시간까지
|
||||
늘어납니다.
|
||||
</span>
|
||||
</label>
|
||||
<label className="block text-xs text-base-content/45">
|
||||
상위 티어 우선 등장
|
||||
<select
|
||||
className="mt-1 h-[38px] w-full border border-base-content/10 bg-transparent px-2 py-2 text-sm focus:border-primary/30 focus:outline-none"
|
||||
value={topTierThreshold}
|
||||
onChange={(event) =>
|
||||
setTopTierThreshold(
|
||||
event.target.value as AuctionTopTierThreshold,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="NONE">없음</option>
|
||||
<option value="EMERALD">EMERALD+</option>
|
||||
<option value="DIAMOND">DIAMOND+</option>
|
||||
<option value="MASTER">MASTER+</option>
|
||||
<option value="MANUAL">수동 선택</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
{topTierThreshold === "MANUAL" && (
|
||||
<div className="border border-base-content/10 bg-base-200/20 p-3">
|
||||
<div className="mb-2 text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
|
||||
Reference in new issue
Block a user