fix: prevent empty-team auction completion state
This commit is contained in:
1 parent
2984bd1604
commit
ab721873f3
6 files changed
+748
-452
No files matched your search
@@ -226,8 +226,10 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
||||
(game) => game.roundNumber === roundNumber,
|
||||
);
|
||||
expect(round).toHaveLength(4);
|
||||
expect(new Set(round.flatMap((game) => [game.teamAIndex, game.teamBIndex])).size)
|
||||
.toBe(8);
|
||||
expect(
|
||||
new Set(round.flatMap((game) => [game.teamAIndex, game.teamBIndex]))
|
||||
.size,
|
||||
).toBe(8);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -405,6 +407,69 @@ describe('TournamentCodeService pool stats', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('TournamentCodeService pending match attachment', () => {
|
||||
it('does not attach tournament codes before match teams are built', async () => {
|
||||
const invalidMatch = {
|
||||
...createMatch({
|
||||
status: 'team-built',
|
||||
teams: [],
|
||||
tournamentCodeIds: [],
|
||||
} as unknown as MatchOverrides),
|
||||
isModified: jest.fn().mockReturnValue(false),
|
||||
};
|
||||
const validMatch = {
|
||||
...createMatch({
|
||||
status: 'team-built',
|
||||
teams: [
|
||||
{
|
||||
teamIndex: 1,
|
||||
members: [{ userId: new mongoose.Types.ObjectId() }],
|
||||
},
|
||||
{
|
||||
teamIndex: 2,
|
||||
members: [{ userId: new mongoose.Types.ObjectId() }],
|
||||
},
|
||||
],
|
||||
tournamentCodeIds: [],
|
||||
} as unknown as MatchOverrides),
|
||||
isModified: jest.fn().mockReturnValue(false),
|
||||
};
|
||||
const codeId = new mongoose.Types.ObjectId();
|
||||
const MatchModel = {
|
||||
find: jest.fn().mockReturnValue({
|
||||
exec: jest.fn().mockResolvedValue([invalidMatch, validMatch]),
|
||||
}),
|
||||
findById: jest.fn().mockResolvedValue(validMatch),
|
||||
};
|
||||
const TournamentCodeModel = {
|
||||
findOneAndUpdate: jest.fn().mockReturnValue({
|
||||
exec: jest.fn().mockResolvedValue({ _id: codeId }),
|
||||
}),
|
||||
};
|
||||
const connectionService = {
|
||||
getModel: jest.fn().mockImplementation((modelName: string) => {
|
||||
if (modelName === 'match') return Promise.resolve(MatchModel);
|
||||
if (modelName === 'tournamentCode') {
|
||||
return Promise.resolve(TournamentCodeModel);
|
||||
}
|
||||
throw new Error(`Unexpected model: ${modelName}`);
|
||||
}),
|
||||
};
|
||||
const service = new TournamentCodeService(connectionService as never);
|
||||
|
||||
const matches = await service.attachPendingMatchDocuments();
|
||||
|
||||
expect(matches).toEqual([validMatch]);
|
||||
expect(MatchModel.findById).toHaveBeenCalledTimes(1);
|
||||
expect(MatchModel.findById).toHaveBeenCalledWith(validMatch._id);
|
||||
expect(TournamentCodeModel.findOneAndUpdate).toHaveBeenCalledTimes(1);
|
||||
expect(validMatch.tournamentCodeIds.map((id) => id.toString())).toEqual([
|
||||
codeId.toString(),
|
||||
]);
|
||||
expect(invalidMatch.tournamentCodeIds).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('TournamentCodeService code replacement', () => {
|
||||
function queryResult<T>(value: T) {
|
||||
return { exec: jest.fn().mockResolvedValue(value) };
|
||||
|
||||
Reference in new issue
Block a user