@@ -555,9 +555,9 @@ mod tests {
555
555
use super :: * ;
556
556
use crate :: {
557
557
EventType ,
558
- chat:: send_msg,
559
558
message:: { Message , Viewtype } ,
560
- test_utils:: TestContextManager ,
559
+ chat:: { self , add_contact_to_chat, resend_msgs, send_msg, ChatId , ProtectionStatus } ,
560
+ test_utils:: { TestContext , TestContextManager } ,
561
561
} ;
562
562
563
563
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
@@ -924,8 +924,30 @@ mod tests {
924
924
let alice = & mut tcm. alice ( ) . await ;
925
925
let bob = & mut tcm. bob ( ) . await ;
926
926
927
+ let chat = alice. create_chat ( & bob) . await . id ;
928
+
929
+ let mut instance = Message :: new ( Viewtype :: File ) ;
930
+ instance
931
+ . set_file_from_bytes (
932
+ alice,
933
+ "minimal.xdc" ,
934
+ include_bytes ! ( "../test-data/webxdc/minimal.xdc" ) ,
935
+ None ,
936
+ )
937
+ . unwrap ( ) ;
938
+ connect_alice_bob ( alice, bob, chat, & mut instance) . await
939
+ }
940
+
941
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
942
+ async fn test_webxdc_resend ( ) {
943
+ let mut tcm = TestContextManager :: new ( ) ;
944
+ let alice = & mut tcm. alice ( ) . await ;
945
+ let bob = & mut tcm. bob ( ) . await ;
946
+ let group = chat:: create_group_chat ( & alice, ProtectionStatus :: Unprotected , "" )
947
+ . await
948
+ . unwrap ( ) ;
949
+
927
950
// Alice sends webxdc to bob
928
- let alice_chat = alice. create_chat ( bob) . await ;
929
951
let mut instance = Message :: new ( Viewtype :: File ) ;
930
952
instance
931
953
. set_file_from_bytes (
@@ -935,7 +957,58 @@ mod tests {
935
957
None ,
936
958
)
937
959
. unwrap ( ) ;
938
- send_msg ( alice, alice_chat. id , & mut instance) . await . unwrap ( ) ;
960
+
961
+ connect_alice_bob ( alice, bob, group, & mut instance) . await ;
962
+
963
+ // fiona joins late
964
+ let fiona = & mut tcm. fiona ( ) . await ;
965
+ add_contact_to_chat ( & alice, group, alice. add_or_lookup_contact_id ( & bob) . await )
966
+ . await
967
+ . unwrap ( ) ;
968
+
969
+ add_contact_to_chat ( & alice, group, alice. add_or_lookup_contact_id ( & fiona) . await )
970
+ . await
971
+ . unwrap ( ) ;
972
+
973
+ resend_msgs ( & alice, & [ instance. id ] ) . await . unwrap ( ) ;
974
+ let msg = alice. pop_sent_msg ( ) . await ;
975
+ let fiona_instance = fiona. recv_msg ( & msg) . await . id ;
976
+
977
+ let fiona_connect_future = send_webxdc_realtime_advertisement ( & fiona, fiona_instance)
978
+ . await
979
+ . unwrap ( )
980
+ . unwrap ( ) ;
981
+ let fiona_advert = fiona. pop_sent_msg ( ) . await ;
982
+ alice. recv_msg_trash ( & fiona_advert) . await ;
983
+
984
+ fiona_connect_future. await . unwrap ( ) ;
985
+ send_webxdc_realtime_data ( alice, instance. id , b"alice -> bob & fiona" . into ( ) )
986
+ . await
987
+ . unwrap ( ) ;
988
+
989
+ eprintln ! ( "Waiting for ephemeral message" ) ;
990
+ loop {
991
+ let event = fiona. evtracker . recv ( ) . await . unwrap ( ) ;
992
+ if let EventType :: WebxdcRealtimeData { data, .. } = event. typ {
993
+ if data == b"alice -> bob & fiona" {
994
+ break ;
995
+ } else {
996
+ panic ! (
997
+ "Unexpected status update: {}" ,
998
+ String :: from_utf8_lossy( & data)
999
+ ) ;
1000
+ }
1001
+ }
1002
+ }
1003
+ }
1004
+
1005
+ async fn connect_alice_bob (
1006
+ alice : & mut TestContext ,
1007
+ bob : & mut TestContext ,
1008
+ chat : ChatId ,
1009
+ instance : & mut Message ,
1010
+ ) {
1011
+ send_msg ( alice, chat, instance) . await . unwrap ( ) ;
939
1012
let alice_webxdc = alice. get_last_msg ( ) . await ;
940
1013
941
1014
let webxdc = alice. pop_sent_msg ( ) . await ;
0 commit comments