Skip to content

Commit

Permalink
refactor: ♻️ cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CourtHive committed Apr 22, 2024
1 parent 4e3e9e7 commit ce6282c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 84 deletions.
7 changes: 4 additions & 3 deletions src/helpers/keyValueScore/keyValueScore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { getMatchUpWinner, removeFromScore, getHighTiebreakValue } from './keyValueUtilities';
import { getLeadingSide } from '@Query/matchUp/checkSetIsComplete';
import { processIncompleteSetScore } from './processIncompleteSetScore';
import { getLeadingSide } from '@Query/matchUp/checkSetIsComplete';
import { keyValueTimedSetScore } from './keyValueTimedSetScore';
import { processTiebreakSet } from './processTiebreakSet';
import { arrayIndices } from '@Tools/arrays';
import { ensureInt } from '@Tools/ensureInt';
import { keyValueSetScore } from './keyValueSetScore';
import { getScoreAnalysis } from './scoreAnalysis';
import { processOutcome } from './processOutcome';
import { getWinningSide } from './winningSide';
import { arrayIndices } from '@Tools/arrays';
import { ensureInt } from '@Tools/ensureInt';

// Constants
import { INCOMPLETE, TO_BE_PLAYED } from '@Constants/matchUpStatusConstants';
import {
SET_TIEBREAK_BRACKETS,
Expand Down
3 changes: 2 additions & 1 deletion src/tests/generators/mocks/generateOutcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import mocksEngine from '@Assemblies/engines/mock';
import { generateRange } from '@Tools/arrays';
import { it, test, expect } from 'vitest';

// Constants
import { INVALID_MATCHUP_FORMAT, INVALID_VALUES } from '@Constants/errorConditionConstants';
import {
COMPLETED,
DEFAULTED,
Expand All @@ -11,7 +13,6 @@ import {
SUSPENDED,
WALKOVER,
} from '@Constants/matchUpStatusConstants';
import { INVALID_MATCHUP_FORMAT, INVALID_VALUES } from '@Constants/errorConditionConstants';

const SET1T20 = 'SET1-S:T20';
const iterations = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { getContextMatchUp, getOrderedDrawPositionPairs } from '../../drawDefinitions/testingUtilities';
import mocksEngine from '@Assemblies/engines/mock';
import tournamentEngine from '@Engines/syncEngine';
import { expect, it } from 'vitest';
import { getContextMatchUp, getOrderedDrawPositionPairs } from '../../drawDefinitions/testingUtilities';

// Constants
import { INCOMPATIBLE_MATCHUP_STATUS } from '@Constants/errorConditionConstants';
import { INCOMPLETE } from '@Constants/matchUpStatusConstants';

it('DISALLOWS entry of incomplete result if active downsream', () => {
it('DISALLOWS entry of incomplete result if active downstream', () => {
const drawProfiles = [
{
drawSize: 8,
Expand Down Expand Up @@ -38,21 +39,21 @@ it('DISALLOWS entry of incomplete result if active downsream', () => {

const { matchUps } = tournamentEngine.setState(tournamentRecord).allTournamentMatchUps();
const { matchUp } = getContextMatchUp({
matchUps,
roundNumber: 1,
roundPosition: 1,
roundNumber: 1,
matchUps,
});
const { drawId, matchUpId, structureId } = matchUp;

const values = {
scoreString: '6-1',
matchUpStatus: INCOMPLETE,
scoreString: '6-1',
};
const { outcome } = mocksEngine.generateOutcomeFromScoreString(values);
const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome,
drawId,
});
expect(result.error).toEqual(INCOMPATIBLE_MATCHUP_STATUS);

Expand All @@ -66,15 +67,15 @@ it('removes advanced participant when completed score changes to incomplete resu
drawSize: 8,
outcomes: [
{
roundNumber: 1,
roundPosition: 1,
scoreString: '6-1 6-1',
roundPosition: 1,
roundNumber: 1,
winningSide: 1,
},
{
roundNumber: 1,
roundPosition: 2,
scoreString: '6-1 6-2',
roundPosition: 2,
roundNumber: 1,
winningSide: 1,
},
],
Expand All @@ -86,21 +87,21 @@ it('removes advanced participant when completed score changes to incomplete resu

let { matchUps } = tournamentEngine.setState(tournamentRecord).allTournamentMatchUps();
let { matchUp } = getContextMatchUp({
matchUps,
roundNumber: 1,
roundPosition: 1,
roundNumber: 1,
matchUps,
});
const { drawId, matchUpId, structureId } = matchUp;

const values = {
scoreString: '6-1',
matchUpStatus: INCOMPLETE,
scoreString: '6-1',
};
const { outcome } = mocksEngine.generateOutcomeFromScoreString(values);
const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -109,9 +110,9 @@ it('removes advanced participant when completed score changes to incomplete resu

({ matchUps } = tournamentEngine.allTournamentMatchUps());
({ matchUp } = getContextMatchUp({
matchUps,
roundNumber: 1,
roundPosition: 1,
roundNumber: 1,
matchUps,
}));
expect(matchUp.score.scoreStringSide1).toEqual('6-1');
});
Expand All @@ -122,9 +123,9 @@ it('removes advanced participant in FINAL when completed score changes to incomp
drawSize: 2,
outcomes: [
{
roundNumber: 1,
roundPosition: 1,
scoreString: '6-1 6-1',
roundPosition: 1,
roundNumber: 1,
winningSide: 1,
},
],
Expand All @@ -136,29 +137,29 @@ it('removes advanced participant in FINAL when completed score changes to incomp

let { matchUps } = tournamentEngine.setState(tournamentRecord).allTournamentMatchUps();
let { matchUp } = getContextMatchUp({
matchUps,
roundNumber: 1,
roundPosition: 1,
roundNumber: 1,
matchUps,
});
const { drawId, matchUpId } = matchUp;

const values = {
scoreString: '6-1',
matchUpStatus: INCOMPLETE,
scoreString: '6-1',
};
const { outcome } = mocksEngine.generateOutcomeFromScoreString(values);
const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome,
drawId,
});
expect(result.success).toEqual(true);

({ matchUps } = tournamentEngine.allTournamentMatchUps());
({ matchUp } = getContextMatchUp({
matchUps,
roundNumber: 1,
roundPosition: 1,
roundNumber: 1,
matchUps,
}));
expect(matchUp.score.scoreStringSide1).toEqual('6-1');
expect(matchUp.winningSide).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mocksEngine from '@Assemblies/engines/mock';
import tournamentEngine from '@Engines/syncEngine';
import { expect, it } from 'vitest';

// Constants
import {
ABANDONED,
CANCELLED,
Expand All @@ -14,11 +15,7 @@ import {
} from '@Constants/matchUpStatusConstants';

it('supports entering CANCELED matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -28,9 +25,9 @@ it('supports entering CANCELED matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: CANCELLED },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -39,11 +36,7 @@ it('supports entering CANCELED matchUpStatus', () => {
});

it('supports entering ABANDONED matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -53,9 +46,9 @@ it('supports entering ABANDONED matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: ABANDONED },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -64,11 +57,7 @@ it('supports entering ABANDONED matchUpStatus', () => {
});

it('supports entering INCOMPLETE matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -78,9 +67,9 @@ it('supports entering INCOMPLETE matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: INCOMPLETE },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -89,11 +78,7 @@ it('supports entering INCOMPLETE matchUpStatus', () => {
});

it('supports entering SUSPENDED matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -103,9 +88,9 @@ it('supports entering SUSPENDED matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: SUSPENDED },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -114,11 +99,7 @@ it('supports entering SUSPENDED matchUpStatus', () => {
});

it('supports entering DEAD_RUBBER matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -128,9 +109,9 @@ it('supports entering DEAD_RUBBER matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: DEAD_RUBBER },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -139,11 +120,7 @@ it('supports entering DEAD_RUBBER matchUpStatus', () => {
});

it('supports entering NOT_PLAYED matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -153,9 +130,9 @@ it('supports entering NOT_PLAYED matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: NOT_PLAYED },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -164,11 +141,7 @@ it('supports entering NOT_PLAYED matchUpStatus', () => {
});

it('supports entering IN_PROGRESS matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -178,9 +151,9 @@ it('supports entering IN_PROGRESS matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: IN_PROGRESS },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand All @@ -189,11 +162,7 @@ it('supports entering IN_PROGRESS matchUpStatus', () => {
});

it('supports entering AWAITING_RESULT matchUpStatus', () => {
const drawProfiles = [
{
drawSize: 8,
},
];
const drawProfiles = [{ drawSize: 8 }];
const {
drawIds: [drawId],
tournamentRecord,
Expand All @@ -203,9 +172,9 @@ it('supports entering AWAITING_RESULT matchUpStatus', () => {
const matchUpId = upcomingMatchUps[0].matchUpId;

const result = tournamentEngine.setMatchUpStatus({
drawId,
matchUpId,
outcome: { matchUpStatus: AWAITING_RESULT },
matchUpId,
drawId,
});
expect(result.success).toEqual(true);

Expand Down

0 comments on commit ce6282c

Please sign in to comment.