fix(api): keep zero-bid auction passes open
This commit is contained in:
1 parent
6a192276e8
commit
b711c63dcd
2 files changed
+67
-90
No files matched your search
@@ -348,7 +348,7 @@ describe('AuctionService', () => {
|
||||
expect(auction.save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('marks a zero-bid player as passed and queues them for round two', async () => {
|
||||
it('marks a zero-bid player as passed and queues them for another round', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const playerId = new mongoose.Types.ObjectId();
|
||||
const auction = {
|
||||
@@ -383,25 +383,63 @@ describe('AuctionService', () => {
|
||||
expect(auction.save).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('force-assigns second-pass players to the open team with most points', async () => {
|
||||
it('queues zero-bid passes after the first auction round', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const playerId = new mongoose.Types.ObjectId();
|
||||
const auction = {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
matchId,
|
||||
phase: 'bidding',
|
||||
currentBid: 0,
|
||||
currentIndex: 0,
|
||||
auctionRound: 2,
|
||||
order: [
|
||||
{
|
||||
userId: playerId,
|
||||
preferredPositions: [{ position: 'MID', priority: 1 }],
|
||||
passCount: 1,
|
||||
},
|
||||
],
|
||||
passedQueue: [],
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
toObject: jest.fn().mockReturnValue({ _id: 'auction', matchId }),
|
||||
};
|
||||
const { service } = createService({
|
||||
auction: {
|
||||
findOne: jest.fn().mockResolvedValue(auction),
|
||||
},
|
||||
});
|
||||
|
||||
await service.markPassed(matchId);
|
||||
|
||||
expect(auction.phase).toBe('passed');
|
||||
expect(auction.order[0].passCount).toBe(2);
|
||||
expect(auction.passedQueue).toHaveLength(1);
|
||||
expect(auction.passedQueue[0]).toMatchObject({
|
||||
userId: playerId.toString(),
|
||||
preferredPositions: [{ position: 'MID', priority: 1 }],
|
||||
passCount: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it('requeues second-pass players instead of force-assigning them', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const captainOneId = new mongoose.Types.ObjectId();
|
||||
const captainTwoId = new mongoose.Types.ObjectId();
|
||||
const passedPlayerId = new mongoose.Types.ObjectId();
|
||||
const passedPlayer = {
|
||||
userId: passedPlayerId,
|
||||
preferredPositions: [{ position: 'SUP', priority: 1 }],
|
||||
passCount: 2,
|
||||
};
|
||||
const auction = {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
matchId,
|
||||
phase: 'passed',
|
||||
currentIndex: 0,
|
||||
auctionRound: 2,
|
||||
order: [
|
||||
{
|
||||
userId: passedPlayerId,
|
||||
preferredPositions: [{ position: 'SUP', priority: 1 }],
|
||||
passCount: 2,
|
||||
},
|
||||
],
|
||||
passedQueue: [],
|
||||
order: [passedPlayer],
|
||||
passedQueue: [passedPlayer],
|
||||
teams: [
|
||||
{
|
||||
teamIndex: 1,
|
||||
@@ -419,46 +457,28 @@ describe('AuctionService', () => {
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
toObject: jest.fn().mockReturnValue({ _id: 'auction', matchId }),
|
||||
};
|
||||
const match = {
|
||||
participants: [
|
||||
{
|
||||
userId: captainOneId,
|
||||
preferredPositions: [{ position: 'TOP', priority: 1 }],
|
||||
},
|
||||
{
|
||||
userId: captainTwoId,
|
||||
preferredPositions: [{ position: 'JGL', priority: 1 }],
|
||||
},
|
||||
{
|
||||
userId: passedPlayerId,
|
||||
preferredPositions: [{ position: 'SUP', priority: 1 }],
|
||||
},
|
||||
],
|
||||
status: 'team-built',
|
||||
teams: [],
|
||||
teamBuiltAt: undefined,
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const { service } = createService({
|
||||
auction: {
|
||||
findOne: jest.fn().mockResolvedValue(auction),
|
||||
},
|
||||
match: {
|
||||
findById: jest.fn().mockResolvedValue(match),
|
||||
},
|
||||
});
|
||||
|
||||
await service.next(matchId);
|
||||
|
||||
expect(auction.phase).toBe('complete');
|
||||
expect(auction.teams[1].members).toEqual([
|
||||
{
|
||||
userId: passedPlayerId,
|
||||
assignedPosition: 'SUP',
|
||||
cost: 1,
|
||||
},
|
||||
]);
|
||||
expect(auction.teams[1].points).toBe(49);
|
||||
expect(auction.phase).toBe('presenting');
|
||||
expect(auction.auctionRound).toBe(3);
|
||||
expect(auction.currentIndex).toBe(1);
|
||||
expect(auction.order).toHaveLength(2);
|
||||
expect(auction.order[1]).toMatchObject({
|
||||
userId: passedPlayerId.toString(),
|
||||
preferredPositions: [{ position: 'SUP', priority: 1 }],
|
||||
passCount: 2,
|
||||
});
|
||||
expect(auction.passedQueue).toEqual([]);
|
||||
expect(auction.teams[0].members).toEqual([]);
|
||||
expect(auction.teams[1].members).toEqual([]);
|
||||
expect(auction.teams[0].points).toBe(10);
|
||||
expect(auction.teams[1].points).toBe(50);
|
||||
});
|
||||
|
||||
it('syncs completed auction teams into the match document', async () => {
|
||||
|
||||
Reference in new issue
Block a user