mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add tests for getEtasForStopId
This commit is contained in:
@@ -298,15 +298,45 @@ describe("getEtasForShuttleId", () => {
|
|||||||
|
|
||||||
describe("getEtasForStopId", () => {
|
describe("getEtasForStopId", () => {
|
||||||
test("getEtasForStopId returns correct ETA data", async () => {
|
test("getEtasForStopId returns correct ETA data", async () => {
|
||||||
|
// Because I'm testing updateEtasForSystemIfTTL separately,
|
||||||
|
// stub it out here
|
||||||
|
|
||||||
|
updateGlobalFetchMockJson(genericEtaDataByStopId);
|
||||||
|
|
||||||
|
const initialCache: ApiBasedRepositoryCache = {
|
||||||
|
etasForStopId: {
|
||||||
|
"177666": [
|
||||||
|
{
|
||||||
|
secondsRemaining: 587,
|
||||||
|
shuttleId: "5577",
|
||||||
|
stopId: "177666",
|
||||||
|
millisecondsSinceEpoch: Date.now(),
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
etasForShuttleId: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
const ttls: ApiBasedRepositoryMillisecondTTLs = {
|
||||||
|
etasForShuttleId: 100000,
|
||||||
|
etasForStopId: 100000,
|
||||||
|
};
|
||||||
|
|
||||||
|
const repository = new ApiBasedRepository(initialCache, ttls);
|
||||||
|
repository.updateEtasForSystemIfTTL = jest.fn(async () => {
|
||||||
|
});
|
||||||
|
const result = await repository.getEtasForStopId("177666");
|
||||||
|
|
||||||
|
expect(result).toEqual(initialCache.etasForShuttleId);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getEtasForStopId returns empty array if no data available", async () => {
|
test("getEtasForStopId returns empty array if no data available", async () => {
|
||||||
|
const repository = new ApiBasedRepository();
|
||||||
|
repository.updateEtasForSystemIfTTL = jest.fn(async () => {
|
||||||
|
});
|
||||||
|
const result = await repository.getEtasForShuttleId("5577");
|
||||||
|
|
||||||
});
|
expect(result).toEqual([]);
|
||||||
|
|
||||||
test("getEtasForStopId returns old data if not expired", async () => {
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user