mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add another test to see if the data actually gets scheduled
This commit is contained in:
@@ -3,6 +3,7 @@ import { NotificationService } from "../../src/services/NotificationService";
|
||||
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
|
||||
import fs from "fs";
|
||||
import { IEta } from "../../src/entities/entities";
|
||||
import { updateGlobalFetchMockJson } from "../testHelpers/fetchMockHelpers";
|
||||
|
||||
jest.mock("fs");
|
||||
|
||||
@@ -49,7 +50,21 @@ describe("NotificationService", () => {
|
||||
})
|
||||
|
||||
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
|
||||
const eta: IEta = {
|
||||
shuttleId: "1",
|
||||
@@ -57,20 +72,26 @@ describe("NotificationService", () => {
|
||||
secondsRemaining: 120,
|
||||
};
|
||||
|
||||
// Simulate 200 + empty object for successful push notification
|
||||
updateGlobalFetchMockJson({});
|
||||
|
||||
// Act
|
||||
await notificationService.scheduleNotification({
|
||||
const notificationData = {
|
||||
deviceId: "1",
|
||||
shuttleId: eta.shuttleId,
|
||||
stopId: eta.stopId,
|
||||
});
|
||||
}
|
||||
await notificationService.scheduleNotification(notificationData);
|
||||
await repository.addOrUpdateEta(eta);
|
||||
|
||||
// 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 () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user