From 75537a9c3a9a9eca2b9521b9985ea52b8ff1c4e4 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 11 Nov 2025 14:59:36 -0800 Subject: [PATCH] Update interface and implementation of ETANotificationScheduler Rely on both the ETA repository and the shuttle repository --- .../schedulers/ETANotificationScheduler.ts | 10 ++++++---- .../__tests__/ETANotificationSchedulerTests.test.ts | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/notifications/schedulers/ETANotificationScheduler.ts b/src/notifications/schedulers/ETANotificationScheduler.ts index 62a22c9..c18f280 100644 --- a/src/notifications/schedulers/ETANotificationScheduler.ts +++ b/src/notifications/schedulers/ETANotificationScheduler.ts @@ -1,4 +1,3 @@ -import { ShuttleGetterRepository, ShuttleRepositoryEvent } from "../../repositories/shuttle/ShuttleGetterRepository"; import { IEta } from "../../entities/ShuttleRepositoryEntities"; import { AppleNotificationSender, NotificationAlertArguments } from "../senders/AppleNotificationSender"; import { @@ -6,11 +5,14 @@ import { ScheduledNotification } from "../../repositories/notifications/NotificationRepository"; import { InMemoryNotificationRepository } from "../../repositories/notifications/InMemoryNotificationRepository"; +import { ETAGetterRepository, ETARepositoryEvent } from "../../repositories/shuttle/eta/ETAGetterRepository"; +import { ShuttleGetterRepository } from "../../repositories/shuttle/ShuttleGetterRepository"; export class ETANotificationScheduler { public static readonly defaultSecondsThresholdForNotificationToFire = 180; constructor( + private etaRepository: ETAGetterRepository, private shuttleRepository: ShuttleGetterRepository, private notificationRepository: NotificationRepository = new InMemoryNotificationRepository(), private appleNotificationSender = new AppleNotificationSender(), @@ -26,7 +28,7 @@ export class ETANotificationScheduler { const shuttle = await this.shuttleRepository.getShuttleById(shuttleId); const stop = await this.shuttleRepository.getStopById(stopId); - const eta = await this.shuttleRepository.getEtaForShuttleAndStopId(shuttleId, stopId); + const eta = await this.etaRepository.getEtaForShuttleAndStopId(shuttleId, stopId); if (!shuttle) { console.warn(`Notification ${notificationData} fell through; no associated shuttle`); return false; @@ -90,10 +92,10 @@ export class ETANotificationScheduler { // The following is a workaround for the constructor being called twice public startListeningForUpdates() { - this.shuttleRepository.on(ShuttleRepositoryEvent.ETA_UPDATED, this.etaSubscriberCallback); + this.etaRepository.on(ETARepositoryEvent.ETA_UPDATED, this.etaSubscriberCallback); } public stopListeningForUpdates() { - this.shuttleRepository.off(ShuttleRepositoryEvent.ETA_UPDATED, this.etaSubscriberCallback); + this.etaRepository.off(ETARepositoryEvent.ETA_UPDATED, this.etaSubscriberCallback); } } diff --git a/src/notifications/schedulers/__tests__/ETANotificationSchedulerTests.test.ts b/src/notifications/schedulers/__tests__/ETANotificationSchedulerTests.test.ts index 17cfeef..e79f4a0 100644 --- a/src/notifications/schedulers/__tests__/ETANotificationSchedulerTests.test.ts +++ b/src/notifications/schedulers/__tests__/ETANotificationSchedulerTests.test.ts @@ -1,6 +1,7 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { ETANotificationScheduler } from "../ETANotificationScheduler"; import { UnoptimizedInMemoryShuttleRepository } from "../../../repositories/shuttle/UnoptimizedInMemoryShuttleRepository"; +import { InMemoryExternalSourceETARepository } from "../../../repositories/shuttle/eta/InMemoryExternalSourceETARepository"; import { IEta, IShuttle, IStop } from "../../../entities/ShuttleRepositoryEntities"; import { addMockShuttleToRepository, addMockStopToRepository } from "../../../../testHelpers/repositorySetupHelpers"; import { AppleNotificationSender } from "../../senders/AppleNotificationSender"; @@ -26,18 +27,21 @@ async function waitForMilliseconds(ms: number): Promise { describe("ETANotificationScheduler", () => { - let shuttleRepository: UnoptimizedInMemoryShuttleRepository + let shuttleRepository: UnoptimizedInMemoryShuttleRepository; + let etaRepository: InMemoryExternalSourceETARepository; let notificationService: ETANotificationScheduler; let notificationRepository: NotificationRepository; beforeEach(() => { shuttleRepository = new UnoptimizedInMemoryShuttleRepository(); notificationRepository = new InMemoryNotificationRepository(); + etaRepository = new InMemoryExternalSourceETARepository(); mockNotificationSenderMethods(true); const appleNotificationSender = new MockAppleNotificationSender(false); notificationService = new ETANotificationScheduler( + etaRepository, shuttleRepository, notificationRepository, appleNotificationSender, @@ -127,6 +131,7 @@ describe("ETANotificationScheduler", () => { mockNotificationSenderMethods(false); const updatedNotificationSender = new MockAppleNotificationSender(false); notificationService = new ETANotificationScheduler( + etaRepository, shuttleRepository, notificationRepository, updatedNotificationSender,