add tests and implementation for notification deletes

This commit is contained in:
2025-03-27 11:18:43 -07:00
parent b0f04a9256
commit 51d66d8886
2 changed files with 52 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it } from "@jest/globals";
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import { InMemoryNotificationRepository } from "../../src/repositories/InMemoryNotificationRepository";
import { NotificationEvent } from "../../src/repositories/NotificationRepository";
describe("InMemoryNotificationRepository", () => {
let repo: InMemoryNotificationRepository;
@@ -71,16 +72,13 @@ describe("InMemoryNotificationRepository", () => {
describe("deleteNotificationIfExists", () => {
it("deletes the notification", async () => {
await repo.addOrUpdateNotification(notification);
await repo.deleteNotificationIfExists({
deviceId: "device1",
shuttleId: "shuttle1",
stopId: "stop1"
});
await repo.deleteNotificationIfExists(notification);
const result = await repo.getAllNotificationsForShuttleAndStopId("shuttle1", "stop1");
expect(result).toHaveLength(0);
});
it("does nothing if there's no notification", async () => {
await expect(repo.deleteNotificationIfExists({
deviceId: "device1",
@@ -89,4 +87,29 @@ describe("InMemoryNotificationRepository", () => {
})).resolves.not.toThrow();
});
});
describe("subscribeToNotificationChanges", () => {
it("calls subscribers when something is added", async () => {
});
it("calls subscribers when something is deleted", async () => {
await repo.addOrUpdateNotification(notification);
const mockCallback = jest.fn();
repo.subscribeToNotificationChanges(mockCallback);
await repo.deleteNotificationIfExists(notification);
expect(mockCallback).toHaveBeenCalledTimes(1);
const expectedEvent: NotificationEvent = {
event: 'delete',
notification: {
...notification,
},
};
expect(mockCallback).toHaveBeenCalledWith(expectedEvent);
});
})
});