@@ -322,6 +322,37 @@ describe('Chats endpoints', async () => {
322322 }
323323 assertReceivedDateUpdated ( resChat1 , dbChat1 , userOneData . username ) ;
324324 assertReceivedDateUpdated ( resChat2 , dbChat2 , userOneData . username ) ;
325+ await db . chat . delete ( { where : { id : dbChat2 . id } } ) ;
326+ } ) ;
327+
328+ it ( 'should respond all the current user chats that include the given member`s' , async ( ) => {
329+ const memberUsername = dbUserTwo . username ;
330+ const dbChatId1 = dbChats . find ( ( c ) =>
331+ c . profiles . some ( ( p ) => p . profileName === memberUsername ) ,
332+ ) ! . id ;
333+ const dbChat1 = ( await db . chat . findUnique ( {
334+ where : { id : dbChatId1 } ,
335+ include : { profiles : true } ,
336+ } ) ) ! ;
337+ const dbChat2 = await createChat ( 'Hello #2' , [ dbUserOne , dbUserTwo , dbXUser ] ) ;
338+ const { authorizedApi } = await prepForAuthorizedTest ( userOneData ) ;
339+ const res = await authorizedApi . get ( `${ CHATS_URL } /members/${ memberUsername } ` ) ;
340+ const resBody = res . body as ChatFullData [ ] ;
341+ const resChat1 = resBody . find ( ( c ) => c . id === dbChat1 . id ) ! ;
342+ const resChat2 = resBody . find ( ( c ) => c . id === dbChat2 . id ) ! ;
343+ expect ( res . statusCode ) . toBe ( 200 ) ;
344+ expect ( res . type ) . toMatch ( / j s o n / ) ;
345+ expect ( resBody ) . toBeInstanceOf ( Array ) ;
346+ expect ( resBody ) . toHaveLength ( 2 ) ;
347+ expect ( resBody . every ( ( c ) => c . id === dbChat1 . id || c . id === dbChat2 . id ) ) . toBe ( true ) ;
348+ for ( const c of resBody ) {
349+ if ( c . id === dbChat2 . id ) assertChat ( c , c . id , 1 , 3 ) ;
350+ else assertChat ( c , c . id ) ;
351+ assertChatMembersTangibility ( c ) ;
352+ }
353+ assertReceivedDateUpdated ( resChat1 , dbChat1 , userOneData . username ) ;
354+ assertReceivedDateUpdated ( resChat2 , dbChat2 , userOneData . username ) ;
355+ await db . chat . delete ( { where : { id : dbChat2 . id } } ) ;
325356 } ) ;
326357 } ) ;
327358
0 commit comments