add test and implementation for addOrUpdate listeners

This commit is contained in:
2025-03-27 11:23:07 -07:00
parent 51d66d8886
commit a84cedd05a
2 changed files with 45 additions and 3 deletions

View File

@@ -90,7 +90,38 @@ describe("InMemoryNotificationRepository", () => {
describe("subscribeToNotificationChanges", () => {
it("calls subscribers when something is added", async () => {
const mockCallback = jest.fn();
repo.subscribeToNotificationChanges(mockCallback);
await repo.addOrUpdateNotification(notification);
const expectedEvent: NotificationEvent = {
event: 'addOrUpdate',
notification,
}
expect(mockCallback).toHaveBeenCalledTimes(1);
expect(mockCallback).toHaveBeenCalledWith(expectedEvent);
});
it("calls subscribers when something is updated", async () => {
const mockCallback = jest.fn();
repo.subscribeToNotificationChanges(mockCallback);
await repo.addOrUpdateNotification(notification);
const updatedNotification = {
...notification,
secondsThreshold: notification.secondsThreshold + 60,
};
await repo.addOrUpdateNotification(updatedNotification);
const expectedEvent: NotificationEvent = {
event: 'addOrUpdate',
notification,
}
expect(mockCallback).toHaveBeenCalledTimes(2);
expect(mockCallback).toHaveBeenCalledWith(expectedEvent);
});
it("calls subscribers when something is deleted", async () => {
@@ -105,9 +136,7 @@ describe("InMemoryNotificationRepository", () => {
const expectedEvent: NotificationEvent = {
event: 'delete',
notification: {
...notification,
},
notification,
};
expect(mockCallback).toHaveBeenCalledWith(expectedEvent);
});