@@ -2607,44 +2607,67 @@ async fn test_can_send_group() -> Result<()> {
2607
2607
}
2608
2608
2609
2609
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2610
- async fn test_broadcast ( ) -> Result < ( ) > {
2610
+ async fn test_broadcast_change_name ( ) -> Result < ( ) > {
2611
2611
// 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 ;
2615
2616
2617
+ tcm. section ( "Alice sends a message to Bob" ) ;
2616
2618
let chat_alice = alice. create_chat ( & bob) . await ;
2617
2619
send_text_msg ( & alice, chat_alice. id , "hi!" . to_string ( ) ) . await ?;
2618
2620
bob. recv_msg ( & alice. pop_sent_msg ( ) . await ) . await ;
2619
2621
2622
+ tcm. section ( "Bob sends a message to Alice" ) ;
2620
2623
let chat_bob = bob. create_chat ( & alice) . await ;
2621
2624
send_text_msg ( & bob, chat_bob. id , "ho!" . to_string ( ) ) . await ?;
2622
2625
let msg = alice. recv_msg ( & bob. pop_sent_msg ( ) . await ) . await ;
2623
2626
assert ! ( msg. get_showpadlock( ) ) ;
2624
2627
2625
- // test broadcast channel
2626
2628
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
+
2636
2636
{
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
+
2637
2658
let chat = Chat :: load_from_db ( & alice, broadcast_id) . await ?;
2638
2659
assert_eq ! ( chat. typ, Chattype :: OutBroadcast ) ;
2639
2660
assert_eq ! ( chat. name, "Broadcast channel" ) ;
2640
2661
assert ! ( !chat. is_self_talk( ) ) ;
2641
2662
2663
+ tcm. section ( "Alice sends a text message 'ola!'" ) ;
2642
2664
send_text_msg ( & alice, broadcast_id, "ola!" . to_string ( ) ) . await ?;
2643
2665
let msg = alice. get_last_msg ( ) . await ;
2644
2666
assert_eq ! ( msg. chat_id, chat. id) ;
2645
2667
}
2646
2668
2647
2669
{
2670
+ tcm. section ( "Bob receives the 'ola!' message" ) ;
2648
2671
let sent_msg = alice. pop_sent_msg ( ) . await ;
2649
2672
let msg = bob. parse_msg ( & sent_msg) . await ;
2650
2673
assert ! ( msg. was_encrypted( ) ) ;
@@ -2657,25 +2680,23 @@ async fn test_broadcast() -> Result<()> {
2657
2680
2658
2681
let msg = bob. recv_msg ( & sent_msg) . await ;
2659
2682
assert_eq ! ( msg. get_text( ) , "ola!" ) ;
2660
- assert_eq ! ( msg. subject, "Broadcast channel" ) ;
2683
+ assert_eq ! ( msg. subject, "Re: Broadcast channel" ) ;
2661
2684
assert ! ( msg. get_showpadlock( ) ) ;
2662
2685
assert ! ( msg. get_override_sender_name( ) . is_none( ) ) ;
2663
2686
let chat = Chat :: load_from_db ( & bob, msg. chat_id ) . await ?;
2664
2687
assert_eq ! ( chat. typ, Chattype :: InBroadcast ) ;
2665
2688
assert_ne ! ( chat. id, chat_bob. id) ;
2666
2689
assert_eq ! ( chat. name, "Broadcast channel" ) ;
2667
2690
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 ;
2674
2691
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" ) ;
2679
2700
}
2680
2701
2681
2702
Ok ( ( ) )
0 commit comments