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([]); }); });