mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add tests and implementation for notification deletes
This commit is contained in:
@@ -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);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user