@@ -2607,44 +2607,67 @@ async fn test_can_send_group() -> Result<()> {
26072607}
26082608
26092609#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2610- async fn test_broadcast ( ) -> Result < ( ) > {
2610+ async fn test_broadcast_change_name ( ) -> Result < ( ) > {
26112611 // create two context, send two messages so both know the other
2612- let alice = TestContext :: new_alice ( ) . await ;
2613- let bob = TestContext :: new_bob ( ) . await ;
2614- let fiona = TestContext :: new_fiona ( ) . await ;
2612+ let mut tcm = TestContextManager :: new ( ) ;
2613+ let alice = & tcm. alice ( ) . await ;
2614+ let bob = & tcm. bob ( ) . await ;
2615+ let fiona = & tcm. fiona ( ) . await ;
26152616
2617+ tcm. section ( "Alice sends a message to Bob" ) ;
26162618 let chat_alice = alice. create_chat ( & bob) . await ;
26172619 send_text_msg ( & alice, chat_alice. id , "hi!" . to_string ( ) ) . await ?;
26182620 bob. recv_msg ( & alice. pop_sent_msg ( ) . await ) . await ;
26192621
2622+ tcm. section ( "Bob sends a message to Alice" ) ;
26202623 let chat_bob = bob. create_chat ( & alice) . await ;
26212624 send_text_msg ( & bob, chat_bob. id , "ho!" . to_string ( ) ) . await ?;
26222625 let msg = alice. recv_msg ( & bob. pop_sent_msg ( ) . await ) . await ;
26232626 assert ! ( msg. get_showpadlock( ) ) ;
26242627
2625- // test broadcast channel
26262628 let broadcast_id = create_broadcast ( & alice, "Channel" . to_string ( ) ) . await ?;
2627- add_contact_to_chat (
2628- & alice,
2629- broadcast_id,
2630- get_chat_contacts ( & alice, chat_bob. id ) . await ?. pop ( ) . unwrap ( ) ,
2631- )
2632- . await ?;
2633- let fiona_contact_id = alice. add_or_lookup_contact_id ( & fiona) . await ;
2634- add_contact_to_chat ( & alice, broadcast_id, fiona_contact_id) . await ?;
2635- set_chat_name ( & alice, broadcast_id, "Broadcast channel" ) . await ?;
2629+ let qr = get_securejoin_qr ( alice, Some ( broadcast_id) ) . await . unwrap ( ) ;
2630+
2631+ tcm. section ( "Alice invites Bob to her channel" ) ;
2632+ tcm. exec_securejoin_qr ( bob, alice, & qr) . await ;
2633+ tcm. section ( "Alice invites Fiona to her channel" ) ;
2634+ tcm. exec_securejoin_qr ( fiona, alice, & qr) . await ;
2635+
26362636 {
2637+ tcm. section ( "Alice changes the chat name" ) ;
2638+ set_chat_name ( & alice, broadcast_id, "My great broadcast" ) . await ?;
2639+ let sent = alice. pop_sent_msg ( ) . await ;
2640+
2641+ tcm. section ( "Bob receives the name-change system message" ) ;
2642+ let msg = bob. recv_msg ( & sent) . await ;
2643+ assert_eq ! ( msg. subject, "Re: My great broadcast" ) ;
2644+ let bob_chat = Chat :: load_from_db ( bob, msg. chat_id ) . await ?;
2645+ assert_eq ! ( bob_chat. name, "My great broadcast" ) ;
2646+
2647+ tcm. section ( "Fiona receives the name-change system message" ) ;
2648+ let msg = fiona. recv_msg ( & sent) . await ;
2649+ assert_eq ! ( msg. subject, "Re: My great broadcast" ) ;
2650+ let fiona_chat = Chat :: load_from_db ( fiona, msg. chat_id ) . await ?;
2651+ assert_eq ! ( fiona_chat. name, "My great broadcast" ) ;
2652+ }
2653+
2654+ {
2655+ tcm. section ( "Alice changes the chat name again, but the system message is lost somehow" ) ;
2656+ set_chat_name ( & alice, broadcast_id, "Broadcast channel" ) . await ?;
2657+
26372658 let chat = Chat :: load_from_db ( & alice, broadcast_id) . await ?;
26382659 assert_eq ! ( chat. typ, Chattype :: OutBroadcast ) ;
26392660 assert_eq ! ( chat. name, "Broadcast channel" ) ;
26402661 assert ! ( !chat. is_self_talk( ) ) ;
26412662
2663+ tcm. section ( "Alice sends a text message 'ola!'" ) ;
26422664 send_text_msg ( & alice, broadcast_id, "ola!" . to_string ( ) ) . await ?;
26432665 let msg = alice. get_last_msg ( ) . await ;
26442666 assert_eq ! ( msg. chat_id, chat. id) ;
26452667 }
26462668
26472669 {
2670+ tcm. section ( "Bob receives the 'ola!' message" ) ;
26482671 let sent_msg = alice. pop_sent_msg ( ) . await ;
26492672 let msg = bob. parse_msg ( & sent_msg) . await ;
26502673 assert ! ( msg. was_encrypted( ) ) ;
@@ -2657,25 +2680,23 @@ async fn test_broadcast() -> Result<()> {
26572680
26582681 let msg = bob. recv_msg ( & sent_msg) . await ;
26592682 assert_eq ! ( msg. get_text( ) , "ola!" ) ;
2660- assert_eq ! ( msg. subject, "Broadcast channel" ) ;
2683+ assert_eq ! ( msg. subject, "Re: Broadcast channel" ) ;
26612684 assert ! ( msg. get_showpadlock( ) ) ;
26622685 assert ! ( msg. get_override_sender_name( ) . is_none( ) ) ;
26632686 let chat = Chat :: load_from_db ( & bob, msg. chat_id ) . await ?;
26642687 assert_eq ! ( chat. typ, Chattype :: InBroadcast ) ;
26652688 assert_ne ! ( chat. id, chat_bob. id) ;
26662689 assert_eq ! ( chat. name, "Broadcast channel" ) ;
26672690 assert ! ( !chat. is_self_talk( ) ) ;
2668- }
2669-
2670- {
2671- // Alice changes the name:
2672- set_chat_name ( & alice, broadcast_id, "My great broadcast" ) . await ?;
2673- let sent = alice. send_text ( broadcast_id, "I changed the title!" ) . await ;
26742691
2675- let msg = bob. recv_msg ( & sent) . await ;
2676- assert_eq ! ( msg. subject, "Re: My great broadcast" ) ;
2677- let bob_chat = Chat :: load_from_db ( & bob, msg. chat_id ) . await ?;
2678- assert_eq ! ( bob_chat. name, "My great broadcast" ) ;
2692+ tcm. section ( "Fiona receives the 'ola!' message" ) ;
2693+ let msg = fiona. recv_msg ( & sent_msg) . await ;
2694+ assert_eq ! ( msg. get_text( ) , "ola!" ) ;
2695+ assert ! ( msg. get_showpadlock( ) ) ;
2696+ assert ! ( msg. get_override_sender_name( ) . is_none( ) ) ;
2697+ let chat = Chat :: load_from_db ( fiona, msg. chat_id ) . await ?;
2698+ assert_eq ! ( chat. typ, Chattype :: InBroadcast ) ;
2699+ assert_eq ! ( chat. name, "Broadcast channel" ) ;
26792700 }
26802701
26812702 Ok ( ( ) )
0 commit comments