mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Update ETA add test to use setReferenceTime
This commit is contained in:
@@ -91,6 +91,9 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
|||||||
test("adds an ETA entry based on historical data", async () => {
|
test("adds an ETA entry based on historical data", async () => {
|
||||||
const { route, systemId, stop1, stop2 } = await setupRouteAndOrderedStops();
|
const { route, systemId, stop1, stop2 } = await setupRouteAndOrderedStops();
|
||||||
|
|
||||||
|
const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 8, 12, 0, 0);
|
||||||
|
// "current time" is 7 minutes past arrival, expected eta = 8 minutes
|
||||||
|
repository.setReferenceTime(new Date(shuttleSecondArrivalTimeAtFirstStop.getTime() + 7 * 60 * 1000));
|
||||||
repository.startListeningForUpdates();
|
repository.startListeningForUpdates();
|
||||||
|
|
||||||
const shuttle = {
|
const shuttle = {
|
||||||
@@ -103,21 +106,21 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
|||||||
updatedTime: new Date(),
|
updatedTime: new Date(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const firstStopArrivalTime = new Date(2025, 0, 1, 12, 0, 0);
|
const firstStopLastWeekArrivalTime = new Date(2025, 0, 1, 12, 0, 0);
|
||||||
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopArrivalTime.getTime());
|
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopLastWeekArrivalTime.getTime());
|
||||||
|
|
||||||
shuttle.coordinates = stop2.coordinates;
|
shuttle.coordinates = stop2.coordinates;
|
||||||
const secondStopArrivalTime = new Date(2025, 0, 1, 12, 15, 0);
|
const secondStopLastWeekArrivalTime = new Date(2025, 0, 1, 12, 15, 0);
|
||||||
await shuttleRepository.addOrUpdateShuttle(shuttle, secondStopArrivalTime.getTime());
|
await shuttleRepository.addOrUpdateShuttle(shuttle, secondStopLastWeekArrivalTime.getTime());
|
||||||
|
|
||||||
shuttle.coordinates = stop1.coordinates;
|
shuttle.coordinates = stop1.coordinates;
|
||||||
await shuttleRepository.addOrUpdateShuttle(
|
await shuttleRepository.addOrUpdateShuttle(
|
||||||
shuttle,
|
shuttle,
|
||||||
new Date(2025, 0, 8, 12, 0, 0).getTime(),
|
shuttleSecondArrivalTimeAtFirstStop.getTime(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const eta = await repository.getEtaForShuttleAndStopId(shuttle.id, stop2.id);
|
const eta = await repository.getEtaForShuttleAndStopId(shuttle.id, stop2.id);
|
||||||
expect(eta?.secondsRemaining).toEqual(7 * 60 + 30);
|
expect(eta?.secondsRemaining).toEqual(8 * 60);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user