Skip to content

Commit 9e0346c

Browse files
authored
fix: getAgencyList fallback (#1129)
1 parent a6732c6 commit 9e0346c

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/api/agencyList.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useState } from 'react'
22
import moment from 'moment'
33
import { BASE_PATH } from './apiConfig'
4+
45
export interface Agency {
56
date: string // example - "2019-07-01"
67
operator_ref: number // example - 25,
@@ -9,17 +10,32 @@ export interface Agency {
910

1011
let agencyList: Agency[]
1112

13+
const tryDates = [
14+
moment().subtract(1, 'day').format('YYYY-MM-DD'),
15+
moment().subtract(8, 'day').format('YYYY-MM-DD'),
16+
'2025-05-18',
17+
]
18+
1219
/**
1320
* Fetch agency data from MOT api
1421
* @returns Agency data array, might contain DUPLICATE agencies with different `date` values
1522
*/
1623
export default async function getAgencyList(): Promise<Agency[]> {
1724
if (!agencyList) {
18-
const yesterday = moment().subtract(1, 'day').format('YYYY-MM-DD')
19-
const response = await fetch(`${BASE_PATH}/gtfs_agencies/list?date_from=${yesterday}`)
20-
const data = (await response.json()) as Awaited<Agency[]>
21-
agencyList = data.filter(Boolean) // filter empty entries
25+
let data: Agency[] = []
26+
for (const date of tryDates) {
27+
try {
28+
const response = await fetch(`${BASE_PATH}/gtfs_agencies/list?date_from=${date}`)
29+
if (!response.ok) continue
30+
data = (await response.json()) as Agency[]
31+
if (data.length > 0) break
32+
} catch (err) {
33+
console.error(err)
34+
}
35+
}
36+
agencyList = data.filter(Boolean)
2237
}
38+
2339
return agencyList
2440
}
2541

tests/visual.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test.describe('Visual Tests', () => {
9696
test('operator page should look good', async ({ page }) => {
9797
await page.goto('/operator')
9898
await page.getByRole('combobox', { name: 'חברה מפעילה' }).click()
99-
await page.getByRole('option', { name: 'אגד' }).click()
99+
await page.getByRole('option', { name: 'אגד', exact: true }).click()
100100
await waitForSkeletonsToHide(page)
101101
await eyes.check('operator page', Target.window().layoutRegions('.chart', '.recharts-wrapper'))
102102
})

0 commit comments

Comments
 (0)