From 12ebd97068a235bb07e0c2b47dd78adc3c6e019f Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 7 Jan 2025 20:34:46 -0800 Subject: [PATCH] add test for old 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 01fa6da..1ae6272 100644 --- a/test/repositories/ApiBasedRepositoryTests.test.ts +++ b/test/repositories/ApiBasedRepositoryTests.test.ts @@ -448,7 +448,34 @@ describe("getShuttleById", () => { }); test("getShuttleById returns old data if not expired", async () => { + updateGlobalFetchMockJson(genericShuttleDataBySystemId); + const expectedShuttle = { + coordinates: { + latitude: 33.791781, + longitude: -117.8589646, + }, + name: "08", + routeId: "53966", + systemId: "1", + id: "5577", + millisecondsSinceEpoch: Date.now() - 1000, + } + + const initialCache: ApiBasedRepositoryCache = { + shuttleByShuttleId: { + "5577": expectedShuttle + } + }; + + const ttls: ApiBasedRepositoryMillisecondTTLs = { + shuttleByShuttleId: 100000, + }; + + const repository = new ApiBasedRepository(initialCache, ttls); + const shuttle = await repository.getShuttleById("5577"); + + expect(shuttle).toEqual(expectedShuttle); }); test("getShuttleById returns fresh data if expired", async () => {