From 506e288b90151fcef82e60f0bda2ec44d8549abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 18 Sep 2022 12:12:27 +0200 Subject: [PATCH] Add test_presence_resync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- README.md | 5 ++-- src/tests.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 20d5f94..d2606b6 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ file. * [ ] Multiple sessions non-MSN * [ ] MSN - [ ] Presence - * [ ] Probes - * [ ] Resync + * [x] Updates + * [x] Resync + * [ ] Probes (storing updates to answer probes) - [ ] Iq * [ ] Ping answers * [ ] Ping probes? diff --git a/src/tests.rs b/src/tests.rs index e1290e1..7dc12bd 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -303,6 +303,76 @@ async fn test_join_presence_existing_room() { } } +#[tokio::test] +async fn test_presence_resync() { + let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap(); + let realjid2 = FullJid::from_str("qxx@bar/foo").unwrap(); + let roomjid = COMPONENT_JID.clone().with_node("room"); + let participant1 = roomjid.clone().with_resource("nick1"); + let participant2 = roomjid.clone().with_resource("nick2"); + + let join1: Element = Presence::new(PresenceType::None) + .with_from(Jid::Full(realjid1.clone())) + .with_to(Jid::Full(participant1.clone())) + .with_payloads(vec![Muc::new().into()]) + .into(); + + let join2: Element = Presence::new(PresenceType::None) + .with_from(Jid::Full(realjid2.clone())) + .with_to(Jid::Full(participant2.clone())) + .with_payloads(vec![Muc::new().into()]) + .into(); + + let mut component = TestComponent::new(vec![join1.clone(), join2, join1]); + let mut rooms: HashMap = HashMap::new(); + + // Self-presence for participant1 + component.expect_presence(|_| ()); + // Subject for participant1 + component.expect_message(|_| ()); + // Participant1 presence for participant2 + component.expect_presence(|_| ()); + // Participant2 presence for participant1 + component.expect_presence(|_| ()); + // Self-presence for participant2 + component.expect_presence(|_| ()); + // Subject for participant2 + component.expect_message(|_| ()); + + // Resync: Participant2 presence for participant1 + component.expect( + Presence::new(PresenceType::None) + .with_from(Jid::Full(participant2.clone())) + .with_to(Jid::Full(realjid1.clone())) + .with_payloads(vec![MucUser { + status: Vec::new(), + items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)], + } + .into()]), + ); + + // Resync: Participant1 self-presence + component.expect( + Presence::new(PresenceType::None) + .with_from(Jid::Full(participant1)) + .with_to(Jid::Full(realjid1.clone())) + .with_payloads(vec![MucUser { + status: vec![MucStatus::SelfPresence, MucStatus::AssignedNick], + items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)], + } + .into()]), + ); + + handle_stanza(&mut component, &mut rooms).await.unwrap(); + component.assert(); + + match rooms.get(&roomjid) { + Some(room) => assert_eq!(room.occupants.len(), 2), + None => panic!(), + } +} + + #[tokio::test] async fn test_leave_non_existing_room() { let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap();