Add a test for emitting the event

This commit is contained in:
2025-11-18 19:57:15 -08:00
parent 47708d050e
commit 8d9ff3ac62

View File

@@ -767,4 +767,30 @@ describe.each(repositoryImplementations)('$name', (holder) => {
});
});
});
describe("SHUTTLE_WILL_LEAVE_STOP event", () => {
test("emits SHUTTLE_WILL_LEAVE_EVENT as a shuttle is leaving a stop", async () => {
const { stop1, sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
shuttle.coordinates = stop1.coordinates;
const listener = jest.fn();
repository.addListener(ShuttleRepositoryEvent.SHUTTLE_WILL_LEAVE_STOP, listener);
// Simulate arrival at stop 1
await repository.addOrUpdateShuttle(shuttle);
shuttle.coordinates = { latitude: 12.5, longitude: 22.5 };
// Simulate leaving stop 1
await repository.addOrUpdateShuttle(shuttle);
expect(listener).toHaveBeenCalledWith({
stopArrivalThatShuttleIsLeaving: {
shuttleId: shuttle.id,
stopId: stop1.id,
timestamp: expect.any(Date),
},
});
});
});
});