@@ -928,7 +928,9 @@ def loop_times(times)
928
928
list_resp = @client . list_imports ( { limit : 1 } )
929
929
expect ( list_resp [ 'import_tasks' ] . length ) . to eq 1
930
930
end
931
+ end
931
932
933
+ describe 'drafts' do
932
934
it 'can query drafts' do
933
935
# Create multiple drafts in different channels
934
936
draft1 = { 'text' => 'Draft in channel 1' }
@@ -1215,4 +1217,90 @@ def loop_times(times)
1215
1217
end
1216
1218
end
1217
1219
end
1220
+
1221
+ describe 'live locations' do
1222
+ before ( :all ) do
1223
+ @location_test_user = { id : SecureRandom . uuid }
1224
+ @client . upsert_users ( [ @location_test_user ] )
1225
+ @location_channel = @client . channel ( 'messaging' , channel_id : SecureRandom . uuid )
1226
+ @location_channel . create ( @location_test_user [ :id ] )
1227
+ @location_channel . update_partial ( { config_overrides : { shared_locations : true } } )
1228
+ @location_message = @location_channel . send_message ( { text : 'Location sharing message' } , @location_test_user [ :id ] )
1229
+ end
1230
+
1231
+ after ( :all ) do
1232
+ @location_channel . delete
1233
+ @client . delete_user ( @location_test_user [ :id ] )
1234
+ end
1235
+
1236
+ it 'can create and update a location' do
1237
+ location = {
1238
+ created_by_device_id : SecureRandom . uuid ,
1239
+ latitude : 40.7128 ,
1240
+ longitude : -74.0060 ,
1241
+ end_at : ( Time . now + 3600 ) . iso8601
1242
+ }
1243
+
1244
+ response = @location_channel . send_message (
1245
+ {
1246
+ text : 'Location sharing message' ,
1247
+ shared_location : location
1248
+ } , @location_test_user [ :id ]
1249
+ )
1250
+
1251
+ expect ( response [ 'message' ] ) . to include 'shared_location'
1252
+ expect ( response [ 'message' ] [ 'shared_location' ] [ 'created_by_device_id' ] ) . to eq ( location [ :created_by_device_id ] )
1253
+ expect ( response [ 'message' ] [ 'shared_location' ] [ 'latitude' ] ) . to eq ( location [ :latitude ] )
1254
+ expect ( response [ 'message' ] [ 'shared_location' ] [ 'longitude' ] ) . to eq ( location [ :longitude ] )
1255
+
1256
+ new_latitude = location [ :latitude ] + 10
1257
+ response = @client . update_location (
1258
+ response [ 'message' ] [ 'user' ] [ 'id' ] ,
1259
+ created_by_device_id : location [ :created_by_device_id ] ,
1260
+ message_id : response [ 'message' ] [ 'id' ] ,
1261
+ latitude : new_latitude ,
1262
+ longitude : location [ :longitude ] ,
1263
+ end_at : location [ :end_at ]
1264
+ )
1265
+
1266
+ expect ( response [ 'created_by_device_id' ] ) . to eq ( location [ :created_by_device_id ] )
1267
+ expect ( response [ 'latitude' ] ) . to eq ( new_latitude )
1268
+ expect ( response [ 'longitude' ] ) . to eq ( location [ :longitude ] )
1269
+ end
1270
+
1271
+ it 'can get active live locations' do
1272
+ device_id = SecureRandom . uuid
1273
+ latitude = 40.7128
1274
+ longitude = -74.0060
1275
+ end_at = ( Time . now + 3600 ) . iso8601
1276
+
1277
+ @location_channel . send_message (
1278
+ {
1279
+ text : 'Location sharing message' ,
1280
+ shared_location : {
1281
+ created_by_device_id : device_id ,
1282
+ latitude : latitude ,
1283
+ longitude : longitude ,
1284
+ end_at : end_at
1285
+ }
1286
+ } , @location_test_user [ :id ]
1287
+ )
1288
+
1289
+ response = @client . get_active_live_locations ( @location_test_user [ :id ] )
1290
+ expect ( response ) . to include 'active_live_locations'
1291
+ expect ( response [ 'active_live_locations' ] ) . to be_an ( Array )
1292
+ expect ( response [ 'active_live_locations' ] . length ) . to be >= 1
1293
+ location = response [ 'active_live_locations' ] . find { |loc | loc [ 'created_by_device_id' ] == device_id }
1294
+ expect ( location ) . not_to be_nil
1295
+ expect ( location [ 'latitude' ] ) . to eq ( latitude )
1296
+ expect ( location [ 'longitude' ] ) . to eq ( longitude )
1297
+ expect ( DateTime . parse ( location [ 'end_at' ] ) . iso8601 ) . to eq ( end_at )
1298
+ end
1299
+
1300
+ it 'should have active live locations on the channel' do
1301
+ response = @location_channel . query
1302
+ expect ( response ) . to include 'active_live_locations'
1303
+ expect ( response [ 'active_live_locations' ] . length ) . to be >= 1
1304
+ end
1305
+ end
1218
1306
end
0 commit comments