mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add test for getEtasForShuttleId cache
This commit is contained in:
@@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user