Merge branch 'msg-tests'
commit
8869da0a38
|
@ -11,7 +11,7 @@ repository = "https://github.com/matrix-org/matrix-rust-sdk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["encryption", "sqlite-cryptostore"]
|
default = ["encryption", "sqlite-cryptostore", "messages"]
|
||||||
messages = []
|
messages = []
|
||||||
encryption = ["matrix-sdk-crypto"]
|
encryption = ["matrix-sdk-crypto"]
|
||||||
sqlite-cryptostore = ["matrix-sdk-crypto/sqlite-cryptostore"]
|
sqlite-cryptostore = ["matrix-sdk-crypto/sqlite-cryptostore"]
|
||||||
|
|
|
@ -161,104 +161,42 @@ mod test {
|
||||||
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
|
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
|
||||||
|
|
||||||
let mut msgs = MessageQueue::new();
|
let mut msgs = MessageQueue::new();
|
||||||
if let Ok(ev) = event.deserialize() {
|
let message = if let RoomEvent::RoomMessage(msg) = event.deserialize().unwrap() {
|
||||||
if let RoomEvent::RoomMessage(msg) = ev {
|
msgs.push(msg.clone());
|
||||||
msgs.push(msg);
|
msg
|
||||||
}
|
} else {
|
||||||
}
|
panic!("this should always be a RoomMessage")
|
||||||
room.messages = msgs;
|
};
|
||||||
|
room.messages = msgs.clone();
|
||||||
|
|
||||||
let mut joined_rooms = HashMap::new();
|
let mut joined_rooms = HashMap::new();
|
||||||
joined_rooms.insert(id, room);
|
joined_rooms.insert(id, room);
|
||||||
|
|
||||||
// println!("{}", serde_json::to_string_pretty(&joined_rooms).unwrap());
|
|
||||||
|
|
||||||
// this is the correct JSON string changes to `ruma-events` have not been released
|
|
||||||
// that would fix the doubling of fields
|
|
||||||
// TODO uncomment when fixed
|
|
||||||
// assert_eq!(
|
|
||||||
// r#"{
|
|
||||||
// "!roomid:example.com": {
|
|
||||||
// "room_id": "!roomid:example.com",
|
|
||||||
// "room_name": {
|
|
||||||
// "name": null,
|
|
||||||
// "canonical_alias": null,
|
|
||||||
// "aliases": [],
|
|
||||||
// "heroes": [],
|
|
||||||
// "joined_member_count": null,
|
|
||||||
// "invited_member_count": null
|
|
||||||
// },
|
|
||||||
// "own_user_id": "@example:example.com",
|
|
||||||
// "creator": null,
|
|
||||||
// "members": {},
|
|
||||||
// "messages": [
|
|
||||||
// {
|
|
||||||
// "type": "m.room.message",
|
|
||||||
// "content": {
|
|
||||||
// "body": "is dancing",
|
|
||||||
// "format": "org.matrix.custom.html",
|
|
||||||
// "formatted_body": "<strong>is dancing</strong>",
|
|
||||||
// "msgtype": "m.text"
|
|
||||||
// },
|
|
||||||
// "event_id": "$152037280074GZeOm:localhost",
|
|
||||||
// "origin_server_ts": 1520372800469,
|
|
||||||
// "sender": "@example:localhost",
|
|
||||||
// "unsigned": {
|
|
||||||
// "age": 598971425
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// "typing_users": [],
|
|
||||||
// "power_levels": null,
|
|
||||||
// "encrypted": false,
|
|
||||||
// "unread_highlight": null,
|
|
||||||
// "unread_notifications": null,
|
|
||||||
// "tombstone": null
|
|
||||||
// }
|
|
||||||
// }"#,
|
|
||||||
// serde_json::to_string_pretty(&joined_rooms).unwrap()
|
|
||||||
// );
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
r#"{
|
serde_json::json!({
|
||||||
"!roomid:example.com": {
|
"!roomid:example.com": {
|
||||||
"room_id": "!roomid:example.com",
|
"room_id": "!roomid:example.com",
|
||||||
"room_name": {
|
"room_name": {
|
||||||
"name": null,
|
"name": null,
|
||||||
"canonical_alias": null,
|
"canonical_alias": null,
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"heroes": [],
|
"heroes": [],
|
||||||
"joined_member_count": null,
|
"joined_member_count": null,
|
||||||
"invited_member_count": null
|
"invited_member_count": null
|
||||||
},
|
},
|
||||||
"own_user_id": "@example:example.com",
|
"own_user_id": "@example:example.com",
|
||||||
"creator": null,
|
"creator": null,
|
||||||
"members": {},
|
"members": {},
|
||||||
"messages": [
|
"messages": [ message ],
|
||||||
{
|
"typing_users": [],
|
||||||
"content": {
|
"power_levels": null,
|
||||||
"msgtype": "m.text",
|
"encrypted": null,
|
||||||
"msgtype": "m.text",
|
"unread_highlight": null,
|
||||||
"body": "is dancing",
|
"unread_notifications": null,
|
||||||
"format": "org.matrix.custom.html",
|
"tombstone": null
|
||||||
"formatted_body": "<strong>is dancing</strong>"
|
}
|
||||||
},
|
}),
|
||||||
"event_id": "$152037280074GZeOm:localhost",
|
serde_json::to_value(&joined_rooms).unwrap()
|
||||||
"origin_server_ts": 1520372800469,
|
|
||||||
"sender": "@example:localhost",
|
|
||||||
"unsigned": {
|
|
||||||
"age": 598971425
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"typing_users": [],
|
|
||||||
"power_levels": null,
|
|
||||||
"encrypted": false,
|
|
||||||
"unread_highlight": null,
|
|
||||||
"unread_notifications": null,
|
|
||||||
"tombstone": null
|
|
||||||
}
|
|
||||||
}"#,
|
|
||||||
serde_json::to_string_pretty(&joined_rooms).unwrap()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,58 +211,43 @@ mod test {
|
||||||
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
|
let event = serde_json::from_str::<EventJson<RoomEvent>>(&json).unwrap();
|
||||||
|
|
||||||
let mut msgs = MessageQueue::new();
|
let mut msgs = MessageQueue::new();
|
||||||
if let Ok(ev) = event.deserialize() {
|
let message = if let RoomEvent::RoomMessage(msg) = event.deserialize().unwrap() {
|
||||||
if let RoomEvent::RoomMessage(msg) = ev {
|
msgs.push(msg.clone());
|
||||||
msgs.push(msg);
|
msg
|
||||||
}
|
} else {
|
||||||
}
|
panic!("this should always be a RoomMessage")
|
||||||
|
};
|
||||||
room.messages = msgs;
|
room.messages = msgs;
|
||||||
|
|
||||||
let mut joined_rooms = HashMap::new();
|
let mut joined_rooms = HashMap::new();
|
||||||
joined_rooms.insert(id, room.clone());
|
joined_rooms.insert(id, room.clone());
|
||||||
|
|
||||||
let json = r#"{
|
let json = serde_json::json!({
|
||||||
"!roomid:example.com": {
|
"!roomid:example.com": {
|
||||||
"room_id": "!roomid:example.com",
|
"room_id": "!roomid:example.com",
|
||||||
"room_name": {
|
"room_name": {
|
||||||
"name": null,
|
"name": null,
|
||||||
"canonical_alias": null,
|
"canonical_alias": null,
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"heroes": [],
|
"heroes": [],
|
||||||
"joined_member_count": null,
|
"joined_member_count": null,
|
||||||
"invited_member_count": null
|
"invited_member_count": null
|
||||||
},
|
},
|
||||||
"own_user_id": "@example:example.com",
|
"own_user_id": "@example:example.com",
|
||||||
"creator": null,
|
"creator": null,
|
||||||
"members": {},
|
"members": {},
|
||||||
"messages": [
|
"messages": [ message ],
|
||||||
{
|
"typing_users": [],
|
||||||
"type": "m.room.message",
|
"power_levels": null,
|
||||||
"content": {
|
"encrypted": null,
|
||||||
"body": "is dancing",
|
"unread_highlight": null,
|
||||||
"format": "org.matrix.custom.html",
|
"unread_notifications": null,
|
||||||
"formatted_body": "<strong>is dancing</strong>",
|
"tombstone": null
|
||||||
"msgtype": "m.text"
|
}
|
||||||
},
|
});
|
||||||
"event_id": "$152037280074GZeOm:localhost",
|
|
||||||
"origin_server_ts": 1520372800469,
|
|
||||||
"sender": "@example:localhost",
|
|
||||||
"unsigned": {
|
|
||||||
"age": 598971425
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"typing_users": [],
|
|
||||||
"power_levels": null,
|
|
||||||
"encrypted": false,
|
|
||||||
"unread_highlight": null,
|
|
||||||
"unread_notifications": null,
|
|
||||||
"tombstone": null
|
|
||||||
}
|
|
||||||
}"#;
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
joined_rooms,
|
joined_rooms,
|
||||||
serde_json::from_str::<HashMap<RoomId, Room>>(json).unwrap()
|
serde_json::from_value::<HashMap<RoomId, Room>>(json).unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue