From 8d9ff3ac6219b6ec1da35dda922f23ebae0204f7 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 18 Nov 2025 19:57:15 -0800 Subject: [PATCH] Add a test for emitting the event --- .../ShuttleRepositorySharedTests.test.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts b/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts index 94dd9e8..f12f4d9 100644 --- a/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts +++ b/src/repositories/shuttle/__tests__/ShuttleRepositorySharedTests.test.ts @@ -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), + }, + }); + }); + }); });