mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Add a test for emitting the event
This commit is contained in:
@@ -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),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user