Make the ETA assertion check for multiple ETA insertions

This commit is contained in:
2025-11-13 17:13:43 -08:00
parent e4151ed914
commit 42c71815e6

View File

@@ -118,10 +118,12 @@ describe.each(repositoryImplementations)('$name', (holder) => {
currentTime: Date, currentTime: Date,
shuttleSecondArrivalTimeAtFirstStop: Date shuttleSecondArrivalTimeAtFirstStop: Date
) { ) {
const { route, systemId, stop1, stop2 } = await setupRouteAndOrderedStops(); const { route, systemId, stop1, stop2, stop3 } = await setupRouteAndOrderedStops();
const firstStopLastWeekArrivalTime = new Date(2025, 0, 1, 12, 0, 0); // Populating travel time data
const secondStopLastWeekArrivalTime = new Date(2025, 0, 1, 12, 15, 0); const firstStopArrivalTime = new Date(2025, 0, 1, 12, 0, 0);
const secondStopArrivalTime = new Date(2025, 0, 1, 12, 15, 0);
const thirdStopArrivalTime = new Date(2025, 0, 1, 12, 20, 0);
repository.setReferenceTime(currentTime); repository.setReferenceTime(currentTime);
repository.startListeningForUpdates(); repository.startListeningForUpdates();
@@ -136,11 +138,15 @@ describe.each(repositoryImplementations)('$name', (holder) => {
updatedTime: new Date(), updatedTime: new Date(),
}; };
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopLastWeekArrivalTime.getTime()); await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopArrivalTime.getTime());
shuttle.coordinates = stop2.coordinates; shuttle.coordinates = stop2.coordinates;
await shuttleRepository.addOrUpdateShuttle(shuttle, secondStopLastWeekArrivalTime.getTime()); await shuttleRepository.addOrUpdateShuttle(shuttle, secondStopArrivalTime.getTime());
shuttle.coordinates = stop3.coordinates;
await shuttleRepository.addOrUpdateShuttle(shuttle, thirdStopArrivalTime.getTime());
// Populating ETA data
shuttle.coordinates = stop1.coordinates; shuttle.coordinates = stop1.coordinates;
await shuttleRepository.addOrUpdateShuttle( await shuttleRepository.addOrUpdateShuttle(
shuttle, shuttle,
@@ -155,11 +161,14 @@ describe.each(repositoryImplementations)('$name', (holder) => {
await new Promise((resolve) => setTimeout(resolve, 1000)); await new Promise((resolve) => setTimeout(resolve, 1000));
const eta = await repository.getEtaForShuttleAndStopId(shuttle.id, stop2.id); const secondStopEta = await repository.getEtaForShuttleAndStopId(shuttle.id, stop2.id);
expect(eta?.secondsRemaining).toEqual(8 * 60); expect(secondStopEta?.secondsRemaining).toEqual(8 * 60);
const thirdStopEta = await repository.getEtaForShuttleAndStopId(shuttle.id, stop3.id);
expect(thirdStopEta?.secondsRemaining).toEqual(13 * 60);
} }
test("adds an ETA entry based on historical data", async () => { test("adds ETA entries for stops based on historical data", async () => {
const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 8, 12, 0, 0); const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 8, 12, 0, 0);
const currentTime = new Date(shuttleSecondArrivalTimeAtFirstStop.getTime() + 7 * 60 * 1000); const currentTime = new Date(shuttleSecondArrivalTimeAtFirstStop.getTime() + 7 * 60 * 1000);