room: test_occupant_update_presence

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-10-16 19:38:49 +02:00
parent fc880c7423
commit a2cc7857b7
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -915,4 +915,65 @@ mod tests {
.await .await
.unwrap(); .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,
),
}
}
} }