base: Test the invited room creation.
parent
fff3abf985
commit
77a8f1b1bc
|
@ -1432,7 +1432,10 @@ impl BaseClient {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::identifiers::{RoomId, UserId};
|
use crate::identifiers::{RoomId, UserId};
|
||||||
use crate::{events::collections::all::RoomEvent, BaseClient, Session};
|
use crate::{
|
||||||
|
events::{collections::all::RoomEvent, stripped::AnyStrippedStateEvent},
|
||||||
|
BaseClient, Session,
|
||||||
|
};
|
||||||
use matrix_sdk_test::{async_test, EventBuilder, EventsFile};
|
use matrix_sdk_test::{async_test, EventBuilder, EventsFile};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
@ -1453,6 +1456,21 @@ mod test {
|
||||||
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
|
RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn member_event() -> serde_json::Value {
|
||||||
|
json!({
|
||||||
|
"content": {
|
||||||
|
"displayname": "example",
|
||||||
|
"membership": "join"
|
||||||
|
},
|
||||||
|
"event_id": "$151800140517rfvjc:localhost",
|
||||||
|
"membership": "join",
|
||||||
|
"origin_server_ts": 0,
|
||||||
|
"sender": "@example:localhost",
|
||||||
|
"state_key": "@example:localhost",
|
||||||
|
"type": "m.room.member",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[async_test]
|
#[async_test]
|
||||||
async fn test_joined_room_creation() {
|
async fn test_joined_room_creation() {
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
|
@ -1461,12 +1479,35 @@ mod test {
|
||||||
let client = get_client();
|
let client = get_client();
|
||||||
let room_id = get_room_id();
|
let room_id = get_room_id();
|
||||||
|
|
||||||
|
let room = client.get_joined_room(&room_id).await;
|
||||||
|
assert!(room.is_none());
|
||||||
|
|
||||||
|
client
|
||||||
|
.receive_sync_response(&mut sync_response)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let room = client.get_left_room(&room_id).await;
|
||||||
|
assert!(room.is_none());
|
||||||
|
|
||||||
|
let room = client.get_joined_room(&room_id).await;
|
||||||
|
assert!(room.is_some());
|
||||||
|
|
||||||
|
let mut sync_response = EventBuilder::default()
|
||||||
|
.add_custom_left_event(&room_id, member_event(), RoomEvent::RoomMember)
|
||||||
|
.build_sync_response();
|
||||||
|
|
||||||
|
sync_response.next_batch = "Hello".to_owned();
|
||||||
|
|
||||||
client
|
client
|
||||||
.receive_sync_response(&mut sync_response)
|
.receive_sync_response(&mut sync_response)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let room = client.get_joined_room(&room_id).await;
|
let room = client.get_joined_room(&room_id).await;
|
||||||
|
assert!(room.is_none());
|
||||||
|
|
||||||
|
let room = client.get_left_room(&room_id).await;
|
||||||
assert!(room.is_some());
|
assert!(room.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1474,26 +1515,14 @@ mod test {
|
||||||
async fn test_left_room_creation() {
|
async fn test_left_room_creation() {
|
||||||
let room_id = RoomId::try_from("!left_room:localhost").unwrap();
|
let room_id = RoomId::try_from("!left_room:localhost").unwrap();
|
||||||
let mut sync_response = EventBuilder::default()
|
let mut sync_response = EventBuilder::default()
|
||||||
.add_custom_left_event(
|
.add_custom_left_event(&room_id, member_event(), RoomEvent::RoomMember)
|
||||||
&room_id,
|
|
||||||
json!({
|
|
||||||
"content": {
|
|
||||||
"displayname": "example",
|
|
||||||
"membership": "join"
|
|
||||||
},
|
|
||||||
"event_id": "$151800140517rfvjc:localhost",
|
|
||||||
"membership": "join",
|
|
||||||
"origin_server_ts": 0,
|
|
||||||
"sender": "@example:localhost",
|
|
||||||
"state_key": "@example:localhost",
|
|
||||||
"type": "m.room.member",
|
|
||||||
}),
|
|
||||||
RoomEvent::RoomMember,
|
|
||||||
)
|
|
||||||
.build_sync_response();
|
.build_sync_response();
|
||||||
|
|
||||||
let client = get_client();
|
let client = get_client();
|
||||||
|
|
||||||
|
let room = client.get_left_room(&room_id).await;
|
||||||
|
assert!(room.is_none());
|
||||||
|
|
||||||
client
|
client
|
||||||
.receive_sync_response(&mut sync_response)
|
.receive_sync_response(&mut sync_response)
|
||||||
.await
|
.await
|
||||||
|
@ -1501,5 +1530,60 @@ mod test {
|
||||||
|
|
||||||
let room = client.get_left_room(&room_id).await;
|
let room = client.get_left_room(&room_id).await;
|
||||||
assert!(room.is_some());
|
assert!(room.is_some());
|
||||||
|
|
||||||
|
let mut sync_response = EventBuilder::default()
|
||||||
|
.add_custom_joined_event(&room_id, member_event(), RoomEvent::RoomMember)
|
||||||
|
.build_sync_response();
|
||||||
|
|
||||||
|
sync_response.next_batch = "Hello".to_owned();
|
||||||
|
|
||||||
|
client
|
||||||
|
.receive_sync_response(&mut sync_response)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let room = client.get_left_room(&room_id).await;
|
||||||
|
assert!(room.is_none());
|
||||||
|
|
||||||
|
let room = client.get_joined_room(&room_id).await;
|
||||||
|
assert!(room.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_test]
|
||||||
|
async fn test_invited_room_creation() {
|
||||||
|
let room_id = RoomId::try_from("!invited_room:localhost").unwrap();
|
||||||
|
let mut sync_response = EventBuilder::default()
|
||||||
|
.add_custom_invited_event(&room_id, member_event(), AnyStrippedStateEvent::RoomMember)
|
||||||
|
.build_sync_response();
|
||||||
|
|
||||||
|
let client = get_client();
|
||||||
|
|
||||||
|
let room = client.get_invited_room(&room_id).await;
|
||||||
|
assert!(room.is_none());
|
||||||
|
|
||||||
|
client
|
||||||
|
.receive_sync_response(&mut sync_response)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let room = client.get_invited_room(&room_id).await;
|
||||||
|
assert!(room.is_some());
|
||||||
|
|
||||||
|
let mut sync_response = EventBuilder::default()
|
||||||
|
.add_custom_joined_event(&room_id, member_event(), RoomEvent::RoomMember)
|
||||||
|
.build_sync_response();
|
||||||
|
|
||||||
|
sync_response.next_batch = "Hello".to_owned();
|
||||||
|
|
||||||
|
client
|
||||||
|
.receive_sync_response(&mut sync_response)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let room = client.get_invited_room(&room_id).await;
|
||||||
|
assert!(room.is_none());
|
||||||
|
|
||||||
|
let room = client.get_joined_room(&room_id).await;
|
||||||
|
assert!(room.is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ impl EventBuilder {
|
||||||
|
|
||||||
pub fn add_custom_joined_event<Ev: TryFromRaw>(
|
pub fn add_custom_joined_event<Ev: TryFromRaw>(
|
||||||
mut self,
|
mut self,
|
||||||
|
room_id: &RoomId,
|
||||||
event: serde_json::Value,
|
event: serde_json::Value,
|
||||||
variant: fn(Ev) -> RoomEvent,
|
variant: fn(Ev) -> RoomEvent,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -134,10 +135,7 @@ impl EventBuilder {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.deserialize()
|
.deserialize()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.add_joined_event(
|
self.add_joined_event(room_id, variant(event));
|
||||||
&RoomId::try_from("!SVkFJHzfwvuaIEawgC:localhost").unwrap(),
|
|
||||||
variant(event),
|
|
||||||
);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +288,17 @@ impl EventBuilder {
|
||||||
left_rooms.insert(room_id, room);
|
left_rooms.insert(room_id, room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut invited_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
|
||||||
|
|
||||||
|
for (room_id, events) in self.invited_room_events.drain() {
|
||||||
|
let room = serde_json::json!({
|
||||||
|
"invite_state": {
|
||||||
|
"events": events,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
invited_rooms.insert(room_id, room);
|
||||||
|
}
|
||||||
|
|
||||||
let body = serde_json::json! {
|
let body = serde_json::json! {
|
||||||
{
|
{
|
||||||
"device_one_time_keys_count": {},
|
"device_one_time_keys_count": {},
|
||||||
|
@ -299,7 +308,7 @@ impl EventBuilder {
|
||||||
"left": []
|
"left": []
|
||||||
},
|
},
|
||||||
"rooms": {
|
"rooms": {
|
||||||
"invite": {},
|
"invite": invited_rooms,
|
||||||
"join": joined_rooms,
|
"join": joined_rooms,
|
||||||
"leave": left_rooms,
|
"leave": left_rooms,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue