Skip to content

Commit 42c5dcb

Browse files
committed
Fix scorecard CSV export for unknown round formats
1 parent 24ea205 commit 42c5dcb

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/lib/domain/events.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { eventNameById, shortEventNameById, roundFormatById, sortWcifEvents } from './events';
1+
import {
2+
eventNameById,
3+
shortEventNameById,
4+
roundFormatById,
5+
roundFormatShortById,
6+
sortWcifEvents,
7+
} from './events';
28
import { type Event } from '@wca/helpers';
39
import { describe, it, expect } from 'vitest';
410

@@ -96,6 +102,20 @@ describe('roundFormatById', () => {
96102
});
97103
});
98104

105+
describe('roundFormatShortById', () => {
106+
it('returns short code for known format IDs', () => {
107+
expect(roundFormatShortById('a')).toBe('ao5');
108+
});
109+
110+
it('falls back to raw format ID for unknown formats', () => {
111+
expect(roundFormatShortById('5')).toBe('5');
112+
});
113+
114+
it('returns empty string for undefined format', () => {
115+
expect(roundFormatShortById(undefined)).toBe('');
116+
});
117+
});
118+
99119
describe('sortWcifEvents', () => {
100120
it('sorts events in canonical order', () => {
101121
const wcifEvents: Event[] = [

src/lib/domain/events.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ const roundFormats: RoundFormat[] = [
5959

6060
export const roundFormatById = (id: string | undefined): RoundFormat | undefined =>
6161
id ? roundFormats.find((roundFormat) => roundFormat.id === id) : undefined;
62+
63+
export const roundFormatShortById = (id: string | undefined): string => {
64+
const roundFormat = roundFormatById(id);
65+
return roundFormat ? roundFormat.short : id ?? '';
66+
};

src/pages/Competition/Export/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { findGroupActivitiesByRound, parseActivityCode } from '../../../lib/domain/activities';
2-
import { eventNameById, roundFormatById } from '../../../lib/domain/events';
2+
import { eventNameById, roundFormatShortById } from '../../../lib/domain/events';
33
import { acceptedRegistrations } from '../../../lib/domain/persons';
44
import { type ActivityWithParent } from '../../../lib/domain/types';
55
import {
@@ -255,7 +255,7 @@ const ExportPage = () => {
255255
cutoff_time: round.cutoff
256256
? `1 or 2 < ${formatCentiseconds(round.cutoff.attemptResult)}`
257257
: '',
258-
round_format: roundFormatById(round.format)?.short ?? '',
258+
round_format: roundFormatShortById(round.format),
259259
advancement_condition: round.advancementCondition
260260
? advancementConditionToText(round.advancementCondition)
261261
: '',

0 commit comments

Comments
 (0)