tests/presence: implement updated_joined

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-12-27 00:33:39 +01:00
parent db764b18f7
commit 7472bc1398
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
3 changed files with 30 additions and 8 deletions

View file

@ -94,7 +94,7 @@ impl Room {
.into()]);
// New participant to all other sessions
let presence_to_old = Presence::new(if leave {
let mut presence_to_old = Presence::new(if leave {
PresenceType::Unavailable
} else {
PresenceType::None
@ -109,6 +109,9 @@ impl Room {
}
.into()]);
// Populate presence with newly received payloads
own_session.fill_presence(&mut presence_to_old);
for (_, other) in self.occupants.iter() {
// Skip sending to all our sessions, we do it later.
if own_occupant.nick == other.nick {

View file

@ -54,6 +54,15 @@ impl Session {
_ => unreachable!(),
}
}
pub fn fill_presence(&self, presence: &mut Presence) {
presence.priority = self.presence.priority;
presence.show = self.presence.show.clone();
presence.statuses = self.presence.statuses.clone();
for elem in self.presence.payloads.clone().into_iter() {
presence.payloads.push(elem);
}
}
}
impl PartialEq for Session {

View file

@ -18,7 +18,8 @@ use crate::handlers::handle_stanza;
use crate::room::Room;
use crate::tests::templates::{
new_room, two_participant_room, LOUISE_FULL1, LOUISE_FULL2, LOUISE_NICK, LOUISE_ROOM1_PART,
ROOM1_BARE, ROSA_FULL1, ROSA_ROOM1_PART, SUGAKO_FULL1, SUGAKO_NICK, SUGAKO_ROOM1_PART,
PETER_FULL1, PETER_NICK, PETER_ROOM1_PART, ROOM1_BARE, ROSA_FULL1, ROSA_ROOM1_PART,
SUGAKO_FULL1, SUGAKO_NICK, SUGAKO_ROOM1_PART,
};
use std::collections::{BTreeMap, HashMap};
@ -604,15 +605,24 @@ async fn test_join_msn() {
}
}
#[ignore]
#[tokio::test]
async fn test_presence_update_joined() {
let mut rooms: HashMap<BareJid, Room> = HashMap::new();
rooms.insert(ROOM1_BARE.clone(), two_participant_room(ROOM1_BARE.clone()));
rooms.insert(
ROOM1_BARE.clone(),
new_room(
ROOM1_BARE.clone(),
vec![
(SUGAKO_FULL1.clone(), SUGAKO_NICK),
(PETER_FULL1.clone(), PETER_NICK),
],
)
.await,
);
let update1: Element = Presence::new(PresenceType::None)
.with_from(Jid::Full(SUGAKO_FULL1.clone()))
.with_to(Jid::Full(SUGAKO_ROOM1_PART.clone()))
.with_from(Jid::Full(PETER_FULL1.clone()))
.with_to(Jid::Full(PETER_ROOM1_PART.clone()))
.with_show(PresenceShow::Away)
.into();
@ -620,8 +630,8 @@ async fn test_presence_update_joined() {
component.expect(
Presence::new(PresenceType::None)
.with_from(Jid::Full(SUGAKO_ROOM1_PART.clone()))
.with_to(Jid::Full(LOUISE_FULL1.clone()))
.with_from(Jid::Full(PETER_ROOM1_PART.clone()))
.with_to(Jid::Full(SUGAKO_FULL1.clone()))
.with_payloads(vec![MucUser {
status: Vec::new(),
items: vec![MucItem::new(Affiliation::Owner, Role::Moderator)],