@@ -7,6 +7,7 @@ import { StreamChat } from '../../src/client';
77import { ConnectionState } from '../../src/connection_fallback' ;
88import { StableWSConnection } from '../../src/connection' ;
99import { mockChannelQueryResponse } from './test-utils/mockChannelQueryResponse' ;
10+ import { generateThreadResponse } from './test-utils/generateThreadResponse' ;
1011import { DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE } from '../../src/constants' ;
1112
1213import {
@@ -787,6 +788,32 @@ describe('StreamChat.queryChannels', async () => {
787788 } ) ;
788789} ) ;
789790
791+ describe ( 'StreamChat.queryThreads' , ( ) => {
792+ it ( 'returns threads and next, and hydrates poll cache with parent messages' , async ( ) => {
793+ const client = await getClientWithUser ( ) ;
794+ const parentMessage = generateMsg ( ) ;
795+ const rawThread = generateThreadResponse (
796+ mockChannelQueryResponse . channel ,
797+ parentMessage ,
798+ ) ;
799+ const apiResponse = { threads : [ rawThread ] , next : undefined } ;
800+
801+ const postStub = sinon . stub ( client , 'post' ) ;
802+ postStub . onFirstCall ( ) . resolves ( apiResponse ) ;
803+ const hydratePollCacheSpy = sinon . spy ( client . polls , 'hydratePollCache' ) ;
804+
805+ const result = await client . queryThreads ( ) ;
806+
807+ expect ( result . threads ) . to . have . lengthOf ( 1 ) ;
808+ expect ( result . threads [ 0 ] . id ) . to . equal ( parentMessage . id ) ;
809+ expect ( result . next ) . to . be . undefined ;
810+ expect ( hydratePollCacheSpy . calledOnce ) . to . be . true ;
811+ expect ( hydratePollCacheSpy . calledWith ( [ parentMessage ] ) ) . to . be . true ;
812+
813+ postStub . restore ( ) ;
814+ } ) ;
815+ } ) ;
816+
790817describe ( 'StreamChat.queryReactions' , ( ) => {
791818 let client ;
792819 let dispatchSpy ;
0 commit comments