mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add shuttle and stop to repository within test
This commit is contained in:
@@ -2,8 +2,9 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
|||||||
import { NotificationService } from "../../src/services/NotificationService";
|
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, IShuttle } from "../../src/entities/entities";
|
||||||
import { updateGlobalFetchMockJson } from "../testHelpers/fetchMockHelpers";
|
import { updateGlobalFetchMockJson } from "../testHelpers/fetchMockHelpers";
|
||||||
|
import { addMockShuttleToRepository, addMockStopToRepository } from "../testHelpers/repositorySetupHelpers";
|
||||||
|
|
||||||
jest.mock("fs");
|
jest.mock("fs");
|
||||||
|
|
||||||
@@ -66,11 +67,15 @@ describe("NotificationService", () => {
|
|||||||
|
|
||||||
it("sends and clears correct notification after ETA changed", async () => {
|
it("sends and clears correct notification after ETA changed", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
const shuttle = await addMockShuttleToRepository(repository, "1");
|
||||||
|
const stop = await addMockStopToRepository(repository, "1");
|
||||||
|
|
||||||
const eta: IEta = {
|
const eta: IEta = {
|
||||||
shuttleId: "1",
|
shuttleId: shuttle.id,
|
||||||
stopId: "1",
|
stopId: stop.id,
|
||||||
secondsRemaining: 120,
|
secondsRemaining: 120,
|
||||||
};
|
};
|
||||||
|
|
||||||
const notificationData1 = {
|
const notificationData1 = {
|
||||||
deviceId: "1",
|
deviceId: "1",
|
||||||
shuttleId: eta.shuttleId,
|
shuttleId: eta.shuttleId,
|
||||||
@@ -90,7 +95,7 @@ describe("NotificationService", () => {
|
|||||||
await repository.addOrUpdateEta(eta);
|
await repository.addOrUpdateEta(eta);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(fetch as jest.Mock).toHaveBeenCalledTimes(1);
|
expect(fetch as jest.Mock).toHaveBeenCalledTimes(2);
|
||||||
const isFirstNotificationScheduled = notificationService.isNotificationScheduled(notificationData1);
|
const isFirstNotificationScheduled = notificationService.isNotificationScheduled(notificationData1);
|
||||||
const isSecondNotificationScheduled = notificationService.isNotificationScheduled(notificationData2);
|
const isSecondNotificationScheduled = notificationService.isNotificationScheduled(notificationData2);
|
||||||
// No longer scheduled after being sent
|
// No longer scheduled after being sent
|
||||||
|
|||||||
Reference in New Issue
Block a user