mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
update getEtaForShuttleAndStopId test to use method stubs
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
ApiBasedRepositoryCache,
|
||||
ApiBasedRepositoryMillisecondTTLs
|
||||
} from "../../src/repositories/ApiBasedRepository";
|
||||
import { IEta } from "../../src/entities/entities";
|
||||
import { IEta, IShuttle } from "../../src/entities/entities";
|
||||
|
||||
/**
|
||||
* Update the global fetch function to return a specific object.
|
||||
@@ -254,7 +254,38 @@ describe("getEtaForShuttleAndStopId", () => {
|
||||
test("getEtaForShuttleAndStopId returns correct ETA data", async () => {
|
||||
updateGlobalFetchMockJson(genericEtaDataByStopId);
|
||||
|
||||
const repository = new ApiBasedRepository();
|
||||
const initialCache: ApiBasedRepositoryCache = {
|
||||
etasForStopId: {
|
||||
"177666": [
|
||||
{
|
||||
secondsRemaining: 587,
|
||||
shuttleId: "5577",
|
||||
stopId: "177666",
|
||||
millisecondsSinceEpoch: Date.now(),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const repository = new ApiBasedRepository(initialCache);
|
||||
|
||||
repository.getShuttleById = jest.fn(async () => {
|
||||
const shuttle: IShuttle = {
|
||||
id: "5577",
|
||||
name: "08",
|
||||
coordinates: {
|
||||
latitude: 33.7933406,
|
||||
longitude: -117.8539321,
|
||||
},
|
||||
routeId: "53966",
|
||||
systemId: "1",
|
||||
};
|
||||
return shuttle;
|
||||
});
|
||||
|
||||
repository.updateEtasForSystemIfTTL = jest.fn(async () => {
|
||||
});
|
||||
|
||||
const result = await repository.getEtaForShuttleAndStopId("5577", "177666");
|
||||
|
||||
expect(result?.secondsRemaining).toEqual(587);
|
||||
|
||||
Reference in New Issue
Block a user