From 0a7b6ab5107f4e935e62047219f26f949d19f2ac Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 7 Jan 2025 20:37:42 -0800 Subject: [PATCH] add test for getting new data --- .../ApiBasedRepositoryTests.test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/repositories/ApiBasedRepositoryTests.test.ts b/test/repositories/ApiBasedRepositoryTests.test.ts index 1ae6272..8511959 100644 --- a/test/repositories/ApiBasedRepositoryTests.test.ts +++ b/test/repositories/ApiBasedRepositoryTests.test.ts @@ -479,7 +479,34 @@ describe("getShuttleById", () => { }); test("getShuttleById returns fresh data if expired", async () => { + updateGlobalFetchMockJson(genericShuttleDataBySystemId); + const initialCacheShuttle = { + coordinates: { + latitude: 33.791781, + longitude: -117.8589646, + }, + name: "08", + routeId: "53966", + systemId: "1", + id: "5577", + millisecondsSinceEpoch: Date.now() - 100000, + } + + const initialCache: ApiBasedRepositoryCache = { + shuttleByShuttleId: { + "5577": initialCacheShuttle + } + }; + + const ttls: ApiBasedRepositoryMillisecondTTLs = { + shuttleByShuttleId: 1000, + }; + + const repository = new ApiBasedRepository(initialCache, ttls); + const shuttle = await repository.getShuttleById("5577"); + expect(shuttle?.id).toEqual(initialCacheShuttle.id); + expect(initialCacheShuttle.millisecondsSinceEpoch).not.toEqual(shuttle?.millisecondsSinceEpoch); }); });