From 9db745bd12fcc2ef3e795000e670d638d32cc891 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 7 Jan 2025 19:41:01 -0800 Subject: [PATCH] add test for updateEtasForSystemIfTTL for updating data --- .../ApiBasedRepositoryTests.test.ts | 76 +++++-------------- 1 file changed, 20 insertions(+), 56 deletions(-) diff --git a/test/repositories/ApiBasedRepositoryTests.test.ts b/test/repositories/ApiBasedRepositoryTests.test.ts index 4883925..26e749e 100644 --- a/test/repositories/ApiBasedRepositoryTests.test.ts +++ b/test/repositories/ApiBasedRepositoryTests.test.ts @@ -142,60 +142,6 @@ const genericEtaDataByStopId = { "stopId": "177666" } }, - { - "OOS": 0, - "busName": "10", - "distance": 1, - "speed": 11.085164763991688, - "routeBlockId": "142270", - "actualRouteBlockId": "142270", - "arrived": null, - "eta": "19 min ", - "color": "#000000", - "bg": "#ffea3f", - "order": 0, - "dwell": null, - "stopsAmount": 2, - "secondsSpent": 1150, - "etaR": "19", - "error": null, - "outdated": 0, - "routeId": "53966", - "serviceTime": "", - "scheduleTimes": [], - "goShowSchedule": 0, - "looping": "1", - "routeGroupId": "6703", - "busId": 7105, - "tripId": 751430, - "deviceId": 404873, - "created": "2025-01-07 15:00:08", - "routePointPosition": 254, - "routeStopPosition": 3, - "stopRoutePointPosition": 217, - "timezoneOffset": -10800, - "busLatLng": [ - 33.7917895, - -117.8901868 - ], - "busProjectionLatlng": { - "lat": 33.79179583075815, - "lng": -117.8902164019431 - }, - "busProjectionError": 3, - "stopId": "177666", - "theStop": { - "name": "Chapman Court", - "position": 3, - "userId": "263", - "routeStopId": "1348785", - "busId": 7105, - "routeName": "Red Route", - "shortName": null, - "routeId": "53966", - "stopId": "177666" - } - } ] } @@ -361,9 +307,27 @@ describe("updateEtasForSystemIfTTL", () => { }); test("updateEtasForSystemIfTTL updates all ETA data if data is TTL", async () => { - // For this one, stub out getStopsBySystemId to return mock data + updateGlobalFetchMockJson(genericEtaDataByStopId); + const repository = new ApiBasedRepository(); + repository.getStopsBySystemId = jest.fn(async () => { + return [ + { + name: "Chapman Court", + systemId: "1", + id: "177666", + coordinates: { + latitude: 33.796796, + longitude: -117.889293 + }, + } + ]; + }); - }) + await repository.updateEtasForSystemIfTTL("1"); + + const updatedResult = await repository.getEtasForStopId("177666"); + expect(updatedResult.length).toEqual(2); + }); });