diff --git a/test/services/NotificationServiceTests.test.ts b/test/services/NotificationServiceTests.test.ts index b0aa767..271a003 100644 --- a/test/services/NotificationServiceTests.test.ts +++ b/test/services/NotificationServiceTests.test.ts @@ -2,8 +2,9 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { NotificationService } from "../../src/services/NotificationService"; import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository"; import fs from "fs"; -import { IEta } from "../../src/entities/entities"; +import { IEta, IShuttle } from "../../src/entities/entities"; import { updateGlobalFetchMockJson } from "../testHelpers/fetchMockHelpers"; +import { addMockShuttleToRepository, addMockStopToRepository } from "../testHelpers/repositorySetupHelpers"; jest.mock("fs"); @@ -66,11 +67,15 @@ describe("NotificationService", () => { it("sends and clears correct notification after ETA changed", async () => { // Arrange + const shuttle = await addMockShuttleToRepository(repository, "1"); + const stop = await addMockStopToRepository(repository, "1"); + const eta: IEta = { - shuttleId: "1", - stopId: "1", + shuttleId: shuttle.id, + stopId: stop.id, secondsRemaining: 120, }; + const notificationData1 = { deviceId: "1", shuttleId: eta.shuttleId, @@ -90,7 +95,7 @@ describe("NotificationService", () => { await repository.addOrUpdateEta(eta); // Assert - expect(fetch as jest.Mock).toHaveBeenCalledTimes(1); + expect(fetch as jest.Mock).toHaveBeenCalledTimes(2); const isFirstNotificationScheduled = notificationService.isNotificationScheduled(notificationData1); const isSecondNotificationScheduled = notificationService.isNotificationScheduled(notificationData2); // No longer scheduled after being sent