That fuck shit the fascists are using
at master 994 lines 32 kB view raw
1package org.tm.archive.database 2 3import androidx.test.ext.junit.runners.AndroidJUnit4 4import org.junit.Assert.assertEquals 5import org.junit.Assert.assertNotEquals 6import org.junit.Assert.assertNotNull 7import org.junit.Assert.assertNull 8import org.junit.Rule 9import org.junit.Test 10import org.junit.runner.RunWith 11import org.signal.ringrtc.CallId 12import org.signal.ringrtc.CallManager 13import org.tm.archive.calls.log.CallLogFilter 14import org.tm.archive.recipients.RecipientId 15import org.tm.archive.testing.SignalActivityRule 16 17@RunWith(AndroidJUnit4::class) 18class CallTableTest { 19 20 @get:Rule 21 val harness = SignalActivityRule(createGroup = true) 22 23 private val groupRecipientId: RecipientId 24 get() = harness.group!!.recipientId 25 26 @Test 27 fun givenACall_whenISetTimestamp_thenIExpectUpdatedTimestamp() { 28 val callId = 1L 29 val now = System.currentTimeMillis() 30 SignalDatabase.calls.insertAcceptedGroupCall( 31 callId, 32 groupRecipientId, 33 CallTable.Direction.INCOMING, 34 now 35 ) 36 37 SignalDatabase.calls.setTimestamp(callId, groupRecipientId, -1L) 38 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 39 assertNotNull(call) 40 assertEquals(-1L, call?.timestamp) 41 42 val messageRecord = SignalDatabase.messages.getMessageRecord(call!!.messageId!!) 43 assertEquals(-1L, messageRecord.dateReceived) 44 assertEquals(-1L, messageRecord.dateSent) 45 } 46 47 @Test 48 fun givenPreExistingEvent_whenIDeleteGroupCall_thenIMarkDeletedAndSetTimestamp() { 49 val callId = 1L 50 val now = System.currentTimeMillis() 51 SignalDatabase.calls.insertAcceptedGroupCall( 52 callId, 53 groupRecipientId, 54 CallTable.Direction.INCOMING, 55 now 56 ) 57 58 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 59 SignalDatabase.calls.deleteGroupCall(call!!) 60 61 val deletedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 62 val oldestDeletionTimestamp = SignalDatabase.calls.getOldestDeletionTimestamp() 63 64 assertEquals(CallTable.Event.DELETE, deletedCall?.event) 65 assertNotEquals(0L, oldestDeletionTimestamp) 66 assertNull(deletedCall!!.messageId) 67 } 68 69 @Test 70 fun givenNoPreExistingEvent_whenIDeleteGroupCall_thenIInsertAndMarkCallDeleted() { 71 val callId = 1L 72 SignalDatabase.calls.insertDeletedGroupCallFromSyncEvent( 73 callId, 74 groupRecipientId, 75 CallTable.Direction.OUTGOING, 76 System.currentTimeMillis() 77 ) 78 79 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 80 assertNotNull(call) 81 82 val oldestDeletionTimestamp = SignalDatabase.calls.getOldestDeletionTimestamp() 83 84 assertEquals(CallTable.Event.DELETE, call?.event) 85 assertNotEquals(oldestDeletionTimestamp, 0) 86 assertNull(call?.messageId) 87 } 88 89 @Test 90 fun givenNoPriorEvent_whenIInsertAcceptedOutgoingGroupCall_thenIExpectLocalRingerAndOutgoingRing() { 91 val callId = 1L 92 SignalDatabase.calls.insertAcceptedGroupCall( 93 callId, 94 groupRecipientId, 95 CallTable.Direction.OUTGOING, 96 System.currentTimeMillis() 97 ) 98 99 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 100 assertNotNull(call) 101 assertEquals(CallTable.Event.OUTGOING_RING, call?.event) 102 assertEquals(harness.self.id, call?.ringerRecipient) 103 assertNotNull(call?.messageId) 104 } 105 106 @Test 107 fun givenNoPriorEvent_whenIInsertAcceptedIncomingGroupCall_thenIExpectJoined() { 108 val callId = 1L 109 SignalDatabase.calls.insertAcceptedGroupCall( 110 callId, 111 groupRecipientId, 112 CallTable.Direction.INCOMING, 113 System.currentTimeMillis() 114 ) 115 116 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 117 assertNotNull(call) 118 assertEquals(CallTable.Event.JOINED, call?.event) 119 assertNull(call?.ringerRecipient) 120 assertNotNull(call?.messageId) 121 } 122 123 @Test 124 fun givenARingingCall_whenIAcceptedIncomingGroupCall_thenIExpectAccepted() { 125 val callId = 1L 126 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 127 ringId = callId, 128 groupRecipientId = groupRecipientId, 129 ringerRecipient = harness.others[1], 130 dateReceived = System.currentTimeMillis(), 131 ringState = CallManager.RingUpdate.REQUESTED 132 ) 133 134 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 135 assertNotNull(call) 136 assertEquals(CallTable.Event.RINGING, call?.event) 137 138 SignalDatabase.calls.acceptIncomingGroupCall( 139 call!! 140 ) 141 142 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 143 assertEquals(CallTable.Event.ACCEPTED, acceptedCall?.event) 144 } 145 146 @Test 147 fun givenAMissedCall_whenIAcceptedIncomingGroupCall_thenIExpectAccepted() { 148 val callId = 1L 149 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 150 ringId = callId, 151 groupRecipientId = groupRecipientId, 152 ringerRecipient = harness.others[1], 153 dateReceived = System.currentTimeMillis(), 154 ringState = CallManager.RingUpdate.EXPIRED_REQUEST 155 ) 156 157 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 158 assertNotNull(call) 159 assertEquals(CallTable.Event.MISSED, call?.event) 160 161 SignalDatabase.calls.acceptIncomingGroupCall( 162 call!! 163 ) 164 165 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 166 assertEquals(CallTable.Event.ACCEPTED, acceptedCall?.event) 167 } 168 169 @Test 170 fun givenADeclinedCall_whenIAcceptedIncomingGroupCall_thenIExpectAccepted() { 171 val callId = 1L 172 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 173 ringId = callId, 174 groupRecipientId = groupRecipientId, 175 ringerRecipient = harness.others[1], 176 dateReceived = System.currentTimeMillis(), 177 ringState = CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE 178 ) 179 180 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 181 assertNotNull(call) 182 assertEquals(CallTable.Event.DECLINED, call?.event) 183 184 SignalDatabase.calls.acceptIncomingGroupCall( 185 call!! 186 ) 187 188 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 189 assertEquals(CallTable.Event.ACCEPTED, acceptedCall?.event) 190 } 191 192 @Test 193 fun givenAGenericGroupCall_whenIAcceptedIncomingGroupCall_thenIExpectAccepted() { 194 val era = "aaa" 195 val callId = CallId.fromEra(era).longValue() 196 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 197 groupRecipientId = groupRecipientId, 198 sender = harness.others[1], 199 timestamp = System.currentTimeMillis(), 200 peekGroupCallEraId = "aaa", 201 peekJoinedUuids = emptyList(), 202 isCallFull = false 203 ) 204 205 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 206 assertNotNull(call) 207 assertEquals(CallTable.Event.GENERIC_GROUP_CALL, call?.event) 208 209 SignalDatabase.calls.acceptIncomingGroupCall( 210 call!! 211 ) 212 213 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 214 assertEquals(CallTable.Event.JOINED, acceptedCall?.event) 215 } 216 217 @Test 218 fun givenAnOutgoingRingCall_whenIAcceptedOutgoingGroupCall_thenIExpectOutgoingRing() { 219 val callId = 1L 220 SignalDatabase.calls.insertAcceptedGroupCall( 221 callId = callId, 222 recipientId = groupRecipientId, 223 direction = CallTable.Direction.OUTGOING, 224 timestamp = 1 225 ) 226 227 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 228 assertNotNull(call) 229 assertEquals(CallTable.Event.OUTGOING_RING, call?.event) 230 231 SignalDatabase.calls.acceptOutgoingGroupCall( 232 call!! 233 ) 234 235 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 236 assertEquals(CallTable.Event.OUTGOING_RING, acceptedCall?.event) 237 } 238 239 @Test 240 fun givenARingingCall_whenIAcceptedOutgoingGroupCall_thenIExpectAccepted() { 241 val callId = 1L 242 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 243 ringId = callId, 244 groupRecipientId = groupRecipientId, 245 ringerRecipient = harness.others[1], 246 dateReceived = System.currentTimeMillis(), 247 ringState = CallManager.RingUpdate.REQUESTED 248 ) 249 250 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 251 assertNotNull(call) 252 assertEquals(CallTable.Event.RINGING, call?.event) 253 254 SignalDatabase.calls.acceptOutgoingGroupCall( 255 call!! 256 ) 257 258 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 259 assertEquals(CallTable.Event.ACCEPTED, acceptedCall?.event) 260 } 261 262 @Test 263 fun givenAMissedCall_whenIAcceptedOutgoingGroupCall_thenIExpectAccepted() { 264 val callId = 1L 265 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 266 ringId = callId, 267 groupRecipientId = groupRecipientId, 268 ringerRecipient = harness.others[1], 269 dateReceived = System.currentTimeMillis(), 270 ringState = CallManager.RingUpdate.EXPIRED_REQUEST 271 ) 272 273 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 274 assertNotNull(call) 275 assertEquals(CallTable.Event.MISSED, call?.event) 276 277 SignalDatabase.calls.acceptOutgoingGroupCall( 278 call!! 279 ) 280 281 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 282 assertEquals(CallTable.Event.ACCEPTED, acceptedCall?.event) 283 } 284 285 @Test 286 fun givenADeclinedCall_whenIAcceptedOutgoingGroupCall_thenIExpectAccepted() { 287 val callId = 1L 288 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 289 ringId = callId, 290 groupRecipientId = groupRecipientId, 291 ringerRecipient = harness.others[1], 292 dateReceived = System.currentTimeMillis(), 293 ringState = CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE 294 ) 295 296 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 297 assertNotNull(call) 298 assertEquals(CallTable.Event.DECLINED, call?.event) 299 300 SignalDatabase.calls.acceptOutgoingGroupCall( 301 call!! 302 ) 303 304 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 305 assertEquals(CallTable.Event.ACCEPTED, acceptedCall?.event) 306 } 307 308 @Test 309 fun givenAnAcceptedCall_whenIAcceptedOutgoingGroupCall_thenIExpectAccepted() { 310 val callId = 1L 311 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 312 ringId = callId, 313 groupRecipientId = groupRecipientId, 314 ringerRecipient = harness.others[1], 315 dateReceived = System.currentTimeMillis(), 316 ringState = CallManager.RingUpdate.REQUESTED 317 ) 318 319 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 320 assertNotNull(call) 321 assertEquals(CallTable.Event.RINGING, call?.event) 322 323 SignalDatabase.calls.acceptIncomingGroupCall( 324 call!! 325 ) 326 327 SignalDatabase.calls.acceptOutgoingGroupCall( 328 SignalDatabase.calls.getCallById(callId, groupRecipientId)!! 329 ) 330 331 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 332 assertEquals(CallTable.Event.ACCEPTED, acceptedCall?.event) 333 } 334 335 @Test 336 fun givenAGenericGroupCall_whenIAcceptedOutgoingGroupCall_thenIExpectOutgoingRing() { 337 val era = "aaa" 338 val callId = CallId.fromEra(era).longValue() 339 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 340 groupRecipientId = groupRecipientId, 341 sender = harness.others[1], 342 timestamp = System.currentTimeMillis(), 343 peekGroupCallEraId = "aaa", 344 peekJoinedUuids = emptyList(), 345 isCallFull = false 346 ) 347 348 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 349 assertNotNull(call) 350 assertEquals(CallTable.Event.GENERIC_GROUP_CALL, call?.event) 351 352 SignalDatabase.calls.acceptOutgoingGroupCall( 353 call!! 354 ) 355 356 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 357 assertEquals(CallTable.Event.OUTGOING_RING, acceptedCall?.event) 358 } 359 360 @Test 361 fun givenAJoinedGroupCall_whenIAcceptedOutgoingGroupCall_thenIExpectOutgoingRing() { 362 val era = "aaa" 363 val callId = CallId.fromEra(era).longValue() 364 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 365 groupRecipientId = groupRecipientId, 366 sender = harness.others[1], 367 timestamp = System.currentTimeMillis(), 368 peekGroupCallEraId = "aaa", 369 peekJoinedUuids = emptyList(), 370 isCallFull = false 371 ) 372 373 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 374 assertNotNull(call) 375 assertEquals(CallTable.Event.GENERIC_GROUP_CALL, call?.event) 376 377 SignalDatabase.calls.acceptIncomingGroupCall( 378 call!! 379 ) 380 381 SignalDatabase.calls.acceptOutgoingGroupCall(SignalDatabase.calls.getCallById(callId, groupRecipientId)!!) 382 val acceptedCall = SignalDatabase.calls.getCallById(callId, groupRecipientId) 383 assertEquals(CallTable.Event.OUTGOING_RING, acceptedCall?.event) 384 } 385 386 @Test 387 fun givenNoPriorCallEvent_whenIReceiveAGroupCallUpdateMessage_thenIExpectAGenericGroupCall() { 388 val era = "aaa" 389 val callId = CallId.fromEra(era).longValue() 390 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 391 groupRecipientId = groupRecipientId, 392 sender = harness.others[1], 393 timestamp = System.currentTimeMillis(), 394 peekGroupCallEraId = "aaa", 395 peekJoinedUuids = emptyList(), 396 isCallFull = false 397 ) 398 399 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 400 assertNotNull(call) 401 assertEquals(CallTable.Event.GENERIC_GROUP_CALL, call?.event) 402 } 403 404 @Test 405 fun givenAPriorCallEventWithNewerTimestamp_whenIReceiveAGroupCallUpdateMessage_thenIExpectAnUpdatedTimestamp() { 406 val era = "aaa" 407 val callId = CallId.fromEra(era).longValue() 408 val now = System.currentTimeMillis() 409 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 410 groupRecipientId = groupRecipientId, 411 sender = harness.others[1], 412 timestamp = now, 413 peekGroupCallEraId = "aaa", 414 peekJoinedUuids = emptyList(), 415 isCallFull = false 416 ) 417 418 SignalDatabase.calls.getCallById(callId, groupRecipientId).let { 419 assertNotNull(it) 420 assertEquals(now, it?.timestamp) 421 } 422 423 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 424 groupRecipientId = groupRecipientId, 425 sender = harness.others[1], 426 timestamp = 1L, 427 peekGroupCallEraId = "aaa", 428 peekJoinedUuids = emptyList(), 429 isCallFull = false 430 ) 431 432 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 433 assertNotNull(call) 434 assertEquals(CallTable.Event.GENERIC_GROUP_CALL, call?.event) 435 assertEquals(1L, call?.timestamp) 436 } 437 438 @Test 439 fun givenADeletedCallEvent_whenIReceiveARingUpdate_thenIIgnoreTheRingUpdate() { 440 val callId = 1L 441 SignalDatabase.calls.insertDeletedGroupCallFromSyncEvent( 442 callId = callId, 443 recipientId = groupRecipientId, 444 direction = CallTable.Direction.INCOMING, 445 timestamp = System.currentTimeMillis() 446 ) 447 448 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 449 ringId = callId, 450 groupRecipientId = groupRecipientId, 451 ringerRecipient = harness.others[1], 452 dateReceived = System.currentTimeMillis(), 453 ringState = CallManager.RingUpdate.REQUESTED 454 ) 455 456 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 457 assertNotNull(call) 458 assertEquals(CallTable.Event.DELETE, call?.event) 459 } 460 461 @Test 462 fun givenAGenericCallEvent_whenRingRequested_thenISetRingerAndMoveToRingingState() { 463 val era = "aaa" 464 val callId = CallId.fromEra(era).longValue() 465 val now = System.currentTimeMillis() 466 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 467 groupRecipientId = groupRecipientId, 468 sender = harness.others[1], 469 timestamp = now, 470 peekGroupCallEraId = "aaa", 471 peekJoinedUuids = emptyList(), 472 isCallFull = false 473 ) 474 475 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 476 callId, 477 groupRecipientId, 478 harness.others[1], 479 System.currentTimeMillis(), 480 CallManager.RingUpdate.REQUESTED 481 ) 482 483 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 484 assertNotNull(call) 485 assertEquals(CallTable.Event.RINGING, call?.event) 486 assertEquals(harness.others[1], call?.ringerRecipient) 487 } 488 489 @Test 490 fun givenAJoinedCallEvent_whenRingRequested_thenISetRingerAndMoveToRingingState() { 491 val era = "aaa" 492 val callId = CallId.fromEra(era).longValue() 493 val now = System.currentTimeMillis() 494 SignalDatabase.calls.insertAcceptedGroupCall( 495 callId, 496 groupRecipientId, 497 CallTable.Direction.INCOMING, 498 now 499 ) 500 501 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 502 callId, 503 groupRecipientId, 504 harness.others[1], 505 System.currentTimeMillis(), 506 CallManager.RingUpdate.REQUESTED 507 ) 508 509 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 510 assertNotNull(call) 511 assertEquals(CallTable.Event.ACCEPTED, call?.event) 512 assertEquals(harness.others[1], call?.ringerRecipient) 513 } 514 515 @Test 516 fun givenAGenericCallEvent_whenRingExpired_thenISetRingerAndMoveToMissedState() { 517 val era = "aaa" 518 val callId = CallId.fromEra(era).longValue() 519 val now = System.currentTimeMillis() 520 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 521 groupRecipientId = groupRecipientId, 522 sender = harness.others[1], 523 timestamp = now, 524 peekGroupCallEraId = "aaa", 525 peekJoinedUuids = emptyList(), 526 isCallFull = false 527 ) 528 529 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 530 callId, 531 groupRecipientId, 532 harness.others[1], 533 System.currentTimeMillis(), 534 CallManager.RingUpdate.EXPIRED_REQUEST 535 ) 536 537 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 538 assertNotNull(call) 539 assertEquals(CallTable.Event.MISSED, call?.event) 540 assertEquals(harness.others[1], call?.ringerRecipient) 541 } 542 543 @Test 544 fun givenARingingCallEvent_whenRingExpired_thenISetRingerAndMoveToMissedState() { 545 val era = "aaa" 546 val callId = CallId.fromEra(era).longValue() 547 val now = System.currentTimeMillis() 548 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 549 groupRecipientId = groupRecipientId, 550 sender = harness.others[1], 551 timestamp = now, 552 peekGroupCallEraId = "aaa", 553 peekJoinedUuids = emptyList(), 554 isCallFull = false 555 ) 556 557 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 558 callId, 559 groupRecipientId, 560 harness.others[1], 561 System.currentTimeMillis(), 562 CallManager.RingUpdate.REQUESTED 563 ) 564 565 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 566 callId, 567 groupRecipientId, 568 harness.others[1], 569 System.currentTimeMillis(), 570 CallManager.RingUpdate.EXPIRED_REQUEST 571 ) 572 573 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 574 assertNotNull(call) 575 assertEquals(CallTable.Event.MISSED, call?.event) 576 assertEquals(harness.others[1], call?.ringerRecipient) 577 } 578 579 @Test 580 fun givenAJoinedCallEvent_whenRingIsCancelledBecauseUserIsBusyLocally_thenIMoveToAcceptedState() { 581 val era = "aaa" 582 val callId = CallId.fromEra(era).longValue() 583 val now = System.currentTimeMillis() 584 SignalDatabase.calls.insertAcceptedGroupCall( 585 callId, 586 groupRecipientId, 587 CallTable.Direction.INCOMING, 588 now 589 ) 590 591 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 592 callId, 593 groupRecipientId, 594 harness.others[1], 595 System.currentTimeMillis(), 596 CallManager.RingUpdate.BUSY_LOCALLY 597 ) 598 599 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 600 assertNotNull(call) 601 assertEquals(CallTable.Event.ACCEPTED, call?.event) 602 } 603 604 @Test 605 fun givenAJoinedCallEvent_whenRingIsCancelledBecauseUserIsBusyOnAnotherDevice_thenIMoveToAcceptedState() { 606 val era = "aaa" 607 val callId = CallId.fromEra(era).longValue() 608 val now = System.currentTimeMillis() 609 SignalDatabase.calls.insertAcceptedGroupCall( 610 callId, 611 groupRecipientId, 612 CallTable.Direction.INCOMING, 613 now 614 ) 615 616 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 617 callId, 618 groupRecipientId, 619 harness.others[1], 620 System.currentTimeMillis(), 621 CallManager.RingUpdate.BUSY_ON_ANOTHER_DEVICE 622 ) 623 624 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 625 assertNotNull(call) 626 assertEquals(CallTable.Event.ACCEPTED, call?.event) 627 } 628 629 @Test 630 fun givenARingingCallEvent_whenRingCancelledBecauseUserIsBusyLocally_thenIMoveToMissedState() { 631 val era = "aaa" 632 val callId = CallId.fromEra(era).longValue() 633 val now = System.currentTimeMillis() 634 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 635 groupRecipientId = groupRecipientId, 636 sender = harness.others[1], 637 timestamp = now, 638 peekGroupCallEraId = "aaa", 639 peekJoinedUuids = emptyList(), 640 isCallFull = false 641 ) 642 643 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 644 callId, 645 groupRecipientId, 646 harness.others[1], 647 System.currentTimeMillis(), 648 CallManager.RingUpdate.REQUESTED 649 ) 650 651 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 652 callId, 653 groupRecipientId, 654 harness.others[1], 655 System.currentTimeMillis(), 656 CallManager.RingUpdate.BUSY_LOCALLY 657 ) 658 659 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 660 assertNotNull(call) 661 assertEquals(CallTable.Event.MISSED, call?.event) 662 } 663 664 @Test 665 fun givenARingingCallEvent_whenRingCancelledBecauseUserIsBusyOnAnotherDevice_thenIMoveToMissedState() { 666 val era = "aaa" 667 val callId = CallId.fromEra(era).longValue() 668 val now = System.currentTimeMillis() 669 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 670 groupRecipientId = groupRecipientId, 671 sender = harness.others[1], 672 timestamp = now, 673 peekGroupCallEraId = "aaa", 674 peekJoinedUuids = emptyList(), 675 isCallFull = false 676 ) 677 678 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 679 callId, 680 groupRecipientId, 681 harness.others[1], 682 System.currentTimeMillis(), 683 CallManager.RingUpdate.REQUESTED 684 ) 685 686 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 687 callId, 688 groupRecipientId, 689 harness.others[1], 690 System.currentTimeMillis(), 691 CallManager.RingUpdate.BUSY_ON_ANOTHER_DEVICE 692 ) 693 694 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 695 assertNotNull(call) 696 assertEquals(CallTable.Event.MISSED, call?.event) 697 } 698 699 @Test 700 fun givenACallEvent_whenRingIsAcceptedOnAnotherDevice_thenIMoveToAcceptedState() { 701 val era = "aaa" 702 val callId = CallId.fromEra(era).longValue() 703 val now = System.currentTimeMillis() 704 SignalDatabase.calls.insertOrUpdateGroupCallFromLocalEvent( 705 groupRecipientId = groupRecipientId, 706 sender = harness.others[1], 707 timestamp = now, 708 peekGroupCallEraId = "aaa", 709 peekJoinedUuids = emptyList(), 710 isCallFull = false 711 ) 712 713 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 714 callId, 715 groupRecipientId, 716 harness.others[1], 717 System.currentTimeMillis(), 718 CallManager.RingUpdate.ACCEPTED_ON_ANOTHER_DEVICE 719 ) 720 721 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 722 assertNotNull(call) 723 assertEquals(CallTable.Event.ACCEPTED, call?.event) 724 } 725 726 @Test 727 fun givenARingingCallEvent_whenRingDeclinedOnAnotherDevice_thenIMoveToDeclinedState() { 728 val era = "aaa" 729 val callId = CallId.fromEra(era).longValue() 730 731 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 732 callId, 733 groupRecipientId, 734 harness.others[1], 735 System.currentTimeMillis(), 736 CallManager.RingUpdate.REQUESTED 737 ) 738 739 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 740 callId, 741 groupRecipientId, 742 harness.others[1], 743 System.currentTimeMillis(), 744 CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE 745 ) 746 747 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 748 assertNotNull(call) 749 assertEquals(CallTable.Event.DECLINED, call?.event) 750 } 751 752 @Test 753 fun givenAMissedCallEvent_whenRingDeclinedOnAnotherDevice_thenIMoveToDeclinedState() { 754 val era = "aaa" 755 val callId = CallId.fromEra(era).longValue() 756 757 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 758 callId, 759 groupRecipientId, 760 harness.others[1], 761 System.currentTimeMillis(), 762 CallManager.RingUpdate.EXPIRED_REQUEST 763 ) 764 765 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 766 callId, 767 groupRecipientId, 768 harness.others[1], 769 System.currentTimeMillis(), 770 CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE 771 ) 772 773 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 774 assertNotNull(call) 775 assertEquals(CallTable.Event.DECLINED, call?.event) 776 } 777 778 @Test 779 fun givenAnOutgoingRingCallEvent_whenRingDeclinedOnAnotherDevice_thenIDoNotChangeState() { 780 val era = "aaa" 781 val callId = CallId.fromEra(era).longValue() 782 783 SignalDatabase.calls.insertAcceptedGroupCall( 784 callId, 785 groupRecipientId, 786 CallTable.Direction.OUTGOING, 787 System.currentTimeMillis() 788 ) 789 790 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 791 callId, 792 groupRecipientId, 793 harness.others[1], 794 System.currentTimeMillis(), 795 CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE 796 ) 797 798 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 799 assertNotNull(call) 800 assertEquals(CallTable.Event.OUTGOING_RING, call?.event) 801 } 802 803 @Test 804 fun givenNoPriorEvent_whenRingRequested_thenICreateAnEventInTheRingingStateAndSetRinger() { 805 val callId = 1L 806 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 807 callId, 808 groupRecipientId, 809 harness.others[1], 810 System.currentTimeMillis(), 811 CallManager.RingUpdate.REQUESTED 812 ) 813 814 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 815 assertNotNull(call) 816 assertEquals(CallTable.Event.RINGING, call?.event) 817 assertEquals(harness.others[1], call?.ringerRecipient) 818 assertNotNull(call?.messageId) 819 } 820 821 @Test 822 fun givenNoPriorEvent_whenRingExpired_thenICreateAnEventInTheMissedStateAndSetRinger() { 823 val callId = 1L 824 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 825 callId, 826 groupRecipientId, 827 harness.others[1], 828 System.currentTimeMillis(), 829 CallManager.RingUpdate.EXPIRED_REQUEST 830 ) 831 832 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 833 assertNotNull(call) 834 assertEquals(CallTable.Event.MISSED, call?.event) 835 assertEquals(harness.others[1], call?.ringerRecipient) 836 assertNotNull(call?.messageId) 837 } 838 839 @Test 840 fun givenNoPriorEvent_whenRingCancelledByRinger_thenICreateAnEventInTheMissedStateAndSetRinger() { 841 val callId = 1L 842 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 843 callId, 844 groupRecipientId, 845 harness.others[1], 846 System.currentTimeMillis(), 847 CallManager.RingUpdate.CANCELLED_BY_RINGER 848 ) 849 850 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 851 assertNotNull(call) 852 assertEquals(CallTable.Event.MISSED, call?.event) 853 assertEquals(harness.others[1], call?.ringerRecipient) 854 assertNotNull(call?.messageId) 855 } 856 857 @Test 858 fun givenNoPriorEvent_whenRingCancelledBecauseUserIsBusyLocally_thenICreateAnEventInTheMissedState() { 859 val callId = 1L 860 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 861 callId, 862 groupRecipientId, 863 harness.others[1], 864 System.currentTimeMillis(), 865 CallManager.RingUpdate.BUSY_LOCALLY 866 ) 867 868 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 869 assertNotNull(call) 870 assertEquals(CallTable.Event.MISSED, call?.event) 871 assertNotNull(call?.messageId) 872 } 873 874 @Test 875 fun givenNoPriorEvent_whenRingCancelledBecauseUserIsBusyOnAnotherDevice_thenICreateAnEventInTheMissedState() { 876 val callId = 1L 877 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 878 callId, 879 groupRecipientId, 880 harness.others[1], 881 System.currentTimeMillis(), 882 CallManager.RingUpdate.BUSY_ON_ANOTHER_DEVICE 883 ) 884 885 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 886 assertNotNull(call) 887 assertEquals(CallTable.Event.MISSED, call?.event) 888 assertNotNull(call?.messageId) 889 } 890 891 @Test 892 fun givenNoPriorEvent_whenRingAcceptedOnAnotherDevice_thenICreateAnEventInTheAcceptedState() { 893 val callId = 1L 894 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 895 callId, 896 groupRecipientId, 897 harness.others[1], 898 System.currentTimeMillis(), 899 CallManager.RingUpdate.ACCEPTED_ON_ANOTHER_DEVICE 900 ) 901 902 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 903 assertNotNull(call) 904 assertEquals(CallTable.Event.ACCEPTED, call?.event) 905 assertNotNull(call?.messageId) 906 } 907 908 @Test 909 fun givenNoPriorEvent_whenRingDeclinedOnAnotherDevice_thenICreateAnEventInTheDeclinedState() { 910 val callId = 1L 911 SignalDatabase.calls.insertOrUpdateGroupCallFromRingState( 912 callId, 913 groupRecipientId, 914 harness.others[1], 915 System.currentTimeMillis(), 916 CallManager.RingUpdate.DECLINED_ON_ANOTHER_DEVICE 917 ) 918 919 val call = SignalDatabase.calls.getCallById(callId, groupRecipientId) 920 assertNotNull(call) 921 assertEquals(CallTable.Event.DECLINED, call?.event) 922 assertNotNull(call?.messageId) 923 } 924 925 @Test 926 fun givenTwoCalls_whenIDeleteBeforeCallB_thenOnlyDeleteCallA() { 927 insertTwoCallEvents() 928 929 SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(1500) 930 931 val allCallEvents = SignalDatabase.calls.getCalls(0, 2, null, CallLogFilter.ALL) 932 assertEquals(1, allCallEvents.size) 933 assertEquals(2, allCallEvents.first().record.callId) 934 } 935 936 @Test 937 fun givenTwoCalls_whenIDeleteBeforeCallA_thenIDoNotDeleteAnyCalls() { 938 insertTwoCallEvents() 939 940 SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(500) 941 942 val allCallEvents = SignalDatabase.calls.getCalls(0, 2, null, CallLogFilter.ALL) 943 assertEquals(2, allCallEvents.size) 944 assertEquals(2, allCallEvents[0].record.callId) 945 assertEquals(1, allCallEvents[1].record.callId) 946 } 947 948 @Test 949 fun givenTwoCalls_whenIDeleteOnCallA_thenIOnlyDeleteCallA() { 950 insertTwoCallEvents() 951 952 SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(1000) 953 954 val allCallEvents = SignalDatabase.calls.getCalls(0, 2, null, CallLogFilter.ALL) 955 assertEquals(1, allCallEvents.size) 956 assertEquals(2, allCallEvents.first().record.callId) 957 } 958 959 @Test 960 fun givenTwoCalls_whenIDeleteOnCallB_thenIDeleteBothCalls() { 961 insertTwoCallEvents() 962 963 SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(2000) 964 965 val allCallEvents = SignalDatabase.calls.getCalls(0, 2, null, CallLogFilter.ALL) 966 assertEquals(0, allCallEvents.size) 967 } 968 969 @Test 970 fun givenTwoCalls_whenIDeleteAfterCallB_thenIDeleteBothCalls() { 971 insertTwoCallEvents() 972 973 SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(2500) 974 975 val allCallEvents = SignalDatabase.calls.getCalls(0, 2, null, CallLogFilter.ALL) 976 assertEquals(0, allCallEvents.size) 977 } 978 979 private fun insertTwoCallEvents() { 980 SignalDatabase.calls.insertAcceptedGroupCall( 981 1, 982 groupRecipientId, 983 CallTable.Direction.INCOMING, 984 1000 985 ) 986 987 SignalDatabase.calls.insertAcceptedGroupCall( 988 2, 989 groupRecipientId, 990 CallTable.Direction.OUTGOING, 991 2000 992 ) 993 } 994}