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 Apr 22, 2024
1 parent 0bd0e92 commit 4e3e9e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UUID } from '@Tools/UUID';
import { INVALID_DATE } from '@Constants/errorConditionConstants';

export function createTournamentRecord(params): any {
const attributes = params || {};
const { tournamentRecord, tournamentRecords, activeTournamentId, ...attributes } = params || {};
if (!attributes.tournamentId) attributes.tournamentId = UUID();
if (attributes.startDate && !isISODateString(attributes.startDate) && !validDateString.test(attributes.startDate)) {
return { error: INVALID_DATE };
Expand Down
23 changes: 23 additions & 0 deletions src/tests/mutations/tournaments/copyTournamentRecord.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import tournamentEngine from '@Engines/syncEngine';
import mocksEngine from '@Assemblies/engines/mock';
import { expect, test } from 'vitest';

// Constants
import { INVALID_VALUES } from '@Constants/errorConditionConstants';
import { addDays } from '@Tools/dateTime';

test('can copy a tournamentRecord', () => {
const startDate = '2024-05-01';
const tournamentId = 'tid';
mocksEngine.generateTournamentRecord({ startDate, tournamentId, drawProfiles: [{ drawSize: 8 }], setState: true });
let result = tournamentEngine.copyTournamentRecord();
expect(result.error).toEqual(INVALID_VALUES);
result = tournamentEngine.copyTournamentRecord({ startDate: addDays(startDate, 7) });
expect(result.error).toEqual(INVALID_VALUES);
result = tournamentEngine.copyTournamentRecord({
tournamentName: 'Tournament Copy',
startDate: addDays(startDate, 7),
});
expect(result.tournamentRecord.tournamentName).toEqual('Tournament Copy');
expect(result.tournamentRecord.tournamentId).not.toEqual(tournamentId);
});
15 changes: 15 additions & 0 deletions src/tests/mutations/tournaments/createTournamentRecord.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import tournamentEngine from '@Engines/syncEngine';
import { expect, test } from 'vitest';

// Constants
import { INVALID_DATE } from '@Constants/errorConditionConstants';

test('can create a tournamentRecord', () => {
let result = tournamentEngine.createTournamentRecord();
expect(result.tournamentId).toBeDefined();
result = tournamentEngine.createTournamentRecord({ tournamentName: 'Tournament Name' });
expect(result.tournamentName).toEqual('Tournament Name');
expect(result.tournamentId).toBeDefined();
result = tournamentEngine.createTournamentRecord({ startDate: 'foo' });
expect(result.error).toEqual(INVALID_DATE);
});

0 comments on commit 4e3e9e7

Please sign in to comment.