diff --git a/test/repositories/ApiBasedRepositoryTests.test.ts b/test/repositories/ApiBasedRepositoryTests.test.ts index 99d4be3..1e353ed 100644 --- a/test/repositories/ApiBasedRepositoryTests.test.ts +++ b/test/repositories/ApiBasedRepositoryTests.test.ts @@ -206,12 +206,6 @@ describe("getEtaForShuttleAndStopId", () => { const repository = new ApiBasedRepository(); const result = await repository.getEtaForShuttleAndStopId("5577", "177666"); - const expectedEta: IEta = { - secondsRemaining: 587, - shuttleId: "5577", - stopId: "177666", - }; - expect(result?.secondsRemaining).toEqual(587); expect(result?.millisecondsSinceEpoch).toBeDefined(); }); @@ -260,6 +254,8 @@ describe("getEtaForShuttleAndStopId", () => { describe("getEtasForShuttleId", () => { test("getEtasForShuttleId returns correct ETA data", async () => { + // Because I'm testing updateEtasForSystemIfTTL separately, force it to hit + // the cache for the stops }); @@ -268,7 +264,31 @@ describe("getEtasForShuttleId", () => { }); test("getEtasForShuttleId returns old data if not expired", async () => { + updateGlobalFetchMockJson(genericEtaDataByStopId); + const initialCache: ApiBasedRepositoryCache = { + etasForStopId: {}, + etasForShuttleId: { + "5577": [ + { + secondsRemaining: 587, + shuttleId: "5577", + stopId: "177666", + millisecondsSinceEpoch: Date.now(), + } + ] + }, + }; + + const ttls: ApiBasedRepositoryMillisecondTTLs = { + etasForShuttleId: 100000, + etasForStopId: 100000, + }; + + const repository = new ApiBasedRepository(initialCache, ttls); + const result = await repository.getEtasForShuttleId("5577"); + + expect(result).toEqual(initialCache.etasForShuttleId); }); });