add shuttle and stop to repository within test

This commit is contained in:
2025-02-03 22:42:50 -08:00
parent 103ddef523
commit d357af7509

View File

@@ -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