Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vdfdev committed Aug 10, 2021
1 parent 86778d5 commit 8dc0040
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/server/transport/pubsub/in-memory-pub-sub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ describe('in-memory pubsub', () => {
expect(callback).toHaveBeenCalledWith(payload);
});

it('should receive message from two subscriptions', () => {
const pubSub = new InMemoryPubSub<string>();
const callback1 = jest.fn();
const callback2 = jest.fn();
pubSub.subscribe(CHANNEL_FOO, callback1);
pubSub.subscribe(CHANNEL_FOO, callback2);
const payload = 'hello world';
pubSub.publish(CHANNEL_FOO, payload);
expect(callback1).toHaveBeenCalledWith(payload);
expect(callback2).toHaveBeenCalledWith(payload);
});

it('should unsubscribe', () => {
const pubSub = new InMemoryPubSub<string>();
const callback = jest.fn();
Expand Down
10 changes: 10 additions & 0 deletions src/server/transport/pubsub/redis-pub-sub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ describe('redis pub-sub', () => {
redisCallback('notTheRightId', JSON.stringify(payload));
expect(callback).not.toHaveBeenCalled();
});

it('should ignore message after unsubscription', () => {
const callback = jest.fn();
const payload = 'hello world';
pubSub.subscribe(CHANNEL_FOO, callback);
pubSub.unsubscribeAll(CHANNEL_FOO);
const redisCallback = subClient.on.mock.calls[0][1];
redisCallback(CHANNEL_FOO, JSON.stringify(payload));
expect(callback).not.toHaveBeenCalled();
});
});

0 comments on commit 8dc0040

Please sign in to comment.