Skip to content

Commit

Permalink
wip: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amydevs committed Apr 15, 2024
1 parent 890ff03 commit 55f3704
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/notifications/NotificationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class NotificationsManager {
await tran.lock(
this.notificationsManagerOutboxNotificationsCounterDbPath.join(''),
);
const notificationIds = await this.getNotificationIds('all', tran);
const notificationIds = await this.getOutboxNotificationIds(tran);
const numMessages = await tran.get<number>(
this.notificationsManagerOutboxNotificationsCounterDbPath,
);
Expand Down
50 changes: 50 additions & 0 deletions tests/notifications/NotificationsManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,38 @@ describe('NotificationsManager', () => {
await acl.unsetNodePerm(senderId);
await notificationsManager.stop();
});
test('clears outbox notifications', async () => {
const notificationsManager =
await NotificationsManager.createNotificationsManager({
acl,
db,
nodeManager,
taskManager,
keyRing,
logger,
});
await receiver.acl.setNodePerm(keyRing.getNodeId(), {
gestalt: {
notify: null,
},
vaults: {},
});
await notificationsManager.sendNotification({
nodeId: receiver.keyRing.getNodeId(),
data: {
type: 'General',
message: 'msg1',
},
});
await notificationsManager.clearOutboxNotifications();
const outboxNotifications =
await notificationsManager.readOutboxNotifications();
expect(outboxNotifications).toHaveLength(0);
// Reverse side-effects
await receiver.notificationsManager.clearNotifications();
await receiver.acl.unsetNodePerm(keyRing.getNodeId());
await notificationsManager.stop();
});
test('notifications are persistent across restarts', async () => {
const generateNotificationId =
notificationsUtils.createNotificationIdGenerator();
Expand Down Expand Up @@ -1068,13 +1100,31 @@ describe('NotificationsManager', () => {
},
vaults: {},
});
await receiver.acl.setNodePerm(keyRing.getNodeId(), {
gestalt: {
notify: null,
},
vaults: {},
});
await notificationsManager.receiveNotification(notification);
await notificationsManager.sendNotification({
nodeId: receiver.keyRing.getNodeId(),
data: {
type: 'General',
message: 'msg1',
},
});
await notificationsManager.stop();
await notificationsManager.start({ fresh: true });
const receivedNotifications =
await notificationsManager.readNotifications();
expect(receivedNotifications).toHaveLength(0);
const outboxNotifications =
await notificationsManager.readOutboxNotifications();
expect(outboxNotifications).toHaveLength(0);
// Reverse side-effects
await receiver.notificationsManager.clearNotifications();
await receiver.acl.unsetNodePerm(keyRing.getNodeId());
await notificationsManager.clearNotifications();
await acl.unsetNodePerm(senderId);
await notificationsManager.stop();
Expand Down

0 comments on commit 55f3704

Please sign in to comment.