mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Change the event name to SHUTTLE_WILL_ARRIVE_AT_STOP, and emit it before the stop is updated
This commit is contained in:
@@ -401,8 +401,8 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
|
||||
timestamp: new Date(travelTimeTimestamp),
|
||||
shuttleId: shuttle.id,
|
||||
};
|
||||
this.emit(ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP, shuttleArrival);
|
||||
await this.updateShuttleLastStopArrival(shuttleArrival);
|
||||
this.emit(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, shuttleArrival);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import type EventEmitter from "node:events";
|
||||
export const ShuttleRepositoryEvent = {
|
||||
SHUTTLE_UPDATED: "shuttleUpdated",
|
||||
SHUTTLE_REMOVED: "shuttleRemoved",
|
||||
SHUTTLE_ARRIVED_AT_STOP: "shuttleArrivedAtStop",
|
||||
SHUTTLE_WILL_ARRIVE_AT_STOP: "shuttleArrivedAtStop",
|
||||
} as const;
|
||||
|
||||
export type ShuttleRepositoryEventName = typeof ShuttleRepositoryEvent[keyof typeof ShuttleRepositoryEvent];
|
||||
@@ -15,7 +15,7 @@ export type EtaDataClearedEventPayload = IEta[];
|
||||
export interface ShuttleRepositoryEventPayloads {
|
||||
[ShuttleRepositoryEvent.SHUTTLE_UPDATED]: IShuttle,
|
||||
[ShuttleRepositoryEvent.SHUTTLE_REMOVED]: IShuttle,
|
||||
[ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP]: ShuttleStopArrival,
|
||||
[ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP]: ShuttleStopArrival,
|
||||
}
|
||||
|
||||
export type ShuttleRepositoryEventListener<T extends ShuttleRepositoryEventName> = (
|
||||
|
||||
@@ -182,8 +182,8 @@ export class UnoptimizedInMemoryShuttleRepository
|
||||
timestamp: new Date(travelTimeTimestamp),
|
||||
shuttleId: shuttle.id,
|
||||
};
|
||||
this.emit(ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP, shuttleArrival);
|
||||
await this.updateShuttleLastStopArrival(shuttleArrival);
|
||||
this.emit(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, shuttleArrival);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -712,12 +712,12 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("SHUTTLE_ARRIVED_AT_STOP event", () => {
|
||||
test("emits SHUTTLE_ARRIVED_AT_STOP event when shuttle arrives at a stop", async () => {
|
||||
describe("SHUTTLE_WILL_ARRIVE_AT_STOP event", () => {
|
||||
test("emits SHUTTLE_WILL_ARRIVE_AT_STOP event before shuttle arrives at a stop", async () => {
|
||||
const { route, systemId, stop1 } = await setupRouteAndOrderedStops();
|
||||
|
||||
const listener = jest.fn();
|
||||
repository.on(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, listener);
|
||||
repository.on(ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP, listener);
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
@@ -743,7 +743,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
const { route, systemId } = await setupRouteAndOrderedStops();
|
||||
|
||||
const listener = jest.fn();
|
||||
repository.on(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, listener);
|
||||
repository.on(ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP, listener);
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
@@ -764,7 +764,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
const { route, systemId, stop1, stop2 } = await setupRouteAndOrderedStops();
|
||||
|
||||
const listener = jest.fn();
|
||||
repository.on(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, listener);
|
||||
repository.on(ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP, listener);
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
|
||||
@@ -26,12 +26,12 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
|
||||
|
||||
startListeningForUpdates() {
|
||||
this.shuttleRepository.addListener(ShuttleRepositoryEvent.SHUTTLE_UPDATED, this.handleShuttleUpdate);
|
||||
this.shuttleRepository.addListener(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, this.handleShuttleArriveAtStop)
|
||||
this.shuttleRepository.addListener(ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP, this.handleShuttleArriveAtStop)
|
||||
}
|
||||
|
||||
stopListeningForUpdates() {
|
||||
this.shuttleRepository.removeListener(ShuttleRepositoryEvent.SHUTTLE_UPDATED, this.handleShuttleUpdate);
|
||||
this.shuttleRepository.removeListener(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, this.handleShuttleArriveAtStop);
|
||||
this.shuttleRepository.removeListener(ShuttleRepositoryEvent.SHUTTLE_WILL_ARRIVE_AT_STOP, this.handleShuttleArriveAtStop);
|
||||
}
|
||||
|
||||
private handleShuttleUpdate(shuttle: IShuttle) {
|
||||
@@ -40,5 +40,6 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple
|
||||
|
||||
private handleShuttleArriveAtStop(shuttleArrival: ShuttleStopArrival) {
|
||||
// TODO: handle shuttle arrive at stop
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user