Add test and example event to ensure display name changes work correctly.

This commit is contained in:
Denis Kasak 2020-07-01 14:50:42 +02:00
parent f447c55fcb
commit 2a0c6c6474
4 changed files with 74 additions and 2 deletions

View file

@ -253,6 +253,50 @@ mod test {
assert_eq!(member.power_level, Int::new(100));
}
#[async_test]
async fn room_member_display_name_change() {
let client = get_client().await;
let room_id = test_room_id();
let mut builder = EventBuilder::default();
let mut initial_response = builder
.add_room_event(EventsJson::Member, RoomEvent::RoomMember)
.build_sync_response();
let mut name_change_response = builder
.add_room_event(EventsJson::MemberNameChange, RoomEvent::RoomMember)
.build_sync_response();
client.receive_sync_response(&mut initial_response).await.unwrap();
let room = client.get_joined_room(&room_id).await.unwrap();
// Initially, the display name is "example".
{
let room = room.read().await;
let member = room
.joined_members
.get(&UserId::try_from("@example:localhost").unwrap())
.unwrap();
assert_eq!(member.display_name.as_ref().unwrap(), "example");
}
client.receive_sync_response(&mut name_change_response).await.unwrap();
// Afterwards, the display name is "changed".
{
let room = room.read().await;
let member = room
.joined_members
.get(&UserId::try_from("@example:localhost").unwrap())
.unwrap();
assert_eq!(member.display_name.as_ref().unwrap(), "changed");
}
}
#[async_test]
async fn member_presence_events() {
let client = get_client().await;

View file

@ -31,6 +31,7 @@ pub enum EventsJson {
HistoryVisibility,
JoinRules,
Member,
MemberNameChange,
MessageEmote,
MessageNotice,
MessageText,
@ -154,6 +155,7 @@ impl EventBuilder {
) -> &mut Self {
let val: &JsonValue = match json {
EventsJson::Member => &test_json::MEMBER,
EventsJson::MemberNameChange => &test_json::MEMBER_NAME_CHANGE,
EventsJson::PowerLevels => &test_json::POWER_LEVELS,
_ => panic!("unknown room event json {:?}", json),
};

View file

@ -234,6 +234,32 @@ lazy_static! {
});
}
// TODO: Move `prev_content` into `unsigned` once ruma supports it
lazy_static! {
pub static ref MEMBER_NAME_CHANGE: JsonValue = json!({
"content": {
"avatar_url": null,
"displayname": "changed",
"membership": "join"
},
"event_id": "$151800234427abgho:localhost",
"membership": "join",
"origin_server_ts": 151800152,
"sender": "@example:localhost",
"state_key": "@example:localhost",
"type": "m.room.member",
"prev_content": {
"avatar_url": null,
"displayname": "example",
"membership": "join"
},
"unsigned": {
"age": 297032,
"replaces_state": "$151800140517rfvjc:localhost"
}
});
}
lazy_static! {
pub static ref MESSAGE_EDIT: JsonValue = json!({
"content": {

View file

@ -9,7 +9,7 @@ pub mod sync;
pub use events::{
ALIAS, ALIASES, EVENT_ID, KEYS_QUERY, KEYS_UPLOAD, LOGIN, LOGIN_RESPONSE_ERR, LOGOUT, MEMBER,
MESSAGE_EDIT, MESSAGE_TEXT, NAME, POWER_LEVELS, PRESENCE, PUBLIC_ROOMS, REACTION,
REGISTRATION_RESPONSE_ERR, ROOM_ID, ROOM_MESSAGES, TYPING,
MEMBER_NAME_CHANGE, MESSAGE_EDIT, MESSAGE_TEXT, NAME, POWER_LEVELS, PRESENCE, PUBLIC_ROOMS,
REACTION, REGISTRATION_RESPONSE_ERR, ROOM_ID, ROOM_MESSAGES, TYPING,
};
pub use sync::{DEFAULT_SYNC_SUMMARY, INVITE_SYNC, LEAVE_SYNC, LEAVE_SYNC_EVENT, MORE_SYNC, SYNC};