From 2e37249bd1310747b34d1ff60b0164877c7f6228 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 7 Jan 2025 16:12:52 -0800 Subject: [PATCH] add tests for getEtasForStopId --- .../ApiBasedRepositoryTests.test.ts | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/test/repositories/ApiBasedRepositoryTests.test.ts b/test/repositories/ApiBasedRepositoryTests.test.ts index 7eba7bb..180576f 100644 --- a/test/repositories/ApiBasedRepositoryTests.test.ts +++ b/test/repositories/ApiBasedRepositoryTests.test.ts @@ -298,15 +298,45 @@ describe("getEtasForShuttleId", () => { describe("getEtasForStopId", () => { test("getEtasForStopId returns correct ETA data", async () => { + // Because I'm testing updateEtasForSystemIfTTL separately, + // stub it out here + updateGlobalFetchMockJson(genericEtaDataByStopId); + + const initialCache: ApiBasedRepositoryCache = { + etasForStopId: { + "177666": [ + { + secondsRemaining: 587, + shuttleId: "5577", + stopId: "177666", + millisecondsSinceEpoch: Date.now(), + } + ] + }, + etasForShuttleId: {} + }; + + const ttls: ApiBasedRepositoryMillisecondTTLs = { + etasForShuttleId: 100000, + etasForStopId: 100000, + }; + + const repository = new ApiBasedRepository(initialCache, ttls); + repository.updateEtasForSystemIfTTL = jest.fn(async () => { + }); + const result = await repository.getEtasForStopId("177666"); + + expect(result).toEqual(initialCache.etasForShuttleId); }); test("getEtasForStopId returns empty array if no data available", async () => { + const repository = new ApiBasedRepository(); + repository.updateEtasForSystemIfTTL = jest.fn(async () => { + }); + const result = await repository.getEtasForShuttleId("5577"); - }); - - test("getEtasForStopId returns old data if not expired", async () => { - + expect(result).toEqual([]); }); });