From 4cfff7fcca8ed09600257b309c53d60519648f4f Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 7 Jan 2025 20:29:54 -0800 Subject: [PATCH] add mock api response and first test for getShuttleById --- .../ApiBasedRepositoryTests.test.ts | 113 +++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/test/repositories/ApiBasedRepositoryTests.test.ts b/test/repositories/ApiBasedRepositoryTests.test.ts index fb30cdc..01fa6da 100644 --- a/test/repositories/ApiBasedRepositoryTests.test.ts +++ b/test/repositories/ApiBasedRepositoryTests.test.ts @@ -31,7 +31,7 @@ beforeEach(() => { resetGlobalFetchMockJson(); }) -// Snapshot taken from the Passio GO! API +// Snapshots taken from the Passio GO! API const genericEtaDataByStopId = { "177666": [ { @@ -144,6 +144,111 @@ const genericEtaDataByStopId = { }, ] } +const genericShuttleDataBySystemId = { + "alertCRC": "23c1b91c", + "buses": { + "402840": [ + { + "deviceId": 402840, + "created": "08:24 PM", + "createdTime": "08:24 PM", + "paxLoad": 0, + "bus": "08", + "busId": 5577, + "userId": "263", + "routeBlockId": "142270", + "latitude": "33.791781800", + "longitude": "-117.858964600", + "calculatedCourse": "351.796001302109", + "outOfService": 0, + "more": "102", + "totalCap": 20, + "color": "#d62728", + "busName": "08", + "busType": "", + "routeId": "53966", + "route": "Red Route", + "outdated": 0 + } + ], + "404873": [ + { + "deviceId": 404873, + "created": "08:24 PM", + "createdTime": "08:24 PM", + "paxLoad": 0, + "bus": "10", + "busId": 7105, + "userId": "263", + "routeBlockId": "142270", + "latitude": "33.789331300", + "longitude": "-117.888790600", + "calculatedCourse": "76.005762226701", + "outOfService": 0, + "more": "101", + "totalCap": 20, + "color": "#d62728", + "busName": "10", + "busType": "", + "routeId": "53966", + "route": "Red Route", + "outdated": 0 + } + ], + "421421": [ + { + "deviceId": 421421, + "created": "08:24 PM", + "createdTime": "08:24 PM", + "paxLoad": 0, + "bus": "17", + "busId": 12502, + "userId": "263", + "routeBlockId": "142660", + "latitude": "33.790699500", + "longitude": "-117.890385500", + "calculatedCourse": "10.65684824528148", + "outOfService": 0, + "more": "101", + "totalCap": 32, + "color": "#bd9e39", + "busName": "17", + "busType": "Shuttle Bus", + "routeId": "54256", + "route": "Gold Route", + "outdated": 0 + } + ], + "441065": [ + { + "deviceId": 441065, + "created": "08:19 PM", + "createdTime": "08:19 PM", + "paxLoad": 0, + "bus": "07", + "busId": 5576, + "userId": "263", + "routeBlockId": "142270", + "latitude": "33.793278900", + "longitude": "-117.852629400", + "calculatedCourse": "299.74488110904485", + "outOfService": 0, + "more": "22", + "totalCap": 20, + "color": "#d62728", + "busName": "07", + "busType": "", + "routeId": "53966", + "route": "Red Route", + "outdated": 0 + } + ] + }, + "microtime": 0.023222923278808594, + "time": { + "263": "08:24 PM" + } +} describe("getEtaForShuttleAndStopId", () => { test("getEtaForShuttleAndStopId returns correct ETA data", async () => { @@ -333,7 +438,13 @@ describe("updateEtasForSystemIfTTL", () => { describe("getShuttleById", () => { test("getShuttleById returns null if unseeded cache", async () => { + updateGlobalFetchMockJson(genericShuttleDataBySystemId); + const initialCache: ApiBasedRepositoryCache = {}; + const repository = new ApiBasedRepository(initialCache); + + const shuttle = await repository.getShuttleById("5577"); + expect(shuttle).toBeNull(); }); test("getShuttleById returns old data if not expired", async () => {