From a2cc7857b780a0c170eb42196c2ee6354dc97ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 16 Oct 2022 19:38:49 +0200 Subject: [PATCH] room: test_occupant_update_presence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/room.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/room.rs b/src/room.rs index 2bbec9e..948d060 100644 --- a/src/room.rs +++ b/src/room.rs @@ -915,4 +915,65 @@ mod tests { .await .unwrap(); } + + #[tokio::test] + async fn test_occupant_update_presence() { + let presence_louise1 = Presence::new(PresenceType::None) + .with_from(LOUISE_FULL1.clone()) + .with_to(LOUISE_ROOM1_PART.clone()); + let presence_louise2 = Presence::new(PresenceType::None) + .with_from(LOUISE_FULL2.clone()) + .with_to(LOUISE_ROOM1_PART.clone()); + + let mut occupant = Occupant::new(presence_louise1).unwrap(); + occupant.add_session(presence_louise2).unwrap(); + + let presence1 = Presence::new(PresenceType::None) + .with_from(LOUISE_FULL1.clone()) + .with_to(ROOM1_BARE.clone()) + .with_show(PresenceShow::Away) + .with_payloads(vec![ + Muc::new().into(), + MucUser { + status: Vec::new(), + items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)], + } + .into(), + ]); + match occupant.update_presence(presence1.clone()) { + Ok(()) => (), + err => panic!("Err: {:?}", err), + } + assert_eq!(occupant.sessions[0].presence, presence1); + + let presence2 = Presence::new(PresenceType::None) + .with_from(LOUISE_FULL2.clone()) + .with_to(ROOM1_BARE.clone()) + .with_show(PresenceShow::Xa); + + match occupant.update_presence(presence2.clone()) { + Err(Error::SecondarySession(session)) if session.real == *LOUISE_FULL2 => (), + err => panic!( + "Should return Error::SecondarySession(Session {{ {:?} }}), returned: {:?}", + *LOUISE_FULL2, err, + ), + } + assert_eq!( + occupant.sessions[1], + Session::with_nick(presence2.clone(), LOUISE_NICK.clone()).unwrap() + ); + + let presence_leave_louise2 = Presence::new(PresenceType::Unavailable) + .with_from(LOUISE_FULL2.clone()) + .with_to(LOUISE_ROOM1_PART.clone()); + occupant.remove_session(presence_leave_louise2).unwrap(); + + match occupant.update_presence(presence2) { + Err(Error::NonexistantSession(session)) if session.real == *LOUISE_FULL2 => (), + err => panic!( + "Should return Error::SecondarySession(Session {{ {:?} }}), returned: {:?}", + *LOUISE_FULL2, err, + ), + } + } }