fix: close competition cutover integrity gaps
This commit is contained in:
1 parent
7ea2002975
commit
683d602d63
57 files changed
+4805
-1582
No files matched your search
@@ -57,6 +57,7 @@ describe('MatchService', () => {
|
||||
) {
|
||||
const MatchModel = {
|
||||
findById: jest.fn().mockResolvedValue(match),
|
||||
findOne: jest.fn().mockResolvedValue(match),
|
||||
findOneAndUpdate: jest.fn().mockResolvedValue(updatedMatch),
|
||||
};
|
||||
const connectionService = {
|
||||
@@ -203,6 +204,19 @@ describe('MatchService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('scopes Match detail lookup to the URL community', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = { _id: matchId, communityId };
|
||||
const { service, MatchModel } = createService(match);
|
||||
|
||||
await expect(service.getById(matchId, communityId)).resolves.toBe(match);
|
||||
expect(MatchModel.findOne).toHaveBeenCalledWith({
|
||||
_id: matchId,
|
||||
communityId,
|
||||
});
|
||||
});
|
||||
|
||||
it('applies offset before page-based pagination', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const { service, skip } = createServiceWithListModel();
|
||||
@@ -344,6 +358,36 @@ describe('MatchService', () => {
|
||||
expect(match.save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not join a user from a different community', async () => {
|
||||
const requestedCommunityId = new mongoose.Types.ObjectId();
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
const user = {
|
||||
_id: userId,
|
||||
communityId: new mongoose.Types.ObjectId(),
|
||||
preferredPositions: [],
|
||||
riotAccounts: [],
|
||||
};
|
||||
const match = {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
communityId: requestedCommunityId,
|
||||
status: 'recruiting',
|
||||
participants: [],
|
||||
};
|
||||
const { service, MatchModel } = createServiceWithJoinModels({
|
||||
user,
|
||||
match,
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.join({
|
||||
matchId: match._id,
|
||||
communityId: requestedCommunityId,
|
||||
userId,
|
||||
}),
|
||||
).rejects.toThrow('Match not found.');
|
||||
expect(MatchModel.findOneAndUpdate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('cancels a join with an atomic participant pull', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const userId = new mongoose.Types.ObjectId();
|
||||
@@ -525,7 +569,7 @@ describe('MatchService', () => {
|
||||
expect(MatchModel.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('clears game schedule when a built match returns to recruiting', async () => {
|
||||
it('rejects returning a finalized team build to recruiting', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
communityId,
|
||||
@@ -547,20 +591,23 @@ describe('MatchService', () => {
|
||||
const { service, tournamentCodeService, matchStatsService } =
|
||||
createService(match);
|
||||
|
||||
await service.update({
|
||||
matchId: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
patch: { status: 'recruiting' },
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.update({
|
||||
matchId: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
patch: { status: 'recruiting' },
|
||||
}),
|
||||
).rejects.toThrow('cannot return to recruiting');
|
||||
expect(tournamentCodeService.releaseFromMatch).not.toHaveBeenCalled();
|
||||
expect(match.tournamentCodeIds).toEqual([]);
|
||||
expect(match.gameSchedule).toEqual([]);
|
||||
expect(match.teamBuiltAt).toBeUndefined();
|
||||
expect(match.result).toBeUndefined();
|
||||
expect(match.resultPollState).toBeUndefined();
|
||||
expect(match.save).toHaveBeenCalledTimes(1);
|
||||
expect(matchStatsService.removeByMatch).toHaveBeenCalledWith(match._id);
|
||||
expect(match.gameSchedule).toEqual([
|
||||
{ gameNumber: 1, teamAIndex: 2, teamBIndex: 4 },
|
||||
]);
|
||||
expect(match.teamBuiltAt).toBeInstanceOf(Date);
|
||||
expect(match.result).toEqual({ games: [] });
|
||||
expect(match.resultPollState).toEqual({ state: 'polling' });
|
||||
expect(match.save).not.toHaveBeenCalled();
|
||||
expect(matchStatsService.removeByMatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects round-robin max round changes after recruiting', async () => {
|
||||
@@ -581,12 +628,77 @@ describe('MatchService', () => {
|
||||
patch: { roundRobinMaxRounds: 3 },
|
||||
}),
|
||||
).rejects.toThrow(
|
||||
'maxParticipants, gameMode, roundRobinMaxRounds, and doubleEliminationResetFinalEnabled can only be changed while recruiting.',
|
||||
'maxParticipants, gameCount, gameMode, roundRobinMaxRounds, and doubleEliminationResetFinalEnabled can only be changed while recruiting.',
|
||||
);
|
||||
expect(match.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('releases reserved codes when returning a built match to recruiting', async () => {
|
||||
it('rejects game count changes after recruiting', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
communityId,
|
||||
status: 'team-built',
|
||||
tournamentCodeIds: [],
|
||||
set: jest.fn(),
|
||||
save: jest.fn(),
|
||||
};
|
||||
const { service } = createService(match);
|
||||
|
||||
await expect(
|
||||
service.update({
|
||||
matchId: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
patch: { gameCount: 5 },
|
||||
}),
|
||||
).rejects.toThrow('gameCount');
|
||||
expect(match.set).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects returning to recruiting after Competition bootstrap', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
communityId,
|
||||
competitionId: new mongoose.Types.ObjectId(),
|
||||
status: 'team-built',
|
||||
tournamentCodeIds: [],
|
||||
set: jest.fn(),
|
||||
save: jest.fn(),
|
||||
};
|
||||
const { service, tournamentCodeService } = createService(match);
|
||||
|
||||
await expect(
|
||||
service.update({
|
||||
matchId: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
patch: { status: 'recruiting' },
|
||||
}),
|
||||
).rejects.toThrow('cannot return to recruiting');
|
||||
expect(match.set).not.toHaveBeenCalled();
|
||||
expect(tournamentCodeService.releaseFromMatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects hard deletion after Competition bootstrap', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
competitionId: new mongoose.Types.ObjectId(),
|
||||
status: 'recruiting',
|
||||
tournamentCodeIds: [],
|
||||
deleteOne: jest.fn(),
|
||||
};
|
||||
const { service, tournamentCodeService, matchStatsService } =
|
||||
createService(match);
|
||||
|
||||
await expect(
|
||||
service.remove({ matchId: match._id, communityId }),
|
||||
).rejects.toThrow('cannot be hard-deleted');
|
||||
expect(tournamentCodeService.releaseFromMatch).not.toHaveBeenCalled();
|
||||
expect(matchStatsService.removeByMatch).not.toHaveBeenCalled();
|
||||
expect(match.deleteOne).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('preserves reserved codes when a recruiting rollback is rejected', async () => {
|
||||
const communityId = new mongoose.Types.ObjectId();
|
||||
const codeId = new mongoose.Types.ObjectId();
|
||||
const match = {
|
||||
@@ -604,14 +716,18 @@ describe('MatchService', () => {
|
||||
};
|
||||
const { service, tournamentCodeService } = createService(match);
|
||||
|
||||
await service.update({
|
||||
matchId: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
patch: { status: 'recruiting' },
|
||||
});
|
||||
|
||||
expect(tournamentCodeService.releaseFromMatch).toHaveBeenCalledWith(match);
|
||||
expect(match.tournamentCodeIds).toEqual([]);
|
||||
expect(match.gameSchedule).toEqual([]);
|
||||
await expect(
|
||||
service.update({
|
||||
matchId: new mongoose.Types.ObjectId(),
|
||||
communityId,
|
||||
patch: { status: 'recruiting' },
|
||||
}),
|
||||
).rejects.toThrow('cannot return to recruiting');
|
||||
expect(tournamentCodeService.releaseFromMatch).not.toHaveBeenCalled();
|
||||
expect(match.tournamentCodeIds).toEqual([codeId]);
|
||||
expect(match.gameSchedule).toEqual([
|
||||
{ gameNumber: 1, teamAIndex: 1, teamBIndex: 3 },
|
||||
]);
|
||||
expect(match.save).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user