From 9eeaa8fba1a25e20dac904fe81d2d01eec624742 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Thu, 12 Jun 2025 09:49:16 +0200 Subject: [PATCH 01/12] feat(CHA-769): support shared locations --- lib/GetStream/StreamChat/Client.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/GetStream/StreamChat/Client.php b/lib/GetStream/StreamChat/Client.php index 57433cd..f94f3a5 100644 --- a/lib/GetStream/StreamChat/Client.php +++ b/lib/GetStream/StreamChat/Client.php @@ -1659,4 +1659,26 @@ public function queryDrafts(string $userId, ?array $filter = null, ?array $sort return $this->post("drafts/query", $data); } + + /** + * Get a user active live locations + * @link https://getstream.io/chat/docs/php/live-locations/?language=php#get-a-user-active-live-locations + * @throws StreamException + */ + public function getUserActiveLiveLocations(string $userId): StreamResponse + { + $params = ["user_id" => $userId]; + return $this->client->get($this->getUrl() . "/users/live_locations", $params); + } + + /** + * Update a user active live location + * @link https://getstream.io/chat/docs/php/live-locations/?language=php#update-a-user-active-live-location + * @throws StreamException + */ + public function updateUserActiveLiveLocation(string $userId, array $location): StreamResponse + { + $params = ["user_id" => $userId, "message_id" => $messageId, "shared_location" => $location]; + return $this->client->post($this->getUrl() . "/users/live_locations", $params); + } } From d53b0455a84f3a246eb86be5d7583cfb58aec65e Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Thu, 12 Jun 2025 12:52:59 +0200 Subject: [PATCH 02/12] fix(CHA-769): lint --- lib/GetStream/StreamChat/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/GetStream/StreamChat/Client.php b/lib/GetStream/StreamChat/Client.php index f94f3a5..10f54f3 100644 --- a/lib/GetStream/StreamChat/Client.php +++ b/lib/GetStream/StreamChat/Client.php @@ -1668,7 +1668,7 @@ public function queryDrafts(string $userId, ?array $filter = null, ?array $sort public function getUserActiveLiveLocations(string $userId): StreamResponse { $params = ["user_id" => $userId]; - return $this->client->get($this->getUrl() . "/users/live_locations", $params); + return $this->get("users/live_locations", $params); } /** @@ -1676,9 +1676,9 @@ public function getUserActiveLiveLocations(string $userId): StreamResponse * @link https://getstream.io/chat/docs/php/live-locations/?language=php#update-a-user-active-live-location * @throws StreamException */ - public function updateUserActiveLiveLocation(string $userId, array $location): StreamResponse + public function updateUserActiveLiveLocation(string $userId, string $messageId, array $location): StreamResponse { $params = ["user_id" => $userId, "message_id" => $messageId, "shared_location" => $location]; - return $this->client->post($this->getUrl() . "/users/live_locations", $params); + return $this->post("users/live_locations", $params); } } From 4f76fd9a4580e857ed22edde9b1053067bf469d4 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Mon, 7 Jul 2025 09:50:24 +0200 Subject: [PATCH 03/12] tests(cha-650): add unit tests --- tests/integration/SharedLocationsTest.php | 167 ++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 tests/integration/SharedLocationsTest.php diff --git a/tests/integration/SharedLocationsTest.php b/tests/integration/SharedLocationsTest.php new file mode 100644 index 0000000..0d856fc --- /dev/null +++ b/tests/integration/SharedLocationsTest.php @@ -0,0 +1,167 @@ +client = new Client(getenv('STREAM_KEY'), getenv('STREAM_SECRET')); + $this->user = $this->getUser(); + $this->channel = $this->getChannel(); + $this->channel->updatePartial([ + "config_overrides" => ["shared_locations" => true], + ]); + + // Create a message to use for shared locations + $message = [ + 'text' => 'This is a test message for shared locations' + ]; + $response = $this->channel->sendMessage($message, $this->user['id']); + $this->messageId = $response['message']['id']; + } + + protected function tearDown(): void + { + try { + $this->channel->delete(); + $this->client->deleteUser($this->user['id'], ["user" => "hard", "messages" => "hard"]); + } catch (\Exception $e) { + // We don't care about cleanup errors + } + } + + private function getUser(): array + { + $userId = 'shared-locations-test-user-' . uniqid(); + $user = [ + 'id' => $userId, + 'name' => 'Shared Locations Test User', + ]; + $this->client->upsertUser($user); + return $user; + } + + public function getChannel(): \GetStream\StreamChat\Channel + { + $channelId = 'shared-locations-test-channel-' . uniqid(); + $channel = $this->client->Channel('messaging', $channelId); + $channel->create($this->user['id']); + return $channel; + } + + public function testGetUserActiveLiveLocations() + { + $response = $this->client->getUserActiveLiveLocations($this->user['id']); + + // The response should be a StreamResponse object + $this->assertNotNull($response); + // Initially, user should have no active live locations + $this->assertArrayHasKey('live_locations', $response); + $this->assertIsArray($response['live_locations']); + } + + public function testUpdateUserActiveLiveLocation() + { + $location = [ + 'latitude' => 40.7128, + 'longitude' => -74.0060, + 'altitude' => 10.5, + 'accuracy' => 5.0, + 'speed' => 0.0, + 'heading' => 0.0, + 'timestamp' => time() + ]; + + $response = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location); + + $this->assertNotNull($response); + $this->assertTrue(true); // If we got here, the test passed + } + + public function testUpdateUserActiveLiveLocationWithMinimalData() + { + $location = [ + 'latitude' => 34.0522, + 'longitude' => -118.2437 + ]; + + $response = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location); + + $this->assertNotNull($response); + $this->assertTrue(true); // If we got here, the test passed + } + + public function testGetUserActiveLiveLocationsAfterUpdate() + { + // First update a location + $location = [ + 'latitude' => 51.5074, + 'longitude' => -0.1278, + 'accuracy' => 10.0 + ]; + $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location); + + // Then get the active live locations + $response = $this->client->getUserActiveLiveLocations($this->user['id']); + + $this->assertNotNull($response); + $this->assertArrayHasKey('live_locations', $response); + $this->assertIsArray($response['live_locations']); + } + + public function testUpdateUserActiveLiveLocationMultipleTimes() + { + $location1 = [ + 'latitude' => 48.8566, + 'longitude' => 2.3522, + 'accuracy' => 5.0 + ]; + + $location2 = [ + 'latitude' => 48.8566, + 'longitude' => 2.3522, + 'accuracy' => 3.0, + 'speed' => 15.5 + ]; + + // Update location twice + $response1 = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location1); + $response2 = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location2); + + $this->assertNotNull($response1); + $this->assertNotNull($response2); + $this->assertTrue(true); // If we got here, the test passed + } +} \ No newline at end of file From 65628e1f9ec53d29e2a0b8f739fc57b0dc12ff09 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Mon, 7 Jul 2025 09:59:06 +0200 Subject: [PATCH 04/12] tests(cha-650) fix unit test --- tests/integration/SharedLocationsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/SharedLocationsTest.php b/tests/integration/SharedLocationsTest.php index 0d856fc..53a9b6c 100644 --- a/tests/integration/SharedLocationsTest.php +++ b/tests/integration/SharedLocationsTest.php @@ -164,4 +164,4 @@ public function testUpdateUserActiveLiveLocationMultipleTimes() $this->assertNotNull($response2); $this->assertTrue(true); // If we got here, the test passed } -} \ No newline at end of file +} From 3280545ff215b694deec64390e72c2482829dede Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 08:54:23 +0200 Subject: [PATCH 05/12] fix tests --- tests/integration/IntegrationTest.php | 127 ++++++++++++++++ tests/integration/SharedLocationsTest.php | 167 ---------------------- 2 files changed, 127 insertions(+), 167 deletions(-) delete mode 100644 tests/integration/SharedLocationsTest.php diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 5301576..2a2bb80 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1774,4 +1774,131 @@ public function testQueryDrafts() // ignore } } + + public function testCreateSharedLocation() + { + // Enable shared locations for the channel + $this->channel->updatePartial([ + "config_overrides" => ["shared_locations" => true], + ]); + + // Create a shared location message + $sharedLocation = [ + 'latitude' => 40.7128, + 'longitude' => -74.0060, + 'created_by_device_id' => 'test-device-123', + 'end_at' => time() + 3600 // 1 hour from now + ]; + + $message = [ + 'text' => 'Sharing my location', + 'shared_location' => $sharedLocation + ]; + + $response = $this->channel->sendMessage($message, $this->user1['id']); + + $this->assertTrue(array_key_exists("message", (array)$response)); + $this->assertTrue(array_key_exists("shared_location", $response["message"])); + $this->assertEquals(40.7128, $response["message"]["shared_location"]["latitude"]); + $this->assertEquals(-74.0060, $response["message"]["shared_location"]["longitude"]); + $this->assertEquals('test-device-123', $response["message"]["shared_location"]["created_by_device_id"]); + $this->assertTrue(array_key_exists("end_at", $response["message"]["shared_location"])); + } + + public function testUpdateSharedLocation() + { + // Enable shared locations for the channel + $this->channel->updatePartial([ + "config_overrides" => ["shared_locations" => true], + ]); + + // First create a shared location message + $initialLocation = [ + 'latitude' => 40.7128, + 'longitude' => -74.0060, + 'created_by_device_id' => 'test-device-123', + 'end_at' => time() + 3600 + ]; + + $message = [ + 'text' => 'Initial location', + 'shared_location' => $initialLocation + ]; + + $response = $this->channel->sendMessage($message, $this->user1['id']); + $messageId = $response["message"]["id"]; + + // Update the shared location using updateUserActiveLiveLocation + $updatedLocation = [ + 'latitude' => 34.0522, + 'longitude' => -118.2437 + ]; + + $updateResponse = $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $updatedLocation); + + $this->assertNotNull($updateResponse); + $this->assertTrue(true); // If we got here, the test passed + } + + public function testGetUserActiveLiveLocations() + { + $response = $this->client->getUserActiveLiveLocations($this->user1['id']); + + $this->assertTrue(array_key_exists("live_locations", (array)$response)); + $this->assertIsArray($response["live_locations"]); + } + + public function testUpdateUserActiveLiveLocation() + { + // First send a message to get a message ID + $message = $this->channel->sendMessage(["text" => "Test message for live location"], $this->user1['id']); + $messageId = $message["message"]["id"]; + + $location = [ + 'latitude' => 40.7128, + 'longitude' => -74.0060, + ]; + + $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $location); + + $this->assertNotNull($response); + $this->assertTrue(true); // If we got here, the test passed + } + + public function testUpdateUserActiveLiveLocationWithMinimalData() + { + // First send a message to get a message ID + $message = $this->channel->sendMessage(["text" => "Test message for minimal live location"], $this->user1['id']); + $messageId = $message["message"]["id"]; + + $location = [ + 'latitude' => 34.0522, + 'longitude' => -118.2437 + ]; + + $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $location); + + $this->assertNotNull($response); + $this->assertTrue(true); // If we got here, the test passed + } + + public function testGetUserActiveLiveLocationsAfterUpdate() + { + // First send a message to get a message ID + $message = $this->channel->sendMessage(["text" => "Test message for live location after update"], $this->user1['id']); + $messageId = $message["message"]["id"]; + + // Update a location + $location = [ + 'latitude' => 51.5074, + 'longitude' => -0.1278, + ]; + $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $location); + + // Then get the active live locations + $response = $this->client->getUserActiveLiveLocations($this->user1['id']); + + $this->assertTrue(array_key_exists("live_locations", (array)$response)); + $this->assertIsArray($response["live_locations"]); + } } diff --git a/tests/integration/SharedLocationsTest.php b/tests/integration/SharedLocationsTest.php deleted file mode 100644 index 53a9b6c..0000000 --- a/tests/integration/SharedLocationsTest.php +++ /dev/null @@ -1,167 +0,0 @@ -client = new Client(getenv('STREAM_KEY'), getenv('STREAM_SECRET')); - $this->user = $this->getUser(); - $this->channel = $this->getChannel(); - $this->channel->updatePartial([ - "config_overrides" => ["shared_locations" => true], - ]); - - // Create a message to use for shared locations - $message = [ - 'text' => 'This is a test message for shared locations' - ]; - $response = $this->channel->sendMessage($message, $this->user['id']); - $this->messageId = $response['message']['id']; - } - - protected function tearDown(): void - { - try { - $this->channel->delete(); - $this->client->deleteUser($this->user['id'], ["user" => "hard", "messages" => "hard"]); - } catch (\Exception $e) { - // We don't care about cleanup errors - } - } - - private function getUser(): array - { - $userId = 'shared-locations-test-user-' . uniqid(); - $user = [ - 'id' => $userId, - 'name' => 'Shared Locations Test User', - ]; - $this->client->upsertUser($user); - return $user; - } - - public function getChannel(): \GetStream\StreamChat\Channel - { - $channelId = 'shared-locations-test-channel-' . uniqid(); - $channel = $this->client->Channel('messaging', $channelId); - $channel->create($this->user['id']); - return $channel; - } - - public function testGetUserActiveLiveLocations() - { - $response = $this->client->getUserActiveLiveLocations($this->user['id']); - - // The response should be a StreamResponse object - $this->assertNotNull($response); - // Initially, user should have no active live locations - $this->assertArrayHasKey('live_locations', $response); - $this->assertIsArray($response['live_locations']); - } - - public function testUpdateUserActiveLiveLocation() - { - $location = [ - 'latitude' => 40.7128, - 'longitude' => -74.0060, - 'altitude' => 10.5, - 'accuracy' => 5.0, - 'speed' => 0.0, - 'heading' => 0.0, - 'timestamp' => time() - ]; - - $response = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location); - - $this->assertNotNull($response); - $this->assertTrue(true); // If we got here, the test passed - } - - public function testUpdateUserActiveLiveLocationWithMinimalData() - { - $location = [ - 'latitude' => 34.0522, - 'longitude' => -118.2437 - ]; - - $response = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location); - - $this->assertNotNull($response); - $this->assertTrue(true); // If we got here, the test passed - } - - public function testGetUserActiveLiveLocationsAfterUpdate() - { - // First update a location - $location = [ - 'latitude' => 51.5074, - 'longitude' => -0.1278, - 'accuracy' => 10.0 - ]; - $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location); - - // Then get the active live locations - $response = $this->client->getUserActiveLiveLocations($this->user['id']); - - $this->assertNotNull($response); - $this->assertArrayHasKey('live_locations', $response); - $this->assertIsArray($response['live_locations']); - } - - public function testUpdateUserActiveLiveLocationMultipleTimes() - { - $location1 = [ - 'latitude' => 48.8566, - 'longitude' => 2.3522, - 'accuracy' => 5.0 - ]; - - $location2 = [ - 'latitude' => 48.8566, - 'longitude' => 2.3522, - 'accuracy' => 3.0, - 'speed' => 15.5 - ]; - - // Update location twice - $response1 = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location1); - $response2 = $this->client->updateUserActiveLiveLocation($this->user['id'], $this->messageId, $location2); - - $this->assertNotNull($response1); - $this->assertNotNull($response2); - $this->assertTrue(true); // If we got here, the test passed - } -} From f8f47605669dcb5781f4ef8ad3aa440bb116dd2b Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 09:01:07 +0200 Subject: [PATCH 06/12] fix tests --- tests/integration/IntegrationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 2a2bb80..9e3036c 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1787,7 +1787,7 @@ public function testCreateSharedLocation() 'latitude' => 40.7128, 'longitude' => -74.0060, 'created_by_device_id' => 'test-device-123', - 'end_at' => time() + 3600 // 1 hour from now + 'end_at' => new DateTime('+1 hour') // 1 hour from now ]; $message = [ @@ -1817,7 +1817,7 @@ public function testUpdateSharedLocation() 'latitude' => 40.7128, 'longitude' => -74.0060, 'created_by_device_id' => 'test-device-123', - 'end_at' => time() + 3600 + 'end_at' => new DateTime('+1 hour') ]; $message = [ From afac690b2384b6aaa45ef420b2dce9f7b381f2e8 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 09:04:36 +0200 Subject: [PATCH 07/12] fix test --- tests/integration/IntegrationTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 9e3036c..72dc398 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1782,12 +1782,13 @@ public function testCreateSharedLocation() "config_overrides" => ["shared_locations" => true], ]); + $endAt = new \DateTime('+1 hour'); // Create a shared location message $sharedLocation = [ 'latitude' => 40.7128, 'longitude' => -74.0060, 'created_by_device_id' => 'test-device-123', - 'end_at' => new DateTime('+1 hour') // 1 hour from now + 'end_at' => $endAt->format('Y-m-d\TH:i:s.u\Z') ]; $message = [ @@ -1812,12 +1813,13 @@ public function testUpdateSharedLocation() "config_overrides" => ["shared_locations" => true], ]); + $endAt = new \DateTime('+1 hour'); // First create a shared location message $initialLocation = [ 'latitude' => 40.7128, 'longitude' => -74.0060, 'created_by_device_id' => 'test-device-123', - 'end_at' => new DateTime('+1 hour') + 'end_at' => $endAt->format('Y-m-d\TH:i:s.u\Z') ]; $message = [ From 55722539356316530186219d964cee6cf9392639 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 09:14:11 +0200 Subject: [PATCH 08/12] refactor --- lib/GetStream/StreamChat/Client.php | 6 ++-- tests/integration/IntegrationTest.php | 43 ++++++++++++++++----------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lib/GetStream/StreamChat/Client.php b/lib/GetStream/StreamChat/Client.php index a3ad69d..5b46672 100644 --- a/lib/GetStream/StreamChat/Client.php +++ b/lib/GetStream/StreamChat/Client.php @@ -1743,9 +1743,9 @@ public function getUserActiveLiveLocations(string $userId): StreamResponse * Update a user active live location * @throws StreamException */ - public function updateUserActiveLiveLocation(string $userId, string $messageId, array $location): StreamResponse + public function updateUserActiveLiveLocation(string $userId, array $location): StreamResponse { - $params = ["user_id" => $userId, "message_id" => $messageId, "shared_location" => $location]; - return $this->post("users/live_locations", $params); + $params = ["user_id" => $userId]; + return $this->put("users/live_locations", $location, $params); } } diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 72dc398..529b92a 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1832,11 +1832,16 @@ public function testUpdateSharedLocation() // Update the shared location using updateUserActiveLiveLocation $updatedLocation = [ + 'message_id' => $messageId, + 'channel_cid' => $this->channel->getCID(), + 'user_id' => $this->user1['id'], 'latitude' => 34.0522, - 'longitude' => -118.2437 + 'longitude' => -118.2437, + 'created_by_device_id' => 'test-device-123', + 'end_at' => (new \DateTime('+2 hours'))->format('Y-m-d\TH:i:s.u\Z') ]; - $updateResponse = $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $updatedLocation); + $updateResponse = $this->client->updateUserActiveLiveLocation($this->user1['id'], $updatedLocation); $this->assertNotNull($updateResponse); $this->assertTrue(true); // If we got here, the test passed @@ -1852,16 +1857,17 @@ public function testGetUserActiveLiveLocations() public function testUpdateUserActiveLiveLocation() { - // First send a message to get a message ID - $message = $this->channel->sendMessage(["text" => "Test message for live location"], $this->user1['id']); - $messageId = $message["message"]["id"]; - $location = [ + 'message_id' => $this->generateGuid(), + 'channel_cid' => $this->channel->getCID(), + 'user_id' => $this->user1['id'], 'latitude' => 40.7128, 'longitude' => -74.0060, + 'created_by_device_id' => 'test-device-123', + 'end_at' => (new \DateTime('+1 hour'))->format('Y-m-d\TH:i:s.u\Z') ]; - $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $location); + $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $location); $this->assertNotNull($response); $this->assertTrue(true); // If we got here, the test passed @@ -1869,16 +1875,16 @@ public function testUpdateUserActiveLiveLocation() public function testUpdateUserActiveLiveLocationWithMinimalData() { - // First send a message to get a message ID - $message = $this->channel->sendMessage(["text" => "Test message for minimal live location"], $this->user1['id']); - $messageId = $message["message"]["id"]; - $location = [ + 'message_id' => $this->generateGuid(), + 'channel_cid' => $this->channel->getCID(), + 'user_id' => $this->user1['id'], 'latitude' => 34.0522, - 'longitude' => -118.2437 + 'longitude' => -118.2437, + 'created_by_device_id' => 'test-device-123' ]; - $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $location); + $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $location); $this->assertNotNull($response); $this->assertTrue(true); // If we got here, the test passed @@ -1886,16 +1892,17 @@ public function testUpdateUserActiveLiveLocationWithMinimalData() public function testGetUserActiveLiveLocationsAfterUpdate() { - // First send a message to get a message ID - $message = $this->channel->sendMessage(["text" => "Test message for live location after update"], $this->user1['id']); - $messageId = $message["message"]["id"]; - // Update a location $location = [ + 'message_id' => $this->generateGuid(), + 'channel_cid' => $this->channel->getCID(), + 'user_id' => $this->user1['id'], 'latitude' => 51.5074, 'longitude' => -0.1278, + 'created_by_device_id' => 'test-device-123', + 'end_at' => (new \DateTime('+1 hour'))->format('Y-m-d\TH:i:s.u\Z') ]; - $this->client->updateUserActiveLiveLocation($this->user1['id'], $messageId, $location); + $this->client->updateUserActiveLiveLocation($this->user1['id'], $location); // Then get the active live locations $response = $this->client->getUserActiveLiveLocations($this->user1['id']); From 910ef5d119e6c2fc1f9e009e2134ad9b5bbb324c Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 09:22:03 +0200 Subject: [PATCH 09/12] fix tests --- tests/integration/IntegrationTest.php | 111 ++++---------------------- 1 file changed, 14 insertions(+), 97 deletions(-) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 529b92a..ba664bb 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1775,7 +1775,7 @@ public function testQueryDrafts() } } - public function testCreateSharedLocation() + public function testSharedLocations() { // Enable shared locations for the channel $this->channel->updatePartial([ @@ -1792,7 +1792,6 @@ public function testCreateSharedLocation() ]; $message = [ - 'text' => 'Sharing my location', 'shared_location' => $sharedLocation ]; @@ -1804,110 +1803,28 @@ public function testCreateSharedLocation() $this->assertEquals(-74.0060, $response["message"]["shared_location"]["longitude"]); $this->assertEquals('test-device-123', $response["message"]["shared_location"]["created_by_device_id"]); $this->assertTrue(array_key_exists("end_at", $response["message"]["shared_location"])); - } - - public function testUpdateSharedLocation() - { - // Enable shared locations for the channel - $this->channel->updatePartial([ - "config_overrides" => ["shared_locations" => true], - ]); - $endAt = new \DateTime('+1 hour'); - // First create a shared location message - $initialLocation = [ - 'latitude' => 40.7128, - 'longitude' => -74.0060, - 'created_by_device_id' => 'test-device-123', - 'end_at' => $endAt->format('Y-m-d\TH:i:s.u\Z') - ]; - - $message = [ - 'text' => 'Initial location', - 'shared_location' => $initialLocation - ]; - - $response = $this->channel->sendMessage($message, $this->user1['id']); - $messageId = $response["message"]["id"]; + $userLocations = $this->client->getUserActiveLiveLocations($this->user1['id']); + + $this->assertTrue(array_key_exists("active_live_locations", (array)$userLocations)); + $this->assertIsArray($userLocations["active_live_locations"]); + $this->assertEquals($message["message"]["id"], $userLocations["active_live_locations"][0]["message_id"]); - // Update the shared location using updateUserActiveLiveLocation - $updatedLocation = [ - 'message_id' => $messageId, - 'channel_cid' => $this->channel->getCID(), - 'user_id' => $this->user1['id'], + $newLocation = [ 'latitude' => 34.0522, 'longitude' => -118.2437, 'created_by_device_id' => 'test-device-123', 'end_at' => (new \DateTime('+2 hours'))->format('Y-m-d\TH:i:s.u\Z') ]; - $updateResponse = $this->client->updateUserActiveLiveLocation($this->user1['id'], $updatedLocation); - - $this->assertNotNull($updateResponse); - $this->assertTrue(true); // If we got here, the test passed - } - - public function testGetUserActiveLiveLocations() - { - $response = $this->client->getUserActiveLiveLocations($this->user1['id']); - - $this->assertTrue(array_key_exists("live_locations", (array)$response)); - $this->assertIsArray($response["live_locations"]); - } - - public function testUpdateUserActiveLiveLocation() - { - $location = [ - 'message_id' => $this->generateGuid(), - 'channel_cid' => $this->channel->getCID(), - 'user_id' => $this->user1['id'], - 'latitude' => 40.7128, - 'longitude' => -74.0060, - 'created_by_device_id' => 'test-device-123', - 'end_at' => (new \DateTime('+1 hour'))->format('Y-m-d\TH:i:s.u\Z') - ]; - - $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $location); - - $this->assertNotNull($response); - $this->assertTrue(true); // If we got here, the test passed - } + $this->client->updateUserActiveLiveLocation($this->user1['id'], $newLocation); - public function testUpdateUserActiveLiveLocationWithMinimalData() - { - $location = [ - 'message_id' => $this->generateGuid(), - 'channel_cid' => $this->channel->getCID(), - 'user_id' => $this->user1['id'], - 'latitude' => 34.0522, - 'longitude' => -118.2437, - 'created_by_device_id' => 'test-device-123' - ]; - - $response = $this->client->updateUserActiveLiveLocation($this->user1['id'], $location); - - $this->assertNotNull($response); - $this->assertTrue(true); // If we got here, the test passed - } - - public function testGetUserActiveLiveLocationsAfterUpdate() - { - // Update a location - $location = [ - 'message_id' => $this->generateGuid(), - 'channel_cid' => $this->channel->getCID(), - 'user_id' => $this->user1['id'], - 'latitude' => 51.5074, - 'longitude' => -0.1278, - 'created_by_device_id' => 'test-device-123', - 'end_at' => (new \DateTime('+1 hour'))->format('Y-m-d\TH:i:s.u\Z') - ]; - $this->client->updateUserActiveLiveLocation($this->user1['id'], $location); - - // Then get the active live locations - $response = $this->client->getUserActiveLiveLocations($this->user1['id']); + $newUserLocations = $this->client->getUserActiveLiveLocations($this->user1['id']); - $this->assertTrue(array_key_exists("live_locations", (array)$response)); - $this->assertIsArray($response["live_locations"]); + $this->assertTrue(array_key_exists("active_live_locations", (array)$newUserLocations)); + $this->assertIsArray($newUserLocations["active_live_locations"]); + $this->assertEquals(34.0522, $newUserLocations["active_live_locations"][0]["latitude"]); + $this->assertEquals(-118.2437, $newUserLocations["active_live_locations"][0]["longitude"]); + $this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]); } } From 37b01d66146b979aa95a9e3dad718e91d7f1b7d2 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 09:29:06 +0200 Subject: [PATCH 10/12] lint --- tests/integration/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index ba664bb..33e790a 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1825,6 +1825,6 @@ public function testSharedLocations() $this->assertIsArray($newUserLocations["active_live_locations"]); $this->assertEquals(34.0522, $newUserLocations["active_live_locations"][0]["latitude"]); $this->assertEquals(-118.2437, $newUserLocations["active_live_locations"][0]["longitude"]); - $this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]); + $this->assertEquals('test-device-123', $newUserLocations["active_live_locations"][0]["created_by_device_id"]); } } From b341e680ab2369254c025fc46c69bded3f583836 Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 09:33:13 +0200 Subject: [PATCH 11/12] fix test --- tests/integration/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 33e790a..44209b3 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1808,7 +1808,7 @@ public function testSharedLocations() $this->assertTrue(array_key_exists("active_live_locations", (array)$userLocations)); $this->assertIsArray($userLocations["active_live_locations"]); - $this->assertEquals($message["message"]["id"], $userLocations["active_live_locations"][0]["message_id"]); + $this->assertEquals($response["message"]["id"], $userLocations["active_live_locations"][0]["message_id"]); $newLocation = [ 'latitude' => 34.0522, From 55870c1f9eea13c4a69aa4bb9565b9ca7ed1794e Mon Sep 17 00:00:00 2001 From: Rafael Marinho Date: Tue, 8 Jul 2025 09:35:41 +0200 Subject: [PATCH 12/12] fix test --- tests/integration/IntegrationTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 44209b3..34f4b61 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -1811,6 +1811,7 @@ public function testSharedLocations() $this->assertEquals($response["message"]["id"], $userLocations["active_live_locations"][0]["message_id"]); $newLocation = [ + 'message_id' => $response["message"]["id"], 'latitude' => 34.0522, 'longitude' => -118.2437, 'created_by_device_id' => 'test-device-123',