Skip to content

Commit

Permalink
test: ✅ extend test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
CourtHive committed Mar 19, 2024
1 parent b830a12 commit a7eba6d
Showing 1 changed file with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import tournamentEngine from '@Engines/syncEngine';
import mocksEngine from '@Assemblies/engines/mock';
import { expect, it } from 'vitest';

import { COMPASS } from '@Constants/drawDefinitionConstants';
import { COMPASS, ROUND_ROBIN } from '@Constants/drawDefinitionConstants';

it('can rename structures', () => {
const {
tournamentRecord,
drawIds: [drawId],
} = mocksEngine.generateTournamentRecord({
drawProfiles: [{ drawType: COMPASS, drawSize: 32 }],
setState: true,
});

let result = tournamentEngine.setState(tournamentRecord);
expect(result.success).toEqual(true);

let { drawDefinition } = tournamentEngine.getEvent({ drawId });
let structureMap = Object.assign(
{},
Expand All @@ -39,7 +36,7 @@ it('can rename structures', () => {
structureId,
}));

result = tournamentEngine.renameStructures({ drawId, structureDetails });
const result = tournamentEngine.renameStructures({ drawId, structureDetails });
expect(result.success).toEqual(true);

drawDefinition = tournamentEngine.getEvent({ drawId }).drawDefinition;
Expand All @@ -52,3 +49,35 @@ it('can rename structures', () => {

expect(Object.values(structureMap)).toEqual(newNames);
});

it('can rename contained structures', () => {
const {
drawIds: [drawId],
} = mocksEngine.generateTournamentRecord({
drawProfiles: [{ drawType: ROUND_ROBIN, drawSize: 32 }],
setState: true,
});

let { drawDefinition } = tournamentEngine.getEvent({ drawId });
const getStructureMap = (structure) =>
structure.structures.reduce((groups, { structureId, structureName }) => {
groups[structureId] = {
structureName,
structureId,
};
return groups;
}, {});
const newNames = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
const structureDetails = Object.keys(getStructureMap(drawDefinition.structures[0])).map((structureId, i) => ({
structureName: newNames[i],
structureId,
}));

const result = tournamentEngine.renameStructures({ drawId, structureDetails });
expect(result.success).toEqual(true);

drawDefinition = tournamentEngine.getEvent({ drawId }).drawDefinition;
const structureMap = getStructureMap(drawDefinition.structures[0]);

expect(Object.values(structureMap).map((s: any) => s.structureName)).toEqual(newNames);
});

0 comments on commit a7eba6d

Please sign in to comment.