@@ -546,6 +546,75 @@ def loop_times(times)
546546 end
547547 end
548548
549+ describe 'unread count' do
550+ before ( :all ) do
551+ @user_id = SecureRandom . uuid
552+ @client . update_users ( [ { id : @user_id } ] )
553+ @channel = @client . channel ( 'team' , channel_id : SecureRandom . uuid )
554+ @channel . create ( @user_id )
555+ @channel . add_members ( [ @user_id ] )
556+ end
557+
558+ before ( :each ) do
559+ @client . mark_all_read ( @user_id )
560+ end
561+
562+ it 'gets unread count' do
563+ resp = @client . unread_counts ( @user_id )
564+ expect ( resp [ 'total_unread_count' ] ) . to eq 0
565+ end
566+
567+ it 'gets unread count if there are unread messages' do
568+ @channel . send_message ( { text : 'Hello world' } , @random_user [ :id ] )
569+ resp = @client . unread_counts ( @user_id )
570+ expect ( resp [ 'total_unread_count' ] ) . to eq 1
571+ end
572+
573+ it 'gets unread count for a channel' do
574+ @message = @channel . send_message ( { text : 'Hello world' } , @random_user [ :id ] )
575+ resp = @client . unread_counts ( @user_id )
576+ expect ( resp [ 'total_unread_count' ] ) . to eq 1
577+ expect ( resp [ 'channels' ] . length ) . to eq 1
578+ expect ( resp [ 'channels' ] [ 0 ] [ 'channel_id' ] ) . to eq @channel . cid
579+ expect ( resp [ 'channels' ] [ 0 ] [ 'unread_count' ] ) . to eq 1
580+ expect ( resp [ 'channels' ] [ 0 ] [ 'last_read' ] ) . not_to be_nil
581+ end
582+ end
583+
584+ describe 'unread counts batch' do
585+ before ( :all ) do
586+ @user_id1 = SecureRandom . uuid
587+ @user_id2 = SecureRandom . uuid
588+ @client . update_users ( [ { id : @user_id1 } , { id : @user_id2 } ] )
589+ @channel = @client . channel ( 'team' , channel_id : SecureRandom . uuid )
590+ @channel . create ( @user_id1 )
591+ @channel . add_members ( [ @user_id1 , @user_id2 ] )
592+ end
593+
594+ before ( :each ) do
595+ @client . mark_all_read ( @user_id1 )
596+ @client . mark_all_read ( @user_id2 )
597+ end
598+
599+ it 'gets unread counts for a batch of users' do
600+ resp = @client . unread_counts_batch ( [ @user_id1 , @user_id2 ] )
601+ expect ( resp [ 'counts_by_user' ] . length ) . to eq 0
602+ end
603+
604+ it 'gets unread counts for a batch of users with unread messages' do
605+ @channel . send_message ( { text : 'Hello world' } , @user_id1 )
606+ @channel . send_message ( { text : 'Hello world' } , @user_id2 )
607+
608+ resp = @client . unread_counts_batch ( [ @user_id1 , @user_id2 ] )
609+ expect ( resp [ 'counts_by_user' ] . length ) . to eq 2
610+ expect ( resp [ 'counts_by_user' ] [ @user_id1 ] [ 'total_unread_count' ] ) . to eq 1
611+ expect ( resp [ 'counts_by_user' ] [ @user_id2 ] [ 'total_unread_count' ] ) . to eq 1
612+ expect ( resp [ 'counts_by_user' ] [ @user_id1 ] [ 'channels' ] . length ) . to eq 1
613+ expect ( resp [ 'counts_by_user' ] [ @user_id2 ] [ 'channels' ] . length ) . to eq 1
614+ expect ( resp [ 'counts_by_user' ] [ @user_id1 ] [ 'channels' ] [ 0 ] [ 'channel_id' ] ) . to eq @channel . cid
615+ end
616+ end
617+
549618 describe 'blocklist' do
550619 before ( :all ) do
551620 @blocklist = SecureRandom . uuid
0 commit comments