-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for qualifying and main tieFormat scenarios
- Loading branch information
1 parent
cf48b8a
commit 4ab29f5
Showing
2 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
222 changes: 222 additions & 0 deletions
222
...tests/mutations/drawDefinitions/structures/qualifying/mainThenQualifyingTieFormat.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
import tournamentEngine from '@Engines/syncEngine'; | ||
import mocksEngine from '@Assemblies/engines/mock'; | ||
import { expect, it } from 'vitest'; | ||
|
||
import { MAIN, QUALIFYING } from '@Constants/drawDefinitionConstants'; | ||
import { INDIVIDUAL, TEAM } from '@Constants/participantConstants'; | ||
import { SINGLES } from '@Constants/eventConstants'; | ||
import { DOUBLES } from '@Constants/matchUpTypes'; | ||
import { ANY, MALE } from '@Constants/genderConstants'; | ||
|
||
it('can generateDrawDefinition a main structure, then generate a qualifying structure with a different tieFormat saved to the structure', () => { | ||
const { | ||
tournamentRecord, | ||
eventIds: [eventId], | ||
} = mocksEngine.generateTournamentRecord({ | ||
participantsProfile: { participantType: TEAM, participantsCount: 40 }, | ||
eventProfiles: [{ eventName: 'test', eventType: TEAM }], | ||
}); | ||
|
||
const individualParticipants = tournamentRecord.participants.filter((p) => p.participantType === INDIVIDUAL); | ||
const teamParticipants = tournamentRecord.participants.filter((p) => p.participantType === TEAM); | ||
|
||
expect(individualParticipants.length).toEqual(320); | ||
expect(teamParticipants.length).toEqual(40); | ||
|
||
tournamentEngine.setState(tournamentRecord); | ||
|
||
const participantIds = teamParticipants.map((p) => p.participantId); | ||
const mainParticipantIds = participantIds.slice(0, 14); | ||
const qualifyingParticipantIds = participantIds.slice(14, 28); | ||
|
||
let result = tournamentEngine.addEventEntries({ | ||
participantIds: mainParticipantIds, | ||
eventId, | ||
}); | ||
expect(result.success).toEqual(true); | ||
|
||
result = tournamentEngine.addEventEntries({ | ||
participantIds: qualifyingParticipantIds, | ||
entryStage: QUALIFYING, | ||
eventId, | ||
}); | ||
expect(result.success).toEqual(true); | ||
|
||
const qualifyingTieFormat = { | ||
tieFormatName: 'CUSTOM', | ||
collectionDefinitions: [ | ||
{ | ||
category: { | ||
ageCategoryCode: 'U18', | ||
}, | ||
gender: ANY, | ||
collectionOrder: 1, | ||
matchUpValue: 1, | ||
collectionName: 'Qualifying Collection', | ||
matchUpCount: 3, | ||
matchUpType: DOUBLES, | ||
matchUpFormat: 'SET3-S:6/TB7', | ||
collectionId: 'Q-collection1', | ||
}, | ||
], | ||
winCriteria: { | ||
valueGoal: 2, | ||
success: true, | ||
}, | ||
}; | ||
|
||
const mainTieFormat = { | ||
tieFormatName: 'CUSTOM', | ||
collectionDefinitions: [ | ||
{ | ||
category: { | ||
ageCategoryCode: 'U18', | ||
}, | ||
gender: MALE, | ||
collectionOrder: 1, | ||
matchUpValue: 1, | ||
collectionName: 'Main Collection', | ||
matchUpCount: 2, | ||
matchUpType: SINGLES, | ||
matchUpFormat: 'SET3-S:6/TB7', | ||
collectionId: 'M-collection1', | ||
}, | ||
], | ||
winCriteria: { | ||
valueGoal: 2, | ||
success: true, | ||
}, | ||
}; | ||
|
||
const drawEntries = [ | ||
...mainParticipantIds.map((p, i) => ({ | ||
participantId: p, | ||
entryStatus: 'DIRECT_ACCEPTANCE', | ||
entryStage: 'MAIN', | ||
entryPosition: i + 1, | ||
})), | ||
...qualifyingParticipantIds.slice(0, 2).map((p, i) => ({ | ||
participantId: p, | ||
entryStatus: 'DIRECT_ACCEPTANCE', | ||
entryStage: 'QUALIFYING', | ||
entryPosition: i + 1, | ||
})), | ||
]; | ||
|
||
const { drawDefinition: mainDrawDefinition } = tournamentEngine.generateDrawDefinition({ | ||
drawSize: 16, | ||
drawType: 'SINGLE_ELIMINATION', | ||
structureOptions: { | ||
groupSize: 4, | ||
}, | ||
seedingProfile: {}, | ||
voluntaryConsolation: false, | ||
advancedPerGroup: '1', | ||
advancementType: 'TOP_FINISHERS', | ||
automated: 'automated', | ||
drawName: 'Draw', | ||
drawStage: 'MAIN', | ||
matchUpFormat: 'SET1-S:TB11NOAD', | ||
placeRemainingPlayers: false, | ||
playoffStructure: 'COMPASS', | ||
qualifiersCount: 2, | ||
qualifyingDrawSize: 4, | ||
qualifyingSeedsCount: 0, | ||
scoring: 's3', | ||
seedsCount: 0, | ||
tieFormatName: '', | ||
eventId: eventId, | ||
ignoreStageSpace: true, | ||
tieFormat: mainTieFormat, | ||
drawEntries, | ||
enforceMinimumDrawSize: false, | ||
hydrateCollections: true, | ||
seedByRanking: false, | ||
ignoreAllowedDrawTypes: true, | ||
feedPolicy: { | ||
roundGroupedOrder: [[1], [1], [1, 2], [3, 4, 1, 2], [2, 1, 4, 3, 6, 5, 8, 7], [1]], | ||
roundFeedProfiles: [ | ||
'TOP_DOWN', | ||
'BOTTOM_UP', | ||
'BOTTOM_UP', | ||
'BOTTOM_UP', | ||
'BOTTOM_UP', | ||
'BOTTOM_UP', | ||
'BOTTOM_UP', | ||
'BOTTOM_UP', | ||
], | ||
}, | ||
finishingPositionNaming: { | ||
'3-4': { | ||
name: '3-4 Playoff', | ||
abbreviation: 'PL', | ||
}, | ||
}, | ||
qualifyingPlaceholder: true, | ||
activeTournamentId: tournamentRecord.tournamentId, | ||
}); | ||
|
||
tournamentEngine.addDrawDefinition({ | ||
activeTournamentId: tournamentRecord.tournamentId, | ||
drawDefinition: mainDrawDefinition, | ||
allowReplacement: true, | ||
existingDrawCount: 0, | ||
eventId, | ||
}); | ||
|
||
// verify main structure has been created with tieFormat at drawDefinition level and not on structure level | ||
const mainStructure = mainDrawDefinition.structures.find(({ stage }) => stage === MAIN); | ||
expect(mainStructure.matchUps.length).toEqual(15); | ||
expect(mainStructure.matchUps[0].tieMatchUps.length).toEqual(2); | ||
expect(mainStructure.tieFormat).toBeUndefined(); | ||
expect(mainDrawDefinition.tieFormat.collectionDefinitions.length).toEqual(1); | ||
expect(mainDrawDefinition.tieFormat.collectionDefinitions[0].collectionName).toEqual('Main Collection'); | ||
expect(mainDrawDefinition.tieFormat.collectionDefinitions[0].collectionId).toEqual( | ||
mainTieFormat.collectionDefinitions[0].collectionId, | ||
); | ||
|
||
const { drawDefinition } = tournamentEngine.generateDrawDefinition({ | ||
activeTournamentId: tournamentRecord.tournamentId, | ||
automated: 'automated', | ||
drawEntries, | ||
drawId: mainDrawDefinition.drawId, | ||
drawName: 'Draw', | ||
eventId, | ||
ignoreStageSpace: true, | ||
qualifyingProfiles: [ | ||
{ | ||
structureProfiles: [ | ||
{ | ||
drawSize: 4, | ||
matchUpFormat: 'SET1-S:TB11NOAD', | ||
qualifyingPositions: 2, | ||
seedsCount: 0, | ||
}, | ||
], | ||
}, | ||
], | ||
tieFormat: qualifyingTieFormat, | ||
}); | ||
|
||
// reverify main structure has been created with tieFormat at drawDefinition level and not on structure level | ||
const newMainStructure = drawDefinition.structures.find(({ stage }) => stage === MAIN); | ||
expect(newMainStructure.matchUps.length).toEqual(15); | ||
expect(newMainStructure.matchUps[0].tieMatchUps.length).toEqual(2); | ||
expect(newMainStructure.tieFormat).toBeUndefined(); | ||
|
||
expect(drawDefinition.tieFormat.collectionDefinitions.length).toEqual(1); | ||
expect(drawDefinition.tieFormat.collectionDefinitions[0].collectionName).toEqual('Main Collection'); | ||
expect(drawDefinition.tieFormat.collectionDefinitions[0].collectionId).toEqual( | ||
mainTieFormat.collectionDefinitions[0].collectionId, | ||
); | ||
|
||
// verify qualifying structure has been created with tieFormat at structure level | ||
const qualifyingStructure = drawDefinition.structures.find(({ stage }) => stage === QUALIFYING); | ||
expect(qualifyingStructure.matchUps.length).toEqual(2); | ||
expect(qualifyingStructure.matchUps[0].tieMatchUps.length).toEqual(3); | ||
expect(qualifyingStructure.tieFormat.collectionDefinitions.length).toEqual(1); | ||
expect(qualifyingStructure.tieFormat.collectionDefinitions[0].collectionName).toEqual('Qualifying Collection'); | ||
expect(qualifyingStructure.tieFormat.collectionDefinitions[0].collectionId).toEqual( | ||
qualifyingTieFormat.collectionDefinitions[0].collectionId, | ||
); | ||
}); |
Oops, something went wrong.