Skip to content

Commit 575fb37

Browse files
author
Rafael Marinho
committed
test(cha-769): add tests
1 parent 5e03572 commit 575fb37

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import pytest
2+
from typing import Dict
3+
4+
from stream_chat.async_chat.client import StreamChatAsync
5+
6+
7+
@pytest.mark.incremental
8+
class TestLiveLocations:
9+
async def test_get_user_locations(self, client: StreamChatAsync, random_user: Dict):
10+
# First create a message to attach location to
11+
channel = client.channel("messaging", str(random_user["id"]))
12+
channel.create(random_user["id"])
13+
14+
# Create a message to attach location to
15+
shared_location = {
16+
"latitude": 37.7749,
17+
"longitude": -122.4194,
18+
}
19+
20+
channel.send_message({"text": "Message with location", "shared_location": shared_location}, random_user["id"])
21+
22+
# Get user locations
23+
response = await client.get_user_locations(random_user["id"])
24+
25+
assert "active_live_locations" in response
26+
assert isinstance(response["active_live_locations"], list)
27+
28+
async def test_update_user_location(self, client: StreamChatAsync, random_user: Dict):
29+
# First create a message to attach location to
30+
channel = client.channel("messaging", str(random_user["id"]))
31+
await channel.create(random_user["id"])
32+
msg = await channel.send_message({"text": "Message with location"}, random_user["id"])
33+
message_id = msg["message"]["id"]
34+
35+
# Update user location
36+
location_data = {
37+
"latitude": 37.7749,
38+
"longitude": -122.4194,
39+
}
40+
response = await client.update_user_location(message_id, location_data)
41+
42+
assert "shared_location" in response
43+
assert response["shared_location"]["latitude"] == location_data["latitude"]
44+
assert response["shared_location"]["longitude"] == location_data["longitude"]
45+
46+
# Get user locations to verify
47+
locations_response = await client.get_user_locations(random_user["id"])
48+
assert "active_live_locations" in locations_response
49+
assert len(locations_response["active_live_locations"]) > 0
50+
location = locations_response["active_live_locations"][0]
51+
assert location["latitude"] == location_data["latitude"]
52+
assert location["longitude"] == location_data["longitude"]
53+
54+
# Cleanup
55+
try:
56+
await channel.delete()
57+
except Exception:
58+
pass
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pytest
2+
from typing import Dict
3+
4+
from stream_chat import StreamChat
5+
6+
7+
@pytest.mark.incremental
8+
class TestLiveLocations:
9+
def test_get_user_locations(self, client: StreamChat, random_user: Dict):
10+
# First create a message to attach location to
11+
channel = client.channel("messaging", str(random_user["id"]))
12+
channel.create(random_user["id"])
13+
14+
# Create a message to attach location to
15+
shared_location = {
16+
"latitude": 37.7749,
17+
"longitude": -122.4194,
18+
}
19+
20+
channel.send_message({"text": "Message with location", "shared_location": shared_location}, random_user["id"])
21+
22+
# Get user locations
23+
response = client.get_user_locations(random_user["id"])
24+
25+
assert "active_live_locations" in response
26+
assert isinstance(response["active_live_locations"], list)
27+
28+
def test_update_user_location(self, client: StreamChat, random_user: Dict):
29+
# First create a message to attach location to
30+
channel = client.channel("messaging", str(random_user["id"]))
31+
channel.create(random_user["id"])
32+
33+
# Create a message to attach location to
34+
shared_location = {
35+
"latitude": 37.7749,
36+
"longitude": -122.4194,
37+
}
38+
39+
msg = channel.send_message({"text": "Message with location", "shared_location": shared_location}, random_user["id"])
40+
message_id = msg["message"]["id"]
41+
42+
# Update user location
43+
location_data = {
44+
"latitude": 37.7749,
45+
"longitude": -122.4194,
46+
}
47+
response = client.update_user_location(message_id, location_data)
48+
49+
assert "shared_location" in response
50+
assert response["shared_location"]["latitude"] == location_data["latitude"]
51+
assert response["shared_location"]["longitude"] == location_data["longitude"]
52+
53+
# Get user locations to verify
54+
locations_response = client.get_user_locations(random_user["id"])
55+
assert "active_live_locations" in locations_response
56+
assert len(locations_response["active_live_locations"]) > 0
57+
location = locations_response["active_live_locations"][0]
58+
assert location["latitude"] == location_data["latitude"]
59+
assert location["longitude"] == location_data["longitude"]
60+
61+
# Cleanup
62+
try:
63+
channel.delete()
64+
except Exception:
65+
pass

0 commit comments

Comments
 (0)