feat: support double-elimination series games
This commit is contained in:
1 parent
2ee8c3807b
commit
e188828423
16 files changed
+1176
-234
No files matched your search
+58
-12
@@ -347,20 +347,22 @@ describe('migrateTournamentCodeUniqueIndexes', () => {
|
||||
indexesDropped: 3,
|
||||
matchesUpdated: 1,
|
||||
});
|
||||
expect(collections.tournamentCode.find((code) => code._id === 'code-2')).toMatchObject({
|
||||
expect(
|
||||
collections.tournamentCode.find((code) => code._id === 'code-2'),
|
||||
).toMatchObject({
|
||||
code: 'B',
|
||||
releasedAt: now,
|
||||
state: 'released',
|
||||
});
|
||||
expect(collections.tournamentCode.find((code) => code._id === 'code-2')).not.toHaveProperty(
|
||||
'matchId',
|
||||
);
|
||||
expect(collections.tournamentCode.find((code) => code._id === 'code-4')).not.toHaveProperty(
|
||||
'riotMatchId',
|
||||
);
|
||||
expect(collections.tournamentCode.find((code) => code._id === 'code-5')).not.toHaveProperty(
|
||||
'riotMatchId',
|
||||
);
|
||||
expect(
|
||||
collections.tournamentCode.find((code) => code._id === 'code-2'),
|
||||
).not.toHaveProperty('matchId');
|
||||
expect(
|
||||
collections.tournamentCode.find((code) => code._id === 'code-4'),
|
||||
).not.toHaveProperty('riotMatchId');
|
||||
expect(
|
||||
collections.tournamentCode.find((code) => code._id === 'code-5'),
|
||||
).not.toHaveProperty('riotMatchId');
|
||||
expect(collections.match[0].tournamentCodeIds).toEqual(['code-1']);
|
||||
expect(indexes).toEqual(
|
||||
expect.arrayContaining([
|
||||
@@ -375,7 +377,9 @@ describe('migrateTournamentCodeUniqueIndexes', () => {
|
||||
expect.objectContaining({
|
||||
key: { matchId: 1, bracketMatchId: 1 },
|
||||
name: 'matchId_1_bracketMatchId_1',
|
||||
unique: true,
|
||||
partialFilterExpression: expect.objectContaining({
|
||||
state: { $in: ['reserved', 'used'] },
|
||||
}),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
key: { riotMatchId: 1 },
|
||||
@@ -421,7 +425,6 @@ describe('migrateTournamentCodeUniqueIndexes', () => {
|
||||
expect.objectContaining({
|
||||
key: { matchId: 1, bracketMatchId: 1 },
|
||||
name: 'matchId_1_bracketMatchId_1',
|
||||
unique: true,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
key: { riotMatchId: 1 },
|
||||
@@ -501,6 +504,49 @@ describe('migrateTournamentCodeUniqueIndexes', () => {
|
||||
expect(JSON.stringify(collections.match)).toBe(beforeMatches);
|
||||
});
|
||||
|
||||
it('allows multiple active codes for the same double-elimination bracket match', async () => {
|
||||
const { db, collections } = createDb({
|
||||
codes: [
|
||||
{
|
||||
_id: 'code-1',
|
||||
matchId: 'match-1',
|
||||
gameNumber: 1,
|
||||
bracketMatchId: 'WB_R1_M1',
|
||||
state: 'reserved',
|
||||
},
|
||||
{
|
||||
_id: 'code-2',
|
||||
matchId: 'match-1',
|
||||
gameNumber: 2,
|
||||
bracketMatchId: 'WB_R1_M1',
|
||||
state: 'reserved',
|
||||
},
|
||||
],
|
||||
matches: [{ _id: 'match-1', tournamentCodeIds: ['code-1', 'code-2'] }],
|
||||
});
|
||||
|
||||
const result = await migrateTournamentCodeUniqueIndexes(db, {
|
||||
dryRun: false,
|
||||
createIndexes: false,
|
||||
});
|
||||
|
||||
expect(result.stats).toMatchObject({
|
||||
duplicateBracketMatchGroups: 0,
|
||||
duplicateCodesReleased: 0,
|
||||
duplicateCodesToRelease: 0,
|
||||
});
|
||||
expect(collections.tournamentCode).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ _id: 'code-1', state: 'reserved' }),
|
||||
expect.objectContaining({ _id: 'code-2', state: 'reserved' }),
|
||||
]),
|
||||
);
|
||||
expect(collections.match[0].tournamentCodeIds).toEqual([
|
||||
'code-1',
|
||||
'code-2',
|
||||
]);
|
||||
});
|
||||
|
||||
it('unsets blank riot match ids without treating them as duplicate releases', async () => {
|
||||
const { db, collections } = createDb({
|
||||
codes: [
|
||||
|
||||
Reference in new issue
Block a user