@@ -825,7 +825,9 @@ def loop_times(times)
825825 list_resp = @client . list_imports ( { limit : 1 } )
826826 expect ( list_resp [ 'import_tasks' ] . length ) . to eq 1
827827 end
828+ end
828829
830+ describe 'drafts' do
829831 it 'can query drafts' do
830832 # Create multiple drafts in different channels
831833 draft1 = { 'text' => 'Draft in channel 1' }
@@ -1020,4 +1022,86 @@ def loop_times(times)
10201022 expect ( response [ 'threads' ] . length ) . to be >= 1
10211023 end
10221024 end
1025+
1026+ describe 'live locations' do
1027+ before ( :all ) do
1028+ @location_test_user = { id : SecureRandom . uuid }
1029+ @client . upsert_users ( [ @location_test_user ] )
1030+ @location_channel = @client . channel ( 'messaging' , channel_id : SecureRandom . uuid )
1031+ @location_channel . create ( @location_test_user [ :id ] )
1032+ @location_message = @location_channel . send_message ( { text : 'Location sharing message' } , @location_test_user [ :id ] )
1033+ end
1034+
1035+ after ( :all ) do
1036+ @location_channel . delete
1037+ @client . delete_user ( @location_test_user [ :id ] )
1038+ end
1039+
1040+ it 'can create and update a location' do
1041+ location = {
1042+ created_by_device_id : SecureRandom . uuid ,
1043+ latitude : 40.7128 ,
1044+ longitude : -74.0060 ,
1045+ end_at : ( Time . now + 3600 ) . iso8601
1046+ }
1047+
1048+ response = @channel . send_message ( {
1049+ text : 'Location sharing message' ,
1050+ shared_location : location ,
1051+ } , @location_test_user [ :id ] )
1052+
1053+ expect ( response [ 'message' ] ) . to include 'shared_location'
1054+ expect ( response [ 'message' ] [ 'shared_location' ] [ 'created_by_device_id' ] ) . to eq ( location [ :created_by_device_id ] )
1055+ expect ( response [ 'message' ] [ 'shared_location' ] [ 'latitude' ] ) . to eq ( location [ :latitude ] )
1056+ expect ( response [ 'message' ] [ 'shared_location' ] [ 'longitude' ] ) . to eq ( location [ :longitude ] )
1057+
1058+ new_latitude = location [ :latitude ] + 10
1059+ response = @client . update_location (
1060+ response [ 'message' ] [ 'user' ] [ 'id' ] ,
1061+ created_by_device_id : location [ :created_by_device_id ] ,
1062+ message_id : response [ 'message' ] [ 'id' ] ,
1063+ latitude : new_latitude ,
1064+ longitude : location [ :longitude ] ,
1065+ end_at : location [ :end_at ] ,
1066+ )
1067+
1068+ expect ( response [ 'created_by_device_id' ] ) . to eq ( location [ :created_by_device_id ] )
1069+ expect ( response [ 'latitude' ] ) . to eq ( new_latitude )
1070+ expect ( response [ 'longitude' ] ) . to eq ( location [ :longitude ] )
1071+ end
1072+
1073+ it 'can get active live locations' do
1074+ device_id = SecureRandom . uuid
1075+ latitude = 40.7128
1076+ longitude = -74.0060
1077+ end_at = ( Time . now + 3600 ) . iso8601
1078+
1079+ response = @location_channel . send_message ( {
1080+ text : 'Location sharing message' ,
1081+ shared_location : {
1082+ created_by_device_id : device_id ,
1083+ latitude : latitude ,
1084+ longitude : longitude ,
1085+ end_at : end_at
1086+ }
1087+ } , @location_test_user [ :id ] )
1088+
1089+ response = @client . get_active_live_locations ( @location_test_user [ :id ] )
1090+ expect ( response ) . to include 'active_live_locations'
1091+ expect ( response [ 'active_live_locations' ] ) . to be_an ( Array )
1092+ expect ( response [ 'active_live_locations' ] . length ) . to be >= 1
1093+
1094+ location = response [ 'active_live_locations' ] . find { |loc | loc [ 'created_by_device_id' ] == device_id }
1095+ expect ( location ) . not_to be_nil
1096+ expect ( location [ 'latitude' ] ) . to eq ( latitude )
1097+ expect ( location [ 'longitude' ] ) . to eq ( longitude )
1098+ expect ( DateTime . parse ( location [ 'end_at' ] ) . iso8601 ) . to eq ( end_at )
1099+ end
1100+
1101+ it 'should have active live locations on the channel' do
1102+ response = @channel . query ( )
1103+ expect ( response ) . to include 'active_live_locations'
1104+ expect ( response [ 'active_live_locations' ] . length ) . to be >= 1
1105+ end
1106+ end
10231107end
0 commit comments