Update ETA add test to use setReferenceTime

This commit is contained in:
2025-11-11 19:41:42 -08:00
parent 5e8a3c84a6
commit 88a393c1ad

View File

@@ -91,6 +91,9 @@ describe.each(repositoryImplementations)('$name', (holder) => {
test("adds an ETA entry based on historical data", async () => {
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();
const shuttle = {
@@ -103,21 +106,21 @@ describe.each(repositoryImplementations)('$name', (holder) => {
updatedTime: new Date(),
};
const firstStopArrivalTime = new Date(2025, 0, 1, 12, 0, 0);
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopArrivalTime.getTime());
const firstStopLastWeekArrivalTime = new Date(2025, 0, 1, 12, 0, 0);
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopLastWeekArrivalTime.getTime());
shuttle.coordinates = stop2.coordinates;
const secondStopArrivalTime = new Date(2025, 0, 1, 12, 15, 0);
await shuttleRepository.addOrUpdateShuttle(shuttle, secondStopArrivalTime.getTime());
const secondStopLastWeekArrivalTime = new Date(2025, 0, 1, 12, 15, 0);
await shuttleRepository.addOrUpdateShuttle(shuttle, secondStopLastWeekArrivalTime.getTime());
shuttle.coordinates = stop1.coordinates;
await shuttleRepository.addOrUpdateShuttle(
shuttle,
new Date(2025, 0, 8, 12, 0, 0).getTime(),
shuttleSecondArrivalTimeAtFirstStop.getTime(),
);
const eta = await repository.getEtaForShuttleAndStopId(shuttle.id, stop2.id);
expect(eta?.secondsRemaining).toEqual(7 * 60 + 30);
expect(eta?.secondsRemaining).toEqual(8 * 60);
});
});