11use super :: * ;
22use crate :: chat:: forward_msgs;
33use crate :: config:: Config ;
4+ use crate :: constants:: DC_CHAT_ID_TRASH ;
5+ use crate :: receive_imf:: receive_imf;
46use crate :: test_utils:: { TestContext , TestContextManager } ;
57
68struct CallSetup {
@@ -53,7 +55,10 @@ async fn setup_call() -> Result<CallSetup> {
5355 for ( t, m) in [ ( & alice, & alice_call) , ( & alice2, & alice2_call) ] {
5456 assert ! ( !m. is_info( ) ) ;
5557 assert_eq ! ( m. viewtype, Viewtype :: Call ) ;
56- let info = t. load_call_by_id ( m. id ) . await ?;
58+ let info = t
59+ . load_call_by_id ( m. id )
60+ . await ?
61+ . expect ( "m should be a call message" ) ;
5762 assert ! ( !info. is_incoming( ) ) ;
5863 assert ! ( !info. is_accepted( ) ) ;
5964 assert_eq ! ( info. place_call_info, PLACE_INFO ) ;
@@ -71,7 +76,10 @@ async fn setup_call() -> Result<CallSetup> {
7176 t. evtracker
7277 . get_matching ( |evt| matches ! ( evt, EventType :: IncomingCall { .. } ) )
7378 . await ;
74- let info = t. load_call_by_id ( m. id ) . await ?;
79+ let info = t
80+ . load_call_by_id ( m. id )
81+ . await ?
82+ . expect ( "IncomingCall event should refer to a call message" ) ;
7583 assert ! ( info. is_incoming( ) ) ;
7684 assert ! ( !info. is_accepted( ) ) ;
7785 assert_eq ! ( info. place_call_info, PLACE_INFO ) ;
@@ -111,7 +119,10 @@ async fn accept_call() -> Result<CallSetup> {
111119 . get_matching ( |evt| matches ! ( evt, EventType :: IncomingCallAccepted { .. } ) )
112120 . await ;
113121 let sent2 = bob. pop_sent_msg ( ) . await ;
114- let info = bob. load_call_by_id ( bob_call. id ) . await ?;
122+ let info = bob
123+ . load_call_by_id ( bob_call. id )
124+ . await ?
125+ . expect ( "bob_call should be a call message" ) ;
115126 assert ! ( info. is_accepted( ) ) ;
116127 assert_eq ! ( info. place_call_info, PLACE_INFO ) ;
117128 assert_eq ! ( call_state( & bob, bob_call. id) . await ?, CallState :: Active ) ;
@@ -121,7 +132,10 @@ async fn accept_call() -> Result<CallSetup> {
121132 bob2. evtracker
122133 . get_matching ( |evt| matches ! ( evt, EventType :: IncomingCallAccepted { .. } ) )
123134 . await ;
124- let info = bob2. load_call_by_id ( bob2_call. id ) . await ?;
135+ let info = bob2
136+ . load_call_by_id ( bob2_call. id )
137+ . await ?
138+ . expect ( "bob2_call should be a call message" ) ;
125139 assert ! ( info. is_accepted( ) ) ;
126140 assert_eq ! ( call_state( & bob2, bob2_call. id) . await ?, CallState :: Active ) ;
127141
@@ -140,7 +154,10 @@ async fn accept_call() -> Result<CallSetup> {
140154 accept_call_info: ACCEPT_INFO . to_string( )
141155 }
142156 ) ;
143- let info = alice. load_call_by_id ( alice_call. id ) . await ?;
157+ let info = alice
158+ . load_call_by_id ( alice_call. id )
159+ . await ?
160+ . expect ( "alice_call should be a call message" ) ;
144161 assert ! ( info. is_accepted( ) ) ;
145162 assert_eq ! ( info. place_call_info, PLACE_INFO ) ;
146163 assert_eq ! ( call_state( & alice, alice_call. id) . await ?, CallState :: Active ) ;
@@ -460,14 +477,20 @@ async fn test_mark_calls() -> Result<()> {
460477 alice, alice_call, ..
461478 } = setup_call ( ) . await ?;
462479
463- let mut call_info: CallInfo = alice. load_call_by_id ( alice_call. id ) . await ?;
480+ let mut call_info: CallInfo = alice
481+ . load_call_by_id ( alice_call. id )
482+ . await ?
483+ . expect ( "alice_call should be a call message" ) ;
464484 assert ! ( !call_info. is_accepted( ) ) ;
465485 assert ! ( !call_info. is_ended( ) ) ;
466486 call_info. mark_as_accepted ( & alice) . await ?;
467487 assert ! ( call_info. is_accepted( ) ) ;
468488 assert ! ( !call_info. is_ended( ) ) ;
469489
470- let mut call_info: CallInfo = alice. load_call_by_id ( alice_call. id ) . await ?;
490+ let mut call_info: CallInfo = alice
491+ . load_call_by_id ( alice_call. id )
492+ . await ?
493+ . expect ( "alice_call should be a call message" ) ;
471494 assert ! ( call_info. is_accepted( ) ) ;
472495 assert ! ( !call_info. is_ended( ) ) ;
473496
@@ -484,7 +507,10 @@ async fn test_update_call_text() -> Result<()> {
484507 alice, alice_call, ..
485508 } = setup_call ( ) . await ?;
486509
487- let call_info = alice. load_call_by_id ( alice_call. id ) . await ?;
510+ let call_info = alice
511+ . load_call_by_id ( alice_call. id )
512+ . await ?
513+ . expect ( "alice_call should be a call message" ) ;
488514 call_info. update_text ( & alice, "foo bar" ) . await ?;
489515
490516 let alice_call = Message :: load_from_db ( & alice, alice_call. id ) . await ?;
@@ -529,3 +555,52 @@ async fn test_forward_call() -> Result<()> {
529555
530556 Ok ( ( ) )
531557}
558+
559+ /// Tests that "end call" message referring
560+ /// to a text message does not make receive_imf fail.
561+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
562+ async fn test_end_text_call ( ) -> Result < ( ) > {
563+ let mut tcm = TestContextManager :: new ( ) ;
564+ let alice = & tcm. alice ( ) . await ;
565+
566+ let received1 = receive_imf (
567+ alice,
568+ b"From: bob@example.net\n \
569+ To: alice@example.org\n \
570+ Message-ID: <first@example.net>\n \
571+ Date: Sun, 22 Mar 2020 22:37:57 +0000\n \
572+ Chat-Version: 1.0\n \
573+ \n \
574+ Hello\n ",
575+ false ,
576+ )
577+ . await ?
578+ . unwrap ( ) ;
579+ assert_eq ! ( received1. msg_ids. len( ) , 1 ) ;
580+ let msg = Message :: load_from_db ( alice, received1. msg_ids [ 0 ] )
581+ . await
582+ . unwrap ( ) ;
583+ assert_eq ! ( msg. viewtype, Viewtype :: Text ) ;
584+
585+ // Receiving "Call ended" message that refers
586+ // to the text message does not result in an error.
587+ let received2 = receive_imf (
588+ alice,
589+ b"From: bob@example.net\n \
590+ To: alice@example.org\n \
591+ Message-ID: <second@example.net>\n \
592+ Date: Sun, 22 Mar 2020 23:37:57 +0000\n \
593+ In-Reply-To: <first@example.net>\n \
594+ Chat-Version: 1.0\n \
595+ Chat-Content: call-ended\n \
596+ \n \
597+ Call ended\n ",
598+ false ,
599+ )
600+ . await ?
601+ . unwrap ( ) ;
602+ assert_eq ! ( received2. msg_ids. len( ) , 1 ) ;
603+ assert_eq ! ( received2. chat_id, DC_CHAT_ID_TRASH ) ;
604+
605+ Ok ( ( ) )
606+ }
0 commit comments