From 55501a0d92d8720b250fcaba3bfbdae7ab2c7367 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 8 Jan 2025 16:30:23 -0800 Subject: [PATCH] update getEtaForShuttleAndStopId test to use method stubs --- .../ApiBasedRepositoryTests.test.ts | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/test/repositories/ApiBasedRepositoryTests.test.ts b/test/repositories/ApiBasedRepositoryTests.test.ts index f23409f..9d5704b 100644 --- a/test/repositories/ApiBasedRepositoryTests.test.ts +++ b/test/repositories/ApiBasedRepositoryTests.test.ts @@ -4,7 +4,7 @@ import { ApiBasedRepositoryCache, ApiBasedRepositoryMillisecondTTLs } from "../../src/repositories/ApiBasedRepository"; -import { IEta } from "../../src/entities/entities"; +import { IEta, IShuttle } from "../../src/entities/entities"; /** * Update the global fetch function to return a specific object. @@ -254,7 +254,38 @@ describe("getEtaForShuttleAndStopId", () => { test("getEtaForShuttleAndStopId returns correct ETA data", async () => { updateGlobalFetchMockJson(genericEtaDataByStopId); - const repository = new ApiBasedRepository(); + const initialCache: ApiBasedRepositoryCache = { + etasForStopId: { + "177666": [ + { + secondsRemaining: 587, + shuttleId: "5577", + stopId: "177666", + millisecondsSinceEpoch: Date.now(), + } + ], + }, + } + + const repository = new ApiBasedRepository(initialCache); + + repository.getShuttleById = jest.fn(async () => { + const shuttle: IShuttle = { + id: "5577", + name: "08", + coordinates: { + latitude: 33.7933406, + longitude: -117.8539321, + }, + routeId: "53966", + systemId: "1", + }; + return shuttle; + }); + + repository.updateEtasForSystemIfTTL = jest.fn(async () => { + }); + const result = await repository.getEtaForShuttleAndStopId("5577", "177666"); expect(result?.secondsRemaining).toEqual(587);