add test for getEtasForShuttleId cache

This commit is contained in:
2025-01-07 15:53:07 -08:00
parent d7d54ec5e6
commit 37909c8dbb

View File

@@ -206,12 +206,6 @@ describe("getEtaForShuttleAndStopId", () => {
const repository = new ApiBasedRepository(); const repository = new ApiBasedRepository();
const result = await repository.getEtaForShuttleAndStopId("5577", "177666"); const result = await repository.getEtaForShuttleAndStopId("5577", "177666");
const expectedEta: IEta = {
secondsRemaining: 587,
shuttleId: "5577",
stopId: "177666",
};
expect(result?.secondsRemaining).toEqual(587); expect(result?.secondsRemaining).toEqual(587);
expect(result?.millisecondsSinceEpoch).toBeDefined(); expect(result?.millisecondsSinceEpoch).toBeDefined();
}); });
@@ -260,6 +254,8 @@ describe("getEtaForShuttleAndStopId", () => {
describe("getEtasForShuttleId", () => { describe("getEtasForShuttleId", () => {
test("getEtasForShuttleId returns correct ETA data", async () => { 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 () => { 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);
}); });
}); });