Skip to content

Commit d62bb5a

Browse files
Football Data Pages: Add mappings for live match status (#13604)
* add mappings for live match status * refactor tests to not export parsing internals
1 parent 4ee3d1e commit d62bb5a

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

dotcom-rendering/fixtures/manual/footballMatches.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export const matchDayLive: FEMatchDay = {
7070
},
7171
};
7272

73+
export const matchDayLiveSecondHalf: FEMatchDay = {
74+
...matchDayLive,
75+
matchStatus: 'SHS',
76+
};
77+
7378
export const liveMatch: FELive = {
7479
...matchData,
7580
type: 'LiveMatch',

dotcom-rendering/src/footballMatches.test.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
emptyMatches,
44
liveMatch,
55
matchDayLive,
6+
matchDayLiveSecondHalf,
67
matchFixture,
78
matchResult,
89
} from '../fixtures/manual/footballMatches';
@@ -12,7 +13,7 @@ import type {
1213
FEMatchDay,
1314
FEResult,
1415
} from './feFootballDataPage';
15-
import { parse, parseMatchResult } from './footballMatches';
16+
import { parse } from './footballMatches';
1617
import { errorOrThrow, okOrThrow } from './lib/result';
1718

1819
const withMatches = (
@@ -190,11 +191,48 @@ describe('footballMatches', () => {
190191
for (const [uncleanName, cleanName] of Object.entries(
191192
uncleanToCleanNames,
192193
)) {
193-
const match = okOrThrow(
194-
parseMatchResult(matchesListWithTeamName(uncleanName)),
194+
const matchDay = okOrThrow(
195+
parse(withMatches([matchesListWithTeamName(uncleanName)])),
195196
'Expected football match parsing to succeed',
196197
);
198+
199+
const match = matchDay[0]!.competitions[0]!.matches[0];
200+
if (match?.kind !== 'Result') {
201+
throw new Error('Expected Result');
202+
}
203+
197204
expect(match.homeTeam.name).toBe(cleanName);
198205
}
199206
});
207+
it('should replace known live match status with our status', () => {
208+
const matchDay = okOrThrow(
209+
parse(withMatches([matchDayLiveSecondHalf])),
210+
'Expected football live match parsing to succeed',
211+
);
212+
213+
const match = matchDay[0]!.competitions[0]!.matches[0];
214+
if (match?.kind !== 'Live') {
215+
throw new Error('Expected live match');
216+
}
217+
218+
expect(match.status).toBe('2nd');
219+
});
220+
it('should replace unknown live match status with first two characters', () => {
221+
const matchDayLiveUnknownStatus = {
222+
...matchDayLiveSecondHalf,
223+
matchStatus: 'Something odd',
224+
};
225+
226+
const matchDay = okOrThrow(
227+
parse(withMatches([matchDayLiveUnknownStatus])),
228+
'Expected football live match parsing to succeed',
229+
);
230+
231+
const match = matchDay[0]!.competitions[0]!.matches[0];
232+
if (match?.kind !== 'Live') {
233+
throw new Error('Expected live match');
234+
}
235+
236+
expect(match.status).toBe('So');
237+
});
200238
});

dotcom-rendering/src/footballMatches.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ const parseFixture = (
229229
});
230230
};
231231

232-
export const parseMatchResult = (
232+
const parseMatchResult = (
233233
feResult: FEResult | FEMatchDay,
234234
): Result<ParserError, MatchResult> => {
235235
if (feResult.type === 'MatchDay' && !feResult.result) {
@@ -314,7 +314,7 @@ const parseLiveMatch = (
314314
dateTimeISOString: date.value,
315315
paId: feMatchDay.id,
316316
comment: feMatchDay.comments,
317-
status: feMatchDay.matchStatus,
317+
status: replaceLiveMatchStatus(feMatchDay.matchStatus),
318318
});
319319
};
320320

@@ -441,3 +441,35 @@ const cleanTeamName = (teamName: string): string => {
441441
.replace('Bialystock', 'Białystok')
442442
.replace('Union Saint Gilloise', 'Union Saint-Gilloise');
443443
};
444+
445+
// This comes from Frontend
446+
const paStatusToMatchStatus: Record<string, string> = {
447+
KO: '1st', // The Match has started Kicked Off.
448+
HT: 'HT', // The Referee has blown the whistle for Half Time.
449+
SHS: '2nd', // The Second Half of the Match has Started.
450+
FT: 'FT', // The Referee has blown the whistle for Full Time.
451+
PTFT: 'FT', // Penalty Shootout Full Time.
452+
Result: 'FT', // The Result is official.
453+
ETFT: 'FT', // Extra Time, Full Time has been blown.
454+
MC: 'FT', // Match has been Completed.
455+
FTET: 'ET', // Full Time, Extra Time it to be played.
456+
ETS: 'ET', // Extra Time has Started.
457+
ETHT: 'ET', // Extra Time Half Time has been called.
458+
ETSHS: 'ET', // Extra Time, Second Half has Started.
459+
FTPT: 'PT', // Full Time, Penalties are To be played.
460+
PT: 'PT', // Penalty Shootout has started.
461+
ETFTPT: 'PT', // Extra Time, Full Time, Penalties are To be played.
462+
Suspended: 'S', // Match has been Suspended.
463+
464+
// We don't really expect to see these the way we handle data in frontend
465+
Resumed: 'R', // Match has been Resumed.
466+
Abandoned: 'A', // Match has been Abandoned.
467+
Fixture: 'F', // Created Fixture is available and had been Created by us.
468+
'-': 'F', // this sneaky one is not in the docs
469+
New: 'N', // Match A New Match has been added to our data.
470+
Cancelled: 'C', // A Match has been Cancelled.
471+
};
472+
473+
const replaceLiveMatchStatus = (status: string): string => {
474+
return paStatusToMatchStatus[status] ?? status.slice(0, 2);
475+
};

0 commit comments

Comments
 (0)