From 4d1b395d59e4d209e78bf9ecb34195a7118b573a Mon Sep 17 00:00:00 2001 From: Anton Arnautov Date: Tue, 26 Nov 2024 11:59:08 +0100 Subject: [PATCH] Adjust tests --- test/unit/channel.js | 5 ++--- test/unit/threads.test.ts | 8 +++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/unit/channel.js b/test/unit/channel.js index 11f8e16c7..b72ec4b61 100644 --- a/test/unit/channel.js +++ b/test/unit/channel.js @@ -652,7 +652,7 @@ describe('Channel _handleChannelEvent', function () { await channel.query(); - expect(Object.keys(channel.state.members).length).to.be.eq(2); + expect(Object.keys(channel.state.members).length).to.be.eq(1); expect(Object.keys(channel.state.watchers).length).to.be.eq(1); expect(Object.keys(channel.state.read).length).to.be.eq(1); expect(channel.state.messages.length).to.be.eq(1); @@ -1217,8 +1217,7 @@ describe('Channel lastMessage', async () => { }); describe('Channel _initializeState', () => { - // FIXME: unwatching should remove members manually, not through state initialization - it.skip('should not keep members that have unwatched since last watch', async () => { + it('should not keep members that have unwatched since last watch', async () => { const client = await getClientWithUser(); const channel = client.channel('messaging', uuidv4()); diff --git a/test/unit/threads.test.ts b/test/unit/threads.test.ts index c71088991..d3c5211fa 100644 --- a/test/unit/threads.test.ts +++ b/test/unit/threads.test.ts @@ -48,7 +48,9 @@ describe('Threads 2.0', () => { beforeEach(() => { client = new StreamChat('apiKey'); client._setUser({ id: TEST_USER_ID }); - channelResponse = generateChannel({ channel: { id: uuidv4(), name: 'Test channel' } }).channel as ChannelResponse; + channelResponse = generateChannel({ + channel: { id: uuidv4(), name: 'Test channel', members: [] }, + }).channel as ChannelResponse; channel = client.channel(channelResponse.type, channelResponse.id); parentMessageResponse = generateMsg() as MessageResponse; threadManager = new ThreadManager({ client }); @@ -57,12 +59,16 @@ describe('Threads 2.0', () => { describe('Thread', () => { it('initializes properly', () => { const threadResponse = generateThreadResponse(channelResponse, parentMessageResponse); + // mimic pre-cached channel with existing members + channel._hydrateMembers({ members: [{ user: { id: TEST_USER_ID } }] }); const thread = new Thread({ client, threadData: threadResponse }); const state = thread.state.getLatestValue(); + expect(threadResponse.channel.members).to.have.lengthOf(0); expect(threadResponse.read).to.have.lengthOf(0); expect(state.read).to.have.keys([TEST_USER_ID]); + expect(thread.channel.state.members).to.have.keys([TEST_USER_ID]); expect(thread.id).to.equal(parentMessageResponse.id); expect(thread.channel.data?.name).to.equal(channelResponse.name); });