Skip to content

Commit c7e2977

Browse files
make score optional in football matches (#13629)
Co-authored-by: Oliver Abrahams <[email protected]>
1 parent c43b986 commit c7e2977

File tree

4 files changed

+22
-110
lines changed

4 files changed

+22
-110
lines changed

dotcom-rendering/fixtures/manual/footballData.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ export const initialDays: FootballMatches = [
4545
},
4646
status: '1st',
4747
},
48+
{
49+
kind: 'Live',
50+
dateTimeISOString: new Date(
51+
'2022-01-01T11:11:00Z',
52+
).toISOString(),
53+
paId: '12345',
54+
homeTeam: {
55+
name: 'Fiorentina',
56+
},
57+
awayTeam: {
58+
name: 'Bologna',
59+
},
60+
status: 'S',
61+
comment: 'Awaiting officials decision',
62+
},
4863
{
4964
kind: 'Fixture',
5065
dateTimeISOString: new Date(

dotcom-rendering/src/components/FootballMatchList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ const Scores = ({
352352
homeScore,
353353
awayScore,
354354
}: {
355-
homeScore: number;
356-
awayScore: number;
355+
homeScore?: number;
356+
awayScore?: number;
357357
}) => (
358358
<span
359359
css={css`

dotcom-rendering/src/footballMatches.test.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import type {
1111
FEFootballMatch,
1212
FEMatchByDateAndCompetition,
13-
FEMatchDay,
1413
FEResult,
1514
} from './feFootballDataPage';
1615
import { parse } from './footballMatches';
@@ -102,67 +101,6 @@ describe('footballMatches', () => {
102101
expect(resultThree.errors[0]!.kind).toBe('FootballMatchInvalidDate');
103102
});
104103

105-
it('should return an error when football matches are missing a score', () => {
106-
const matchResultMissingHomeScore: FEResult = {
107-
...matchResult,
108-
homeTeam: {
109-
...matchResult.homeTeam,
110-
score: undefined,
111-
},
112-
};
113-
const matchResultMissingAwayScore: FEResult = {
114-
...matchResult,
115-
homeTeam: {
116-
...matchResult.awayTeam,
117-
score: undefined,
118-
},
119-
};
120-
const liveMatchMissingHomeScore: FEMatchDay = {
121-
...matchDayLive,
122-
homeTeam: {
123-
...matchDayLive.homeTeam,
124-
score: undefined,
125-
},
126-
};
127-
const liveMatchMissingAwayScore: FEMatchDay = {
128-
...matchDayLive,
129-
homeTeam: {
130-
...matchDayLive.awayTeam,
131-
score: undefined,
132-
},
133-
};
134-
135-
const resultHome = errorOrThrow(
136-
parse(withMatches([matchResultMissingHomeScore])),
137-
'Expected football match parsing to fail',
138-
);
139-
const resultAway = errorOrThrow(
140-
parse(withMatches([matchResultMissingAwayScore])),
141-
'Expected football match parsing to fail',
142-
);
143-
const liveHome = errorOrThrow(
144-
parse(withMatches([liveMatchMissingHomeScore])),
145-
'Expected football match parsing to fail',
146-
);
147-
const liveAway = errorOrThrow(
148-
parse(withMatches([liveMatchMissingAwayScore])),
149-
'Expected football match parsing to fail',
150-
);
151-
152-
expect(resultHome.kind).toBe('FootballMatchMissingScore');
153-
expect(resultAway.kind).toBe('FootballMatchMissingScore');
154-
155-
if (
156-
liveHome.kind !== 'InvalidMatchDay' ||
157-
liveAway.kind !== 'InvalidMatchDay'
158-
) {
159-
throw new Error('Expected an invalid match day error');
160-
}
161-
162-
expect(liveHome.errors[0]?.kind).toBe('FootballMatchMissingScore');
163-
expect(liveAway.errors[0]?.kind).toBe('FootballMatchMissingScore');
164-
});
165-
166104
it('should return an error when it receives a live match', () => {
167105
const result = errorOrThrow(
168106
parse(withMatches([liveMatch])),

dotcom-rendering/src/footballMatches.ts

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
FEFootballPageConfig,
77
FEMatchByDateAndCompetition,
88
FEMatchDay,
9-
FEMatchDayTeam,
109
FEResult,
1110
} from './feFootballDataPage';
1211
import type { EditionId } from './lib/edition';
@@ -16,7 +15,7 @@ import type { FooterType } from './types/footer';
1615

1716
type TeamScore = {
1817
name: string;
19-
score: number;
18+
score?: number;
2019
};
2120

2221
type MatchData = {
@@ -172,22 +171,6 @@ const parseDate = (a: string): Result<string, string> => {
172171
return ok(d.toISOString());
173172
};
174173

175-
const parseScore = (
176-
team: FEMatchDayTeam,
177-
matchKind: 'Result' | 'Live',
178-
): Result<ParserError, number> => {
179-
if (team.score === undefined) {
180-
const prefix = matchKind === 'Result' ? 'Results' : 'Live matches';
181-
182-
return error({
183-
kind: 'FootballMatchMissingScore',
184-
message: `${prefix} must have scores, but the score for ${team.name} is missing`,
185-
});
186-
}
187-
188-
return ok(team.score);
189-
};
190-
191174
const parseMatchDate = (date: string): Result<string, string> => {
192175
// Frontend appends a timezone in square brackets
193176
const isoDate = date.split('[')[0];
@@ -245,27 +228,15 @@ const parseMatchResult = (
245228
return error({ kind: 'FootballMatchInvalidDate', message: date.error });
246229
}
247230

248-
const homeScore = parseScore(feResult.homeTeam, 'Result');
249-
250-
if (homeScore.kind === 'error') {
251-
return homeScore;
252-
}
253-
254-
const awayScore = parseScore(feResult.awayTeam, 'Result');
255-
256-
if (awayScore.kind === 'error') {
257-
return awayScore;
258-
}
259-
260231
return ok({
261232
kind: 'Result',
262233
homeTeam: {
263234
name: cleanTeamName(feResult.homeTeam.name),
264-
score: homeScore.value,
235+
score: feResult.homeTeam.score,
265236
},
266237
awayTeam: {
267238
name: cleanTeamName(feResult.awayTeam.name),
268-
score: awayScore.value,
239+
score: feResult.awayTeam.score,
269240
},
270241
dateTimeISOString: date.value,
271242
paId: feResult.id,
@@ -289,27 +260,15 @@ const parseLiveMatch = (
289260
return error({ kind: 'FootballMatchInvalidDate', message: date.error });
290261
}
291262

292-
const homeScore = parseScore(feMatchDay.homeTeam, 'Live');
293-
294-
if (homeScore.kind === 'error') {
295-
return homeScore;
296-
}
297-
298-
const awayScore = parseScore(feMatchDay.awayTeam, 'Live');
299-
300-
if (awayScore.kind === 'error') {
301-
return awayScore;
302-
}
303-
304263
return ok({
305264
kind: 'Live',
306265
homeTeam: {
307266
name: cleanTeamName(feMatchDay.homeTeam.name),
308-
score: homeScore.value,
267+
score: feMatchDay.homeTeam.score,
309268
},
310269
awayTeam: {
311270
name: cleanTeamName(feMatchDay.awayTeam.name),
312-
score: awayScore.value,
271+
score: feMatchDay.awayTeam.score,
313272
},
314273
dateTimeISOString: date.value,
315274
paId: feMatchDay.id,

0 commit comments

Comments
 (0)