Skip to content

Commit

Permalink
chore: add edge case for notification.message_new
Browse files Browse the repository at this point in the history
  • Loading branch information
isekovanic committed Feb 6, 2025
1 parent 2cf1afb commit aa372c8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/unit/channel_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,39 @@ describe('ChannelManager', () => {
expect(moveChannelUpwardsArgs).to.deep.equal({ channels, channelToMove: newChannel, sort });
expect(setChannelsStub.args[0][0]).to.deep.equal(Utils.moveChannelUpwards(moveChannelUpwardsArgs));
});

it('should not add duplicate channels for multiple event invocations', async () => {
const newChannelResponse = generateChannel({ channel: { id: 'channel4' } });
const newChannel = client.channel(newChannelResponse.channel.type, newChannelResponse.channel.id);
getAndWatchChannelStub.resolves(newChannel);

const event = {
type: 'notification.message_new',
channel: ({ type: 'messaging', id: 'channel4' } as unknown) as ChannelResponse,
} as const;
// call the event 3 times
client.dispatchEvent(event);
client.dispatchEvent(event);
client.dispatchEvent(event);

await clock.runAllAsync();

const {
pagination: { sort },
channels,
} = channelManager.state.getLatestValue();
const moveChannelUpwardsArgs = { channels, channelToMove: newChannel, sort };

expect(getAndWatchChannelStub.callCount).to.equal(3);
expect(moveChannelUpwardsSpy.callCount).to.equal(3);
expect(setChannelsStub.callCount).to.equal(3);
moveChannelUpwardsSpy.args.forEach(arg => {
expect(arg[0]).to.deep.equal(moveChannelUpwardsArgs);
})
setChannelsStub.args.forEach(arg => {
expect(arg[0]).to.deep.equal(Utils.moveChannelUpwards(moveChannelUpwardsArgs));
})
});
});

describe('channelVisibleHandler', () => {
Expand Down

0 comments on commit aa372c8

Please sign in to comment.