@@ -136,7 +136,7 @@ async def test_get_app_settings(self, client: StreamChatAsync):
136136
137137 async def test_update_user (self , client : StreamChatAsync ):
138138 user = {"id" : str (uuid .uuid4 ())}
139- response = await client .update_user (user )
139+ response = await client .upsert_user (user )
140140 assert "users" in response
141141 assert user ["id" ] in response ["users" ]
142142
@@ -148,7 +148,7 @@ async def test_update_users(self, client: StreamChatAsync):
148148
149149 async def test_update_user_partial (self , client : StreamChatAsync ):
150150 user_id = str (uuid .uuid4 ())
151- await client .update_user ({"id" : user_id , "field" : "value" })
151+ await client .upsert_user ({"id" : user_id , "field" : "value" })
152152
153153 response = await client .update_user_partial (
154154 {"id" : user_id , "set" : {"field" : "updated" }}
@@ -785,7 +785,7 @@ async def test_imports_end2end(self, client: StreamChatAsync):
785785 headers = {"Content-Type" : "application/json" },
786786 ) as resp :
787787 assert resp .status == 200
788- sess .close ()
788+ await sess .close ()
789789
790790 create_resp = await client .create_import (url_resp ["path" ], "upsert" )
791791 assert create_resp ["import_task" ]["id" ]
@@ -795,3 +795,64 @@ async def test_imports_end2end(self, client: StreamChatAsync):
795795
796796 list_resp = await client .list_imports ({"limit" : 1 })
797797 assert len (list_resp ["import_tasks" ]) == 1
798+
799+ async def test_unread_counts (
800+ self , client : StreamChatAsync , channel , random_user : Dict
801+ ):
802+ await channel .add_members ([random_user ["id" ]])
803+ msg_id = str (uuid .uuid4 ())
804+ await channel .send_message (
805+ {"id" : msg_id , "text" : "helloworld" }, str (uuid .uuid4 ())
806+ )
807+ response = await client .unread_counts (random_user ["id" ])
808+ assert "total_unread_count" in response
809+ assert "channels" in response
810+ assert "channel_type" in response
811+ assert response ["total_unread_count" ] == 1
812+ assert len (response ["channels" ]) == 1
813+ assert response ["channels" ][0 ]["channel_id" ] == channel .cid
814+ assert len (response ["channel_type" ]) == 1
815+
816+ # test threads unread counts
817+ await channel .send_message (
818+ {"parent_id" : msg_id , "text" : "helloworld" }, random_user ["id" ]
819+ )
820+ await channel .send_message (
821+ {"parent_id" : msg_id , "text" : "helloworld" }, str (uuid .uuid4 ())
822+ )
823+ response = await client .unread_counts (random_user ["id" ])
824+ assert "total_unread_threads_count" in response
825+ assert "threads" in response
826+ assert response ["total_unread_threads_count" ] == 1
827+ assert len (response ["threads" ]) == 1
828+ assert response ["threads" ][0 ]["parent_message_id" ] == msg_id
829+
830+ async def test_unread_counts_batch (
831+ self , client : StreamChatAsync , channel , random_users : Dict
832+ ):
833+ await channel .add_members ([x ["id" ] for x in random_users ])
834+ msg_id = str (uuid .uuid4 ())
835+ await channel .send_message (
836+ {"id" : msg_id , "text" : "helloworld" }, str (uuid .uuid4 ())
837+ )
838+ response = await client .unread_counts_batch ([x ["id" ] for x in random_users ])
839+ assert "counts_by_user" in response
840+ for user_id in [x ["id" ] for x in random_users ]:
841+ assert user_id in response ["counts_by_user" ]
842+ assert response ["counts_by_user" ][user_id ]["total_unread_count" ] == 1
843+
844+ # send this message to add user to the thread
845+ await channel .send_message (
846+ {"parent_id" : msg_id , "text" : "helloworld" }, user_id
847+ )
848+
849+ # test threads unread counts
850+ await channel .send_message (
851+ {"parent_id" : msg_id , "text" : "helloworld" }, str (uuid .uuid4 ())
852+ )
853+ response = await client .unread_counts_batch ([x ["id" ] for x in random_users ])
854+ for user_id in [x ["id" ] for x in random_users ]:
855+ assert user_id in response ["counts_by_user" ]
856+ assert (
857+ response ["counts_by_user" ][user_id ]["total_unread_threads_count" ] == 1
858+ )
0 commit comments