@@ -1774,4 +1774,131 @@ public function testQueryDrafts()
17741774 // ignore
17751775 }
17761776 }
1777+
1778+ public function testCreateSharedLocation ()
1779+ {
1780+ // Enable shared locations for the channel
1781+ $ this ->channel ->updatePartial ([
1782+ "config_overrides " => ["shared_locations " => true ],
1783+ ]);
1784+
1785+ // Create a shared location message
1786+ $ sharedLocation = [
1787+ 'latitude ' => 40.7128 ,
1788+ 'longitude ' => -74.0060 ,
1789+ 'created_by_device_id ' => 'test-device-123 ' ,
1790+ 'end_at ' => time () + 3600 // 1 hour from now
1791+ ];
1792+
1793+ $ message = [
1794+ 'text ' => 'Sharing my location ' ,
1795+ 'shared_location ' => $ sharedLocation
1796+ ];
1797+
1798+ $ response = $ this ->channel ->sendMessage ($ message , $ this ->user1 ['id ' ]);
1799+
1800+ $ this ->assertTrue (array_key_exists ("message " , (array )$ response ));
1801+ $ this ->assertTrue (array_key_exists ("shared_location " , $ response ["message " ]));
1802+ $ this ->assertEquals (40.7128 , $ response ["message " ]["shared_location " ]["latitude " ]);
1803+ $ this ->assertEquals (-74.0060 , $ response ["message " ]["shared_location " ]["longitude " ]);
1804+ $ this ->assertEquals ('test-device-123 ' , $ response ["message " ]["shared_location " ]["created_by_device_id " ]);
1805+ $ this ->assertTrue (array_key_exists ("end_at " , $ response ["message " ]["shared_location " ]));
1806+ }
1807+
1808+ public function testUpdateSharedLocation ()
1809+ {
1810+ // Enable shared locations for the channel
1811+ $ this ->channel ->updatePartial ([
1812+ "config_overrides " => ["shared_locations " => true ],
1813+ ]);
1814+
1815+ // First create a shared location message
1816+ $ initialLocation = [
1817+ 'latitude ' => 40.7128 ,
1818+ 'longitude ' => -74.0060 ,
1819+ 'created_by_device_id ' => 'test-device-123 ' ,
1820+ 'end_at ' => time () + 3600
1821+ ];
1822+
1823+ $ message = [
1824+ 'text ' => 'Initial location ' ,
1825+ 'shared_location ' => $ initialLocation
1826+ ];
1827+
1828+ $ response = $ this ->channel ->sendMessage ($ message , $ this ->user1 ['id ' ]);
1829+ $ messageId = $ response ["message " ]["id " ];
1830+
1831+ // Update the shared location using updateUserActiveLiveLocation
1832+ $ updatedLocation = [
1833+ 'latitude ' => 34.0522 ,
1834+ 'longitude ' => -118.2437
1835+ ];
1836+
1837+ $ updateResponse = $ this ->client ->updateUserActiveLiveLocation ($ this ->user1 ['id ' ], $ messageId , $ updatedLocation );
1838+
1839+ $ this ->assertNotNull ($ updateResponse );
1840+ $ this ->assertTrue (true ); // If we got here, the test passed
1841+ }
1842+
1843+ public function testGetUserActiveLiveLocations ()
1844+ {
1845+ $ response = $ this ->client ->getUserActiveLiveLocations ($ this ->user1 ['id ' ]);
1846+
1847+ $ this ->assertTrue (array_key_exists ("live_locations " , (array )$ response ));
1848+ $ this ->assertIsArray ($ response ["live_locations " ]);
1849+ }
1850+
1851+ public function testUpdateUserActiveLiveLocation ()
1852+ {
1853+ // First send a message to get a message ID
1854+ $ message = $ this ->channel ->sendMessage (["text " => "Test message for live location " ], $ this ->user1 ['id ' ]);
1855+ $ messageId = $ message ["message " ]["id " ];
1856+
1857+ $ location = [
1858+ 'latitude ' => 40.7128 ,
1859+ 'longitude ' => -74.0060 ,
1860+ ];
1861+
1862+ $ response = $ this ->client ->updateUserActiveLiveLocation ($ this ->user1 ['id ' ], $ messageId , $ location );
1863+
1864+ $ this ->assertNotNull ($ response );
1865+ $ this ->assertTrue (true ); // If we got here, the test passed
1866+ }
1867+
1868+ public function testUpdateUserActiveLiveLocationWithMinimalData ()
1869+ {
1870+ // First send a message to get a message ID
1871+ $ message = $ this ->channel ->sendMessage (["text " => "Test message for minimal live location " ], $ this ->user1 ['id ' ]);
1872+ $ messageId = $ message ["message " ]["id " ];
1873+
1874+ $ location = [
1875+ 'latitude ' => 34.0522 ,
1876+ 'longitude ' => -118.2437
1877+ ];
1878+
1879+ $ response = $ this ->client ->updateUserActiveLiveLocation ($ this ->user1 ['id ' ], $ messageId , $ location );
1880+
1881+ $ this ->assertNotNull ($ response );
1882+ $ this ->assertTrue (true ); // If we got here, the test passed
1883+ }
1884+
1885+ public function testGetUserActiveLiveLocationsAfterUpdate ()
1886+ {
1887+ // First send a message to get a message ID
1888+ $ message = $ this ->channel ->sendMessage (["text " => "Test message for live location after update " ], $ this ->user1 ['id ' ]);
1889+ $ messageId = $ message ["message " ]["id " ];
1890+
1891+ // Update a location
1892+ $ location = [
1893+ 'latitude ' => 51.5074 ,
1894+ 'longitude ' => -0.1278 ,
1895+ ];
1896+ $ this ->client ->updateUserActiveLiveLocation ($ this ->user1 ['id ' ], $ messageId , $ location );
1897+
1898+ // Then get the active live locations
1899+ $ response = $ this ->client ->getUserActiveLiveLocations ($ this ->user1 ['id ' ]);
1900+
1901+ $ this ->assertTrue (array_key_exists ("live_locations " , (array )$ response ));
1902+ $ this ->assertIsArray ($ response ["live_locations " ]);
1903+ }
17771904}
0 commit comments