.
This commit is contained in:
1 parent
ec2315cc3d
commit
dfcfe9e4ad
3 files changed
+116
-3
No files matched your search
@@ -20,6 +20,71 @@ describe('AuctionService', () => {
|
||||
};
|
||||
}
|
||||
|
||||
function createFullTeam(side: 'blue' | 'red') {
|
||||
return {
|
||||
side,
|
||||
captainUserId: new mongoose.Types.ObjectId(),
|
||||
points: 100,
|
||||
members: Array.from({ length: 4 }, () => ({
|
||||
userId: new mongoose.Types.ObjectId(),
|
||||
assignedPosition: 'MID',
|
||||
cost: 10,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
it('rejects bids when the team already has 5 members including captain', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const auction = {
|
||||
phase: 'bidding',
|
||||
teams: [createFullTeam('blue'), createFullTeam('red')],
|
||||
currentBid: 10,
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const { service } = createService({
|
||||
auction: {
|
||||
findOne: jest.fn().mockResolvedValue(auction),
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.placeBid({
|
||||
matchId,
|
||||
side: 'blue',
|
||||
amount: 20,
|
||||
}),
|
||||
).rejects.toThrow('Team already has maximum members.');
|
||||
expect(auction.save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects sold confirmation when the winning team is already full', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const auction = {
|
||||
phase: 'bidding',
|
||||
currentBidder: 'blue',
|
||||
currentBid: 20,
|
||||
currentIndex: 0,
|
||||
order: [
|
||||
{
|
||||
userId: new mongoose.Types.ObjectId(),
|
||||
preferredPositions: [{ position: 'ADC', priority: 1 }],
|
||||
},
|
||||
],
|
||||
teams: [createFullTeam('blue'), createFullTeam('red')],
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const { service } = createService({
|
||||
auction: {
|
||||
findOne: jest.fn().mockResolvedValue(auction),
|
||||
},
|
||||
});
|
||||
|
||||
await expect(service.markSold({ matchId })).rejects.toThrow(
|
||||
'Team already has maximum members.',
|
||||
);
|
||||
expect(auction.save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('syncs completed auction teams into the match document', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const blueCaptainId = new mongoose.Types.ObjectId();
|
||||
|
||||
Reference in new issue
Block a user