-
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: ✅ extend test coverage and cleanup
- Loading branch information
Showing
7 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/tests/generators/events/generateEventsFromTieFormat.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,86 @@ | ||
import mocksEngine from '@Assemblies/engines/mock'; | ||
import tournamentEngine from '@Engines/syncEngine'; | ||
import { expect, it } from 'vitest'; | ||
|
||
// Constants | ||
import { INVALID_TIE_FORMAT, INVALID_VALUES } from '@Constants/errorConditionConstants'; | ||
import { USTA_GOLD_TEAM_CHALLENGE } from '@Constants/tieFormatConstants'; | ||
import tieFormatDefaults from '@Generators/templates/tieFormatDefaults'; | ||
import { ALTERNATE, UNGROUPED } from '@Constants/entryStatusConstants'; | ||
import { SINGLES_EVENT, TEAM_EVENT } from '@Constants/eventConstants'; | ||
import { TEAM_PARTICIPANT } from '@Constants/participantConstants'; | ||
import { FEMALE, MALE, MIXED } from '@Constants/genderConstants'; | ||
|
||
it('can generate singles/doubles events from tieFormats', () => { | ||
const drawSize = 8; | ||
mocksEngine.generateTournamentRecord({ | ||
participantsProfile: { participantsCount: 0 }, // required to force generation of tieFormat-specific participants | ||
drawProfiles: [ | ||
{ generate: false, addEvent: false, eventType: TEAM_EVENT, drawSize, tieFormatName: USTA_GOLD_TEAM_CHALLENGE }, | ||
], | ||
setState: true, | ||
}); | ||
|
||
let events = tournamentEngine.getEvents().events; | ||
expect(events.length).toBe(0); | ||
|
||
const teamParticipants = tournamentEngine.getParticipants({ | ||
participantFilters: { participantTypes: [TEAM_PARTICIPANT] }, | ||
withIndividualParticipants: true, | ||
}).participants; | ||
expect(teamParticipants.length).toBe(drawSize); | ||
teamParticipants.forEach((teamParticipant) => { | ||
expect(teamParticipant.individualParticipantIds.length).toEqual(8); | ||
const genders = teamParticipant.individualParticipants.map((p) => p.person?.sex); | ||
expect(genders).toEqual([FEMALE, FEMALE, FEMALE, FEMALE, MALE, MALE, MALE, MALE]); | ||
}); | ||
|
||
let result = tournamentEngine.generateEventsFromTieFormat(); | ||
expect(result.error).toEqual(INVALID_VALUES); | ||
|
||
result = tournamentEngine.generateEventsFromTieFormat({ tieFormat: {} }); | ||
expect(result.error).toEqual(INVALID_TIE_FORMAT); | ||
|
||
result = tournamentEngine.generateEventsFromTieFormat({ tieFormatName: {} }); | ||
expect(result.error).toEqual(INVALID_VALUES); | ||
|
||
result = tournamentEngine.generateEventsFromTieFormat({ tieFormatName: '' }); | ||
expect(result.error).toEqual(INVALID_VALUES); | ||
|
||
const tieFormat = tieFormatDefaults({ namedFormat: USTA_GOLD_TEAM_CHALLENGE }); | ||
|
||
const entryStatus = ALTERNATE; | ||
result = tournamentEngine.generateEventsFromTieFormat({ | ||
addEntriesFromTeams: true, | ||
addEvents: false, | ||
entryStatus, | ||
tieFormat, | ||
}); | ||
expect(result.events.length).toBe(5); | ||
expect(result.success).toBe(true); | ||
for (const event of result.events) { | ||
if (event.gender === MIXED) { | ||
// 64 entries because 8 teams with 8 individualParticipants each = 64, all INDIVIDUALS are UNGROUPED | ||
expect(event.entries.length).toBe(64); | ||
} else { | ||
// 32 entries in SINGLES because 8 teams with 4 gendered individualParticipants each = 32 | ||
// 32 entries in DOUBLES because 8 teams with 4 gendered individualParticipants each = 32, all INDIVIDUALS are UNGROUPED | ||
expect(event.entries.length).toBe(32); | ||
} | ||
|
||
if (event.eventType === SINGLES_EVENT) { | ||
expect(event.entries.every((entry) => entry.entryStatus === entryStatus)).toBe(true); | ||
} else { | ||
expect(event.entries.every((entry) => entry.entryStatus === UNGROUPED)).toBe(true); | ||
} | ||
} | ||
|
||
events = tournamentEngine.getEvents().events; | ||
expect(events.length).toBe(0); | ||
|
||
result = tournamentEngine.generateEventsFromTieFormat({ tieFormatName: USTA_GOLD_TEAM_CHALLENGE }); | ||
expect(result.success).toBe(true); | ||
|
||
events = tournamentEngine.getEvents().events; | ||
expect(events.length).toBe(5); | ||
}); |
87 changes: 87 additions & 0 deletions
87
src/tests/generators/leagueScenarios/leagueNoRounds.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,87 @@ | ||
import { mocksEngine } from '@Assemblies/engines/mock'; | ||
import tournamentEngine from '@Engines/syncEngine'; | ||
import { expect, it } from 'vitest'; | ||
|
||
// constants | ||
import { TEAM_PARTICIPANT } from '@Constants/participantConstants'; | ||
import { FEMALE, MALE, MIXED } from '@Constants/genderConstants'; | ||
import { DOUBLES, SINGLES } from '@Constants/matchUpTypes'; | ||
import { TEAM_EVENT } from '@Constants/eventConstants'; | ||
import { instanceCount } from '@Tools/arrays'; | ||
|
||
it('can generate Teams from drawProfiles without persisting events', () => { | ||
const matchUpCount = 2; | ||
const tieFormat = { | ||
collectionDefinitions: [ | ||
{ | ||
collectionName: 'Doubles', | ||
matchUpType: DOUBLES, | ||
collectionOrder: 1, | ||
matchUpValue: 1, | ||
gender: MIXED, | ||
matchUpCount, | ||
}, | ||
{ | ||
collectionName: 'Singles', | ||
matchUpType: SINGLES, | ||
collectionOrder: 2, | ||
matchUpValue: 1, | ||
gender: MALE, | ||
matchUpCount, | ||
}, | ||
{ | ||
collectionName: 'Singles', | ||
matchUpType: SINGLES, | ||
collectionOrder: 2, | ||
matchUpValue: 1, | ||
gender: FEMALE, | ||
matchUpCount, | ||
}, | ||
], | ||
winCriteria: { aggregateValue: true }, | ||
}; | ||
|
||
const teamNames = ['Team One', 'Team Two']; | ||
const drawSize = 4; | ||
const mockProfile = { | ||
participantsProfile: { participantsCount: 0 }, // do not generate participants unless specified by drawProfile(s) | ||
drawProfiles: [ | ||
{ | ||
eventType: TEAM_EVENT, | ||
addEvent: false, // do not add event to tournamentRecord, only generate participants | ||
generate: false, | ||
teamNames, | ||
tieFormat, | ||
drawSize, | ||
}, | ||
], | ||
}; | ||
|
||
const { tournamentRecord } = mocksEngine.generateTournamentRecord({ | ||
setState: true, | ||
...mockProfile, | ||
}); | ||
|
||
const participantResult = tournamentEngine.getParticipants({ withIndividualParticipants: true }); | ||
const teams = participantResult.participants.filter((p) => p.participantType === TEAM_PARTICIPANT); | ||
|
||
for (const team of teams) { | ||
const counts = instanceCount(team.individualParticipants.map((i) => i.person.sex)); | ||
expect(counts.FEMALE).toEqual(matchUpCount); | ||
expect(counts.MALE).toEqual(matchUpCount); | ||
} | ||
|
||
expect(teams.map((team) => team.participantName).slice(0, 2)).toEqual(teamNames); | ||
|
||
const teamIndividualParticipants = teams | ||
.reduce((acc, team) => { | ||
acc.push(...team.individualParticipantIds); | ||
return acc; | ||
}, []) | ||
.map((participantId) => participantResult.participantMap[participantId]); | ||
|
||
const gendersCount = 2; | ||
expect(teamIndividualParticipants.length).toEqual(drawSize * matchUpCount * gendersCount); | ||
|
||
expect(tournamentRecord.events).toBeUndefined(); | ||
}); |
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
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
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
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
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