diff --git a/src/tests/templates.rs b/src/tests/templates.rs index 01b74bd..e53d142 100644 --- a/src/tests/templates.rs +++ b/src/tests/templates.rs @@ -15,6 +15,7 @@ use crate::occupant::Occupant; use crate::room::Room; +use crate::session::Nick; use std::str::FromStr; use std::sync::LazyLock; use xmpp_parsers::{ @@ -101,3 +102,27 @@ pub fn two_participant_room(roomjid: BareJid) -> Room { ); room } + +// TODO: Fix this. Add yet another layer of struct that doesn't send stanzas so we don't need to +// duplicate Room code in here without all the safeguards? +pub async fn new_room>(roomjid: BareJid, sessions: Vec<(FullJid, N)>) -> Room { + let mut room = Room::new(roomjid.clone()); + for (session, nick) in sessions { + let nick: Nick = nick.into(); + + let participant = roomjid.clone().with_resource(nick.clone()); + let presence = Presence::new(PresenceType::None) + .with_to(participant) + .with_from(session); + + match room.occupants.get_mut(&nick) { + Some(occupant) => occupant.add_session(presence).unwrap(), + None => { + let _ = room + .occupants + .insert(nick.clone(), Occupant::new(presence).unwrap()); + } + }; + } + room +}