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

@@ -19,7 +19,7 @@ export class InMemoryNotificationRepository implements NotificationRepository {
*/
private deviceIdsToDeliverTo: { [key: string]: DeviceIdSecondsThresholdAssociation } = {}
private subscribers: Listener[] = [];
private listeners: Listener[] = [];
async getAllNotificationsForShuttleAndStopId(shuttleId: string, stopId: string) {
const tuple = new TupleKey(shuttleId, stopId);
@@ -81,12 +81,34 @@ export class InMemoryNotificationRepository implements NotificationRepository {
return;
}
const secondsThreshold = this.deviceIdsToDeliverTo[tupleKey.toString()][deviceId];
delete this.deviceIdsToDeliverTo[tupleKey.toString()][deviceId];
this.listeners.forEach((listener) => {
const event: NotificationEvent = {
event: 'delete',
notification: {
deviceId,
shuttleId,
stopId,
secondsThreshold
}
}
listener(event);
})
}
public subscribeToNotificationChanges(listener: Listener): void {
const index = this.listeners.findIndex((existingListener) => existingListener == listener);
if (index < 0) {
this.listeners.push(listener);
}
}
public unsubscribeFromNotificationChanges(listener: Listener): void {
const index = this.listeners.findIndex((existingListener) => existingListener == listener);
if (index >= 0) {
this.listeners.splice(index, 1);
}
}
}