Skip to content

Commit

Permalink
test: Add test that MUC owners/admins/members with no node are ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
nesium committed Aug 22, 2024
1 parent d95550b commit cae6145
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions tests/prose-core-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
chrono = { workspace = true }
ctor = "0.2"
itertools = { workspace = true }
jid = { workspace = true }
minidom = { workspace = true }
parking_lot = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use anyhow::Result;
use chrono::{DateTime, Duration, Utc};
use jid::BareJid;
use minidom::{Element, IntoAttributeValue};
use xmpp_parsers::mam::QueryId;

Expand All @@ -26,9 +27,9 @@ pub struct JoinRoomStrategy {
pub room_name: String,
pub room_type: RoomType,
pub room_settings: Option<SyncedRoomSettings>,
pub owners: Vec<UserId>,
pub members: Vec<UserId>,
pub admins: Vec<UserId>,
pub owners: Vec<BareJid>,
pub members: Vec<BareJid>,
pub admins: Vec<BareJid>,
pub user_affiliation: RoomAffiliation,
pub receive_occupant_presences: Box<dyn FnOnce(&TestClient, &MucId)>,
pub expect_catchup: Box<dyn FnOnce(&TestClient, &MucId)>,
Expand Down Expand Up @@ -87,17 +88,17 @@ impl JoinRoomStrategy {
self
}

pub fn with_owners(mut self, owners: impl IntoIterator<Item = UserId>) -> Self {
pub fn with_owners(mut self, owners: impl IntoIterator<Item = BareJid>) -> Self {
self.owners = owners.into_iter().collect();
self
}

pub fn with_admins(mut self, admins: impl IntoIterator<Item = UserId>) -> Self {
pub fn with_admins(mut self, admins: impl IntoIterator<Item = BareJid>) -> Self {
self.admins = admins.into_iter().collect();
self
}

pub fn with_members(mut self, members: impl IntoIterator<Item = UserId>) -> Self {
pub fn with_members(mut self, members: impl IntoIterator<Item = BareJid>) -> Self {
self.members = members.into_iter().collect();
self
}
Expand Down Expand Up @@ -262,7 +263,7 @@ impl TestClient {
fn expect_load_affiliations(
client: &TestClient,
affiliation: RoomAffiliation,
users: impl IntoIterator<Item = UserId>,
users: impl IntoIterator<Item = BareJid>,
) {
let users = users
.into_iter()
Expand Down Expand Up @@ -305,7 +306,7 @@ impl TestClient {
RoomAffiliation::Owner,
strategy.owners.into_iter().chain(
(strategy.user_affiliation == RoomAffiliation::Owner)
.then_some(current_user_id.clone()),
.then_some(current_user_id.clone().into_inner()),
),
);

Expand All @@ -314,7 +315,7 @@ impl TestClient {
RoomAffiliation::Member,
strategy.members.into_iter().chain(
(strategy.user_affiliation == RoomAffiliation::Member)
.then_some(current_user_id.clone()),
.then_some(current_user_id.clone().into_inner()),
),
);

Expand All @@ -323,7 +324,7 @@ impl TestClient {
RoomAffiliation::Admin,
strategy.admins.into_iter().chain(
(strategy.user_affiliation == RoomAffiliation::Admin)
.then_some(current_user_id.clone()),
.then_some(current_user_id.clone().into_inner()),
),
);

Expand Down Expand Up @@ -789,7 +790,7 @@ impl RoomResponse for RoomType {
</query>
</iq>
"#
},
}
RoomType::PrivateChannel => unimplemented!(),
RoomType::PublicChannel => {
r#"
Expand Down
29 changes: 24 additions & 5 deletions tests/prose-core-integration-tests/src/tests/client/muc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ use anyhow::Result;
use jid::BareJid;
use pretty_assertions::assert_eq;

use super::helpers::{JoinRoomStrategy, TestClient};
use crate::{event, recv, room_event, send};
use itertools::Itertools;
use prose_core_client::domain::shared::models::AnonOccupantId;
use prose_core_client::domain::sidebar::models::BookmarkType;
use prose_core_client::dtos::{
MucId, ParticipantId, SendMessageRequest, SendMessageRequestBody, UserId,
};
use prose_core_client::{muc_id, user_id, ClientEvent, ClientRoomEventType};
use prose_proc_macros::mt_test;

use crate::{event, recv, room_event, send};

use super::helpers::TestClient;
use prose_xmpp::bare;

#[mt_test]
async fn test_joins_room() -> Result<()> {
Expand All @@ -27,10 +27,29 @@ async fn test_joins_room() -> Result<()> {
.expect_login(user_id!("[email protected]"), "secret")
.await?;

let strategy = JoinRoomStrategy::default().with_owners([
bare!("[email protected]"),
// Some rooms may have owners that where the JID doesn't have a node. These should
// be ignored for now.
bare!("prose.org"),
]);

client
.join_room(muc_id!("[email protected]"), "anon-id")
.join_room_with_strategy(muc_id!("[email protected]"), "anon-id", strategy)
.await?;

let room = client.get_room(muc_id!("[email protected]")).await;

assert_eq!(
vec![user_id!("[email protected]"), user_id!("[email protected]")],
room.to_generic_room()
.participants()
.into_iter()
.filter_map(|p| p.user_id)
.sorted()
.collect::<Vec<_>>()
);

Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async fn test_joins_room() -> Result<()> {
"#
)
}).with_members(
[user_id!("[email protected]")]
[bare!("[email protected]")]
);

client
Expand Down

0 comments on commit cae6145

Please sign in to comment.