Skip to content

Commit 2e76222

Browse files
committed
more tests
1 parent 1a2ab94 commit 2e76222

12 files changed

Lines changed: 64 additions & 47 deletions

src/lib/api/wca-env.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
console.log('env', import.meta.env);
21
const searchParams = new URLSearchParams(window.location.search);
32
export const STAGING_QUERY_PARAMS = searchParams.has('staging');
43

src/lib/importExport/import.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,22 @@ const buildCompetition = (rooms: any[], persons: Person[]): Competition => ({
3636
id: 'comp',
3737
shortName: 'comp',
3838
name: 'Comp',
39+
formatVersion: 'v1.0',
3940
competitorLimit: null,
40-
competitors: [],
41+
extensions: [],
4142
schedule: {
43+
startDate: '2024-01-01',
44+
numberOfDays: 1,
4245
venues: [
4346
{
4447
id: 1,
4548
name: 'Venue',
49+
latitudeMicrodegrees: 0,
50+
longitudeMicrodegrees: 0,
51+
countryIso2: 'US',
52+
timezone: 'America/New_York',
4653
rooms,
54+
extensions: [],
4755
},
4856
],
4957
},
@@ -55,9 +63,9 @@ const buildCompetition = (rooms: any[], persons: Person[]): Competition => ({
5563
{
5664
id: '333-r1',
5765
format: 'a',
58-
advancesTo: null,
59-
cutOff: null,
66+
cutoff: null,
6067
timeLimit: null,
68+
advancementCondition: null,
6169
results: [],
6270
scrambleSetCount: 1,
6371
extensions: [],
@@ -72,14 +80,18 @@ const buildCompetition = (rooms: any[], persons: Person[]): Competition => ({
7280

7381
const competitor = (overrides: Partial<Person>): Person => ({
7482
registrantId: 1,
83+
wcaUserId: 1,
7584
name: 'Alice',
7685
email: 'alice@example.com',
7786
countryIso2: 'US',
7887
assignments: [],
7988
registration: {
89+
wcaRegistrationId: 1,
8090
status: 'accepted',
8191
eventIds: ['333'],
92+
isCompeting: true,
8293
},
94+
extensions: [],
8395
...overrides,
8496
});
8597

src/lib/importExport/import.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface ParsedAssignment {
4343
export const validate = (wcif: Competition) => (data: ImportData): ValidationCheck[] => {
4444
const checks: ValidationCheck[] = [];
4545

46-
if (!data.meta.fields.indexOf('email') === -1) {
46+
if (data.meta.fields.indexOf('email') === -1) {
4747
checks.push({
4848
key: 'email',
4949
passed: false,
@@ -179,7 +179,7 @@ export const findCompetingAssignment = (
179179

180180
const matchWithoutStage = data.match(competitorAssignmentRegexWithoutStage);
181181

182-
if (stages.length > 2 && matchWithoutStage) {
182+
if (stages.length > 1 && matchWithoutStage) {
183183
throw new Error('Stage data for competitor assignment is ambiguous');
184184
}
185185

@@ -343,7 +343,7 @@ export const determineMissingGroupActivities = (
343343
const bParsedActivityCode = parseActivityCode(b.activityCode);
344344

345345
if (aParsedActivityCode.eventId === bParsedActivityCode.eventId) {
346-
return aParsedActivityCode.groupNumber - bParsedActivityCode.groupNumber;
346+
return (aParsedActivityCode.groupNumber ?? 0) - (bParsedActivityCode.groupNumber ?? 0);
347347
} else {
348348
return (
349349
events.findIndex((e) => e.id === aParsedActivityCode.eventId) -
@@ -444,8 +444,12 @@ export const generateMissingGroupActivities = (
444444
throw new Error(`Could not find round activity ${eventRound} in room ${roomId}`);
445445
}
446446

447+
if (groupNumber === undefined) {
448+
return;
449+
}
450+
447451
roundActivity.childActivities.push(
448-
createGroupActivity(startingActivityId, roundActivity as Activity, groupNumber)
452+
createGroupActivity(startingActivityId, roundActivity as Activity, groupNumber, roundActivity.startTime, roundActivity.endTime)
449453
);
450454

451455
startingActivityId += 1;
@@ -484,7 +488,7 @@ export const balanceStartAndEndTimes = (
484488
return childActivity;
485489
}
486490

487-
const groupNumber = parseActivityCode(childActivity.activityCode).groupNumber;
491+
const groupNumber = parseActivityCode(childActivity.activityCode).groupNumber ?? 1;
488492

489493
return {
490494
...childActivity,

src/lib/utils/time.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
declare const navigator: Navigator;
1212

1313
const setNavigatorLanguages = (languages: string[]) => {
14-
// @ts-expect-error - test helper for overriding languages
1514
Object.defineProperty(globalThis, 'navigator', {
1615
value: { ...navigator, languages },
1716
configurable: true,

src/lib/wcif/groups.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ const baseRound: Activity = {
2121

2222
const buildWcif = (roundActivities: Activity[]): Competition => ({
2323
schedule: {
24+
startDate: '2024-01-01',
25+
numberOfDays: 1,
2426
venues: [
2527
{
2628
id: 1,
29+
name: 'Main Venue',
30+
latitudeMicrodegrees: 0,
31+
longitudeMicrodegrees: 0,
32+
countryIso2: 'US',
33+
timezone: 'America/New_York',
34+
extensions: [],
2735
rooms: [
2836
{
2937
id: 10,
3038
name: 'Main Room',
3139
activities: roundActivities,
3240
color: '#000',
41+
extensions: [],
3342
},
3443
],
3544
},
@@ -40,8 +49,9 @@ const buildWcif = (roundActivities: Activity[]): Competition => ({
4049
id: 'test-competition',
4150
shortName: 'test',
4251
name: 'Test',
52+
formatVersion: 'v1.0',
4353
competitorLimit: null,
44-
competitors: [],
54+
extensions: [],
4555
});
4656

4757
describe('group helpers', () => {
@@ -105,8 +115,8 @@ describe('group helpers', () => {
105115
});
106116

107117
it('calculates group sizes for a round id', () => {
108-
const group1 = { id: 2, activityCode: '333-r1-g1', childActivities: [], extensions: [] } as Activity;
109-
const group2 = { id: 3, activityCode: '333-r1-g2', childActivities: [], extensions: [] } as Activity;
118+
const group1 = { id: 2, name: '333 Round 1 Group 1', activityCode: '333-r1-g1', startTime: '2024-01-01T10:00:00Z', endTime: '2024-01-01T11:00:00Z', childActivities: [], extensions: [] } as Activity;
119+
const group2 = { id: 3, name: '333 Round 1 Group 2', activityCode: '333-r1-g2', startTime: '2024-01-01T10:00:00Z', endTime: '2024-01-01T11:00:00Z', childActivities: [], extensions: [] } as Activity;
110120
const roundWithGroups: Activity = {
111121
...baseRound,
112122
childActivities: [group1, group2],

src/lib/wcif/validation/eventRoundValidation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { describe, it, expect } from 'vitest';
2-
import type { Competition, Event } from '@wca/helpers';
31
import {
42
validateEventHasRounds,
53
validateAdvancementConditions,
@@ -11,6 +9,8 @@ import {
119
NO_ROUNDS_FOR_ACTIVITY,
1210
NO_SCHEDULE_ACTIVITIES_FOR_ROUND,
1311
} from './types';
12+
import type { Competition, Event } from '@wca/helpers';
13+
import { describe, it, expect } from 'vitest';
1414

1515
const mockWcif: Competition = {
1616
formatVersion: '1.0',

src/lib/wcif/validation/eventRoundValidation.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import type { Competition, Event } from '@wca/helpers';
2-
import {
3-
activityCodeToName,
4-
findAllRoundActivities,
5-
} from '../../domain';
1+
import { activityCodeToName, findAllRoundActivities } from '../../domain';
62
import { flatMap } from '../../utils';
73
import {
84
MISSING_ADVANCEMENT_CONDITION,
95
NO_ROUNDS_FOR_ACTIVITY,
106
NO_SCHEDULE_ACTIVITIES_FOR_ROUND,
117
ValidationError,
128
} from './types';
9+
import type { Competition, Event } from '@wca/helpers';
1310

1411
/**
1512
* Validates that an event has at least one round configured
@@ -57,12 +54,12 @@ export const validateRoundsHaveScheduleActivities = (
5754
event: Event
5855
): ValidationError[] => {
5956
const allRoundActivities = findAllRoundActivities(wcif);
60-
57+
6158
return flatMap(event.rounds, (round) => {
6259
const hasScheduleActivity = allRoundActivities.some((activity) =>
6360
activity.activityCode.startsWith(round.id)
6461
);
65-
62+
6663
return hasScheduleActivity
6764
? []
6865
: [
@@ -91,7 +88,7 @@ export const validateEventRounds = (wcif: Competition): ValidationError[] => {
9188

9289
const advancementErrors = validateAdvancementConditions(event);
9390
const scheduleActivityErrors = validateRoundsHaveScheduleActivities(wcif, event);
94-
91+
9592
return [...advancementErrors, ...scheduleActivityErrors];
9693
});
9794
};

src/lib/wcif/validation/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { describe, it, expect } from 'vitest';
2-
import type { Competition } from '@wca/helpers';
31
import { validateWcif } from './index';
42
import {
53
MISSING_ADVANCEMENT_CONDITION,
64
NO_ROUNDS_FOR_ACTIVITY,
75
MISSING_ACTIVITY_FOR_PERSON_ASSIGNMENT,
86
PERSON_ASSIGNMENT_SCHEDULE_CONFLICT,
97
} from './types';
8+
import type { Competition } from '@wca/helpers';
9+
import { describe, it, expect } from 'vitest';
1010

1111
const mockWcif: Competition = {
1212
formatVersion: '1.0',
@@ -232,15 +232,15 @@ describe('validateWcif', () => {
232232
const errors = validateWcif(wcif);
233233

234234
expect(errors.length).toBeGreaterThan(0);
235-
235+
236236
// Check for event errors
237237
const noRoundsErrors = errors.filter((e) => e.type === NO_ROUNDS_FOR_ACTIVITY);
238238
expect(noRoundsErrors.length).toBeGreaterThan(0);
239-
239+
240240
// Check for advancement condition errors
241241
const advancementErrors = errors.filter((e) => e.type === MISSING_ADVANCEMENT_CONDITION);
242242
expect(advancementErrors.length).toBeGreaterThan(0);
243-
243+
244244
// Check for person assignment errors
245245
const assignmentErrors = errors.filter(
246246
(e) => e.type === MISSING_ACTIVITY_FOR_PERSON_ASSIGNMENT

src/lib/wcif/validation/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Competition } from '@wca/helpers';
21
import { validateEventRounds } from './eventRoundValidation';
32
import { validatePersonAssignments } from './personAssignmentValidation';
43
import type { ValidationError } from './types';
4+
import type { Competition } from '@wca/helpers';
55

66
export * from './types';
77
export * from './eventRoundValidation';
@@ -15,6 +15,6 @@ export * from './personAssignmentValidation';
1515
export const validateWcif = (wcif: Competition): ValidationError[] => {
1616
const eventRoundErrors = validateEventRounds(wcif);
1717
const personAssignmentErrors = validatePersonAssignments(wcif);
18-
18+
1919
return [...eventRoundErrors, ...personAssignmentErrors].filter(Boolean);
2020
};

src/lib/wcif/validation/personAssignmentValidation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { describe, it, expect } from 'vitest';
2-
import type { Competition, Person } from '@wca/helpers';
31
import {
42
validatePersonAssignmentActivitiesExist,
53
validatePersonAssignmentScheduleConflicts,
@@ -9,6 +7,8 @@ import {
97
MISSING_ACTIVITY_FOR_PERSON_ASSIGNMENT,
108
PERSON_ASSIGNMENT_SCHEDULE_CONFLICT,
119
} from './types';
10+
import type { Competition, Person } from '@wca/helpers';
11+
import { describe, it, expect } from 'vitest';
1212

1313
const mockWcif: Competition = {
1414
formatVersion: '1.0',

0 commit comments

Comments
 (0)