add another test to see if the data actually gets scheduled

This commit is contained in:
2025-02-03 21:26:59 -08:00
parent 737a61fd41
commit 69525a643d

View File

@@ -3,6 +3,7 @@ import { NotificationService } from "../../src/services/NotificationService";
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository"; import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
import fs from "fs"; import fs from "fs";
import { IEta } from "../../src/entities/entities"; import { IEta } from "../../src/entities/entities";
import { updateGlobalFetchMockJson } from "../testHelpers/fetchMockHelpers";
jest.mock("fs"); jest.mock("fs");
@@ -49,7 +50,21 @@ describe("NotificationService", () => {
}) })
describe("scheduleNotification", () => { describe("scheduleNotification", () => {
it("sends a notification to given shuttle/stop ID when changed", async () => { it("schedules the notification", async () => {
// arrange
const notificationData = {
deviceId: "1",
shuttleId: "1",
stopId: "1"
};
await notificationService.scheduleNotification(notificationData);
const isNotificationScheduled = notificationService.isNotificationScheduled(notificationData);
expect(isNotificationScheduled).toEqual(true);
});
it("sends and clears correct notification after ETA changed", async () => {
// Arrange // Arrange
const eta: IEta = { const eta: IEta = {
shuttleId: "1", shuttleId: "1",
@@ -57,20 +72,26 @@ describe("NotificationService", () => {
secondsRemaining: 120, secondsRemaining: 120,
}; };
// Simulate 200 + empty object for successful push notification
updateGlobalFetchMockJson({});
// Act // Act
await notificationService.scheduleNotification({ const notificationData = {
deviceId: "1", deviceId: "1",
shuttleId: eta.shuttleId, shuttleId: eta.shuttleId,
stopId: eta.stopId, stopId: eta.stopId,
}); }
await notificationService.scheduleNotification(notificationData);
await repository.addOrUpdateEta(eta); await repository.addOrUpdateEta(eta);
// Assert // Assert
// ...that notification (fetch request) was sent expect(fetch as jest.Mock).toHaveBeenCalledTimes(1);
const isNotificationScheduled = notificationService.isNotificationScheduled(notificationData);
// No longer scheduled after being sent
expect(isNotificationScheduled).toBe(false);
}); });
it("clears the notification after delivering successfully", async () => { it("leaves notification in array if delivery unsuccessful", async () => {
}); });
}); });