Skip to content

Commit e85d971

Browse files
committed
add test
1 parent aad8f69 commit e85d971

File tree

1 file changed

+77
-4
lines changed

1 file changed

+77
-4
lines changed

src/peer_channels.rs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,9 @@ mod tests {
555555
use super::*;
556556
use crate::{
557557
EventType,
558-
chat::send_msg,
559558
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},
561561
};
562562

563563
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -924,8 +924,30 @@ mod tests {
924924
let alice = &mut tcm.alice().await;
925925
let bob = &mut tcm.bob().await;
926926

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+
927950
// Alice sends webxdc to bob
928-
let alice_chat = alice.create_chat(bob).await;
929951
let mut instance = Message::new(Viewtype::File);
930952
instance
931953
.set_file_from_bytes(
@@ -935,7 +957,58 @@ mod tests {
935957
None,
936958
)
937959
.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();
9391012
let alice_webxdc = alice.get_last_msg().await;
9401013

9411014
let webxdc = alice.pop_sent_msg().await;

0 commit comments

Comments
 (0)