diff --git a/src/index.ts b/src/index.ts index c2d04e4..3880fac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import { TimedApiBasedShuttleRepositoryLoader } from "./loaders/TimedApiBasedShu import { ETANotificationScheduler } from "./notifications/schedulers/ETANotificationScheduler"; import { loadShuttleTestData } from "./loaders/loadShuttleTestData"; import { AppleNotificationSender } from "./notifications/senders/AppleNotificationSender"; +import { InMemoryNotificationRepository } from "./repositories/InMemoryNotificationRepository"; const typeDefs = readFileSync("./schema.graphqls", "utf8"); @@ -23,8 +24,14 @@ async function main() { if (process.argv.length > 2 && process.argv[2] == "integration-testing") { console.log("Using integration testing setup") await loadShuttleTestData(repository); + const appleNotificationSender = new AppleNotificationSender(false); - notificationService = new ETANotificationScheduler(repository, appleNotificationSender); + const inMemoryNotificationRepository = new InMemoryNotificationRepository(); + notificationService = new ETANotificationScheduler( + repository, + inMemoryNotificationRepository, + appleNotificationSender + ); } else { const repositoryDataUpdater = new TimedApiBasedShuttleRepositoryLoader( repository diff --git a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts index afc6f85..392844e 100644 --- a/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts +++ b/test/notifications/schedulers/ETANotificationSchedulerTests.test.ts @@ -5,6 +5,7 @@ import http2 from "http2"; import { IEta, IShuttle, IStop } from "../../../src/entities/entities"; import { addMockShuttleToRepository, addMockStopToRepository } from "../../testHelpers/repositorySetupHelpers"; import { AppleNotificationSender } from "../../../src/notifications/senders/AppleNotificationSender"; +import { InMemoryNotificationRepository } from "../../../src/repositories/InMemoryNotificationRepository"; jest.mock("http2"); jest.mock("../../../src/notifications/senders/AppleNotificationSender"); @@ -51,7 +52,11 @@ describe("ETANotificationScheduler", () => { mockNotificationSenderMethods(true); const appleNotificationSender = new MockAppleNotificationSender(false); - notificationService = new ETANotificationScheduler(repository, appleNotificationSender); + notificationService = new ETANotificationScheduler( + repository, + new InMemoryNotificationRepository(), + appleNotificationSender + ); }); function generateNotificationDataAndEta(shuttle: IShuttle, stop: IStop) { @@ -141,6 +146,7 @@ describe("ETANotificationScheduler", () => { mockNotificationSenderMethods(false); notificationService = new ETANotificationScheduler( repository, + new InMemoryNotificationRepository(), new MockAppleNotificationSender(), ) @@ -176,38 +182,4 @@ describe("ETANotificationScheduler", () => { expect(http2.connect as jest.Mock).toHaveBeenCalledTimes(0); }); }); - - describe("getAllScheduledNotificationsForDevice", () => { - it("returns scheduled notifications for the device ID", async () => { - // Arrange - const shuttle1 = await addMockShuttleToRepository(repository, "1"); - const stop = await addMockStopToRepository(repository, "1"); - const { notificationData1 } = generateNotificationDataAndEta(shuttle1, stop); - await notificationService.scheduleNotification(notificationData1); - - const shuttle2 = { - ...shuttle1, - id: "2", - } - await repository.addOrUpdateShuttle(shuttle2); - - const notificationData2 = { - ...notificationData1, - shuttleId: shuttle2.id, - } - await notificationService.scheduleNotification(notificationData2); - - // Act - const notifications = await notificationService.getAllScheduledNotificationsForDevice(notificationData1.deviceId); - - // Assert - expect(notifications.length).toBe(2); - }); - - it("returns an empty array if there are no notifications", async () => { - // Act - const notifications = await notificationService.getAllScheduledNotificationsForDevice("1"); - expect(notifications.length).toBe(0); - }); - }); });