diff --git a/stream_chat/tests/async_chat/test_channel.py b/stream_chat/tests/async_chat/test_channel.py index a266601d..2ec76044 100644 --- a/stream_chat/tests/async_chat/test_channel.py +++ b/stream_chat/tests/async_chat/test_channel.py @@ -53,6 +53,29 @@ async def test_send_message_with_options(self, channel: Channel, random_user: Di assert "message" in response assert response["message"]["text"] == "hi" + async def test_send_message_with_restricted_visibility( + self, client: StreamChatAsync, channel: Channel, random_user: Dict + ): + + # Create test users first + restricted_users = [ + {"id": "amy", "name": "Amy"}, + {"id": "paul", "name": "Paul"}, + ] + await client.upsert_users(restricted_users) + + # Add users to channel + await channel.add_members([u["id"] for u in restricted_users]) + + # Send message with restricted visibility + response = await channel.send_message( + {"text": "hi", "restricted_visibility": ["amy", "paul"]}, random_user["id"] + ) + + assert "message" in response + assert response["message"]["text"] == "hi" + assert response["message"]["restricted_visibility"] == ["amy", "paul"] + async def test_send_event(self, channel: Channel, random_user: Dict): response = await channel.send_event({"type": "typing.start"}, random_user["id"]) assert "event" in response diff --git a/stream_chat/tests/async_chat/test_client.py b/stream_chat/tests/async_chat/test_client.py index f9ef5cca..2190df28 100644 --- a/stream_chat/tests/async_chat/test_client.py +++ b/stream_chat/tests/async_chat/test_client.py @@ -325,6 +325,64 @@ async def test_update_message_partial( assert response["message"]["text"] == "helloworld" assert response["message"]["awesome"] is True + async def test_update_message_restricted_visibility( + self, client: StreamChatAsync, channel: Channel, random_user: Dict + ): + # Create test users first + restricted_users = [ + {"id": "amy", "name": "Amy"}, + {"id": "paul", "name": "Paul"}, + ] + await client.upsert_users(restricted_users) + + # Add users to channel + await channel.add_members([u["id"] for u in restricted_users]) + + # Send initial message + msg_id = str(uuid.uuid4()) + response = await channel.send_message( + {"id": msg_id, "text": "hello world"}, random_user["id"] + ) + assert response["message"]["text"] == "hello world" + + # Update message with restricted visibility + response = await client.update_message( + { + "id": msg_id, + "text": "helloworld", + "restricted_visibility": ["amy", "paul"], + "user": {"id": response["message"]["user"]["id"]}, + } + ) + assert response["message"]["text"] == "helloworld" + assert response["message"]["restricted_visibility"] == ["amy", "paul"] + + async def test_update_message_partial_restricted_visibility( + self, client: StreamChatAsync, channel: Channel, random_user: Dict + ): + # Create test users first + restricted_users = [ + {"id": "amy", "name": "Amy"}, + {"id": "paul", "name": "Paul"}, + ] + client.upsert_users(restricted_users) + + # Add users to channel + channel.add_members([u["id"] for u in restricted_users]) + + msg_id = str(uuid.uuid4()) + response = await channel.send_message( + {"id": msg_id, "text": "hello world"}, random_user["id"] + ) + assert response["message"]["text"] == "hello world" + response = await client.update_message_partial( + msg_id, + dict(set=dict(text="helloworld", restricted_visibility=["amy"])), + random_user["id"], + ) + + assert response["message"]["restricted_visibility"] == ["amy"] + async def test_delete_message( self, client: StreamChatAsync, channel: Channel, random_user: Dict ): diff --git a/stream_chat/tests/test_channel.py b/stream_chat/tests/test_channel.py index 522ea463..5972490e 100644 --- a/stream_chat/tests/test_channel.py +++ b/stream_chat/tests/test_channel.py @@ -63,6 +63,28 @@ def test_send_pending_message( assert "message" in response assert response["message"]["text"] == "hi" + def test_send_message_with_restricted_visibility( + self, client: StreamChat, channel: Channel, random_user: Dict + ): + + # Create test users first + restricted_users = [ + {"id": "amy", "name": "Amy"}, + {"id": "paul", "name": "Paul"}, + ] + client.upsert_users(restricted_users) + + # Add users to channel + channel.add_members([u["id"] for u in restricted_users]) + + # Send message with restricted visibility + response = channel.send_message( + {"text": "hi", "restricted_visibility": ["amy", "paul"]}, random_user["id"] + ) + assert "message" in response + assert response["message"]["text"] == "hi" + assert response["message"]["restricted_visibility"] == ["amy", "paul"] + def test_send_event(self, channel: Channel, random_user: Dict): response = channel.send_event({"type": "typing.start"}, random_user["id"]) assert "event" in response diff --git a/stream_chat/tests/test_client.py b/stream_chat/tests/test_client.py index 2390470d..f66c3e82 100644 --- a/stream_chat/tests/test_client.py +++ b/stream_chat/tests/test_client.py @@ -370,6 +370,64 @@ def test_update_message_partial( assert response["message"]["text"] == "helloworld" assert response["message"]["awesome"] is True + def test_update_message_restricted_visibility( + self, client: StreamChat, channel: Channel, random_user: Dict + ): + # Create test users first + restricted_users = [ + {"id": "amy", "name": "Amy"}, + {"id": "paul", "name": "Paul"}, + ] + client.upsert_users(restricted_users) + + # Add users to channel + channel.add_members([u["id"] for u in restricted_users]) + + # Send initial message + msg_id = str(uuid.uuid4()) + response = channel.send_message( + {"id": msg_id, "text": "hello world"}, random_user["id"] + ) + assert response["message"]["text"] == "hello world" + + # Update message with restricted visibility + response = client.update_message( + { + "id": msg_id, + "text": "helloworld", + "restricted_visibility": ["amy", "paul"], + "user": {"id": response["message"]["user"]["id"]}, + } + ) + assert response["message"]["text"] == "helloworld" + assert response["message"]["restricted_visibility"] == ["amy", "paul"] + + def test_update_message_partial_restricted_visibility( + self, client: StreamChat, channel: Channel, random_user: Dict + ): + # Create test users first + restricted_users = [ + {"id": "amy", "name": "Amy"}, + {"id": "paul", "name": "Paul"}, + ] + client.upsert_users(restricted_users) + + # Add users to channel + channel.add_members([u["id"] for u in restricted_users]) + + msg_id = str(uuid.uuid4()) + response = channel.send_message( + {"id": msg_id, "text": "hello world"}, random_user["id"] + ) + assert response["message"]["text"] == "hello world" + response = client.update_message_partial( + msg_id, + dict(set=dict(text="helloworld", restricted_visibility=["amy"])), + random_user["id"], + ) + + assert response["message"]["restricted_visibility"] == ["amy"] + def test_delete_message(self, client: StreamChat, channel, random_user: Dict): msg_id = str(uuid.uuid4()) channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])