Add back ruma-events/tests/stripped.rs
This commit is contained in:
parent
9074e4c17a
commit
3ec0936a28
@ -3,24 +3,21 @@ use std::convert::TryFrom;
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_events::{
|
use ruma_events::{
|
||||||
room::{join_rules::JoinRule, topic::TopicEventContent},
|
room::{join_rules::JoinRule, topic::TopicEventContent},
|
||||||
AnyStrippedStateEvent, EventJson, EventType,
|
AnyStateEventContent, AnyStrippedStateEventStub,
|
||||||
};
|
};
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_stripped_state_event() {
|
fn serialize_stripped_state_event() {
|
||||||
let content = StrippedRoomTopic {
|
let event = AnyStrippedStateEventStub {
|
||||||
content: TopicEventContent {
|
content: AnyStateEventContent::RoomTopic(TopicEventContent {
|
||||||
topic: "Testing room".to_string(),
|
topic: "Testing room".to_string(),
|
||||||
},
|
}),
|
||||||
state_key: "".to_string(),
|
state_key: "".to_string(),
|
||||||
event_type: EventType::RoomTopic,
|
|
||||||
sender: UserId::try_from("@example:localhost").unwrap(),
|
sender: UserId::try_from("@example:localhost").unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = AnyStrippedStateEvent::RoomTopic(content);
|
|
||||||
|
|
||||||
let json_data = json!({
|
let json_data = json!({
|
||||||
"content": {
|
"content": {
|
||||||
"topic": "Testing room"
|
"topic": "Testing room"
|
||||||
@ -78,47 +75,30 @@ fn deserialize_stripped_state_events() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
match from_json_value::<EventJson<_>>(name_event.clone())
|
let event = from_json_value::<AnyStrippedStateEventStub>(name_event).unwrap();
|
||||||
.unwrap()
|
match event.content {
|
||||||
.deserialize()
|
AnyStateEventContent::RoomName(content) => {
|
||||||
.unwrap()
|
assert_eq!(content.name(), Some("Ruma"));
|
||||||
{
|
|
||||||
AnyStrippedStateEvent::RoomName(event) => {
|
|
||||||
assert_eq!(event.content.name, Some("Ruma".to_string()));
|
|
||||||
assert_eq!(event.event_type, EventType::RoomName);
|
|
||||||
assert_eq!(event.state_key, "");
|
assert_eq!(event.state_key, "");
|
||||||
assert_eq!(event.sender.to_string(), "@example:localhost");
|
assert_eq!(event.sender.to_string(), "@example:localhost");
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
}
|
||||||
|
|
||||||
// Ensure `StrippedStateContent` can be parsed, not just `StrippedState`.
|
let event = from_json_value::<AnyStrippedStateEventStub>(join_rules_event).unwrap();
|
||||||
assert!(from_json_value::<EventJson<StrippedRoomName>>(name_event)
|
match event.content {
|
||||||
.unwrap()
|
AnyStateEventContent::RoomJoinRules(content) => {
|
||||||
.deserialize()
|
assert_eq!(content.join_rule, JoinRule::Public);
|
||||||
.is_ok());
|
|
||||||
|
|
||||||
match from_json_value::<EventJson<_>>(join_rules_event)
|
|
||||||
.unwrap()
|
|
||||||
.deserialize()
|
|
||||||
.unwrap()
|
|
||||||
{
|
|
||||||
AnyStrippedStateEvent::RoomJoinRules(event) => {
|
|
||||||
assert_eq!(event.content.join_rule, JoinRule::Public);
|
|
||||||
assert_eq!(event.event_type, EventType::RoomJoinRules);
|
|
||||||
assert_eq!(event.state_key, "");
|
assert_eq!(event.state_key, "");
|
||||||
assert_eq!(event.sender.to_string(), "@example:localhost");
|
assert_eq!(event.sender.to_string(), "@example:localhost");
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
}
|
||||||
|
|
||||||
match from_json_value::<EventJson<_>>(avatar_event)
|
let event = from_json_value::<AnyStrippedStateEventStub>(avatar_event).unwrap();
|
||||||
.unwrap()
|
match event.content {
|
||||||
.deserialize()
|
AnyStateEventContent::RoomAvatar(content) => {
|
||||||
.unwrap()
|
let image_info = content.info.unwrap();
|
||||||
{
|
|
||||||
AnyStrippedStateEvent::RoomAvatar(event) => {
|
|
||||||
let image_info = event.content.info.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(image_info.height.unwrap(), UInt::try_from(128).unwrap());
|
assert_eq!(image_info.height.unwrap(), UInt::try_from(128).unwrap());
|
||||||
assert_eq!(image_info.width.unwrap(), UInt::try_from(128).unwrap());
|
assert_eq!(image_info.width.unwrap(), UInt::try_from(128).unwrap());
|
||||||
@ -128,11 +108,10 @@ fn deserialize_stripped_state_events() {
|
|||||||
image_info.thumbnail_info.unwrap().size.unwrap(),
|
image_info.thumbnail_info.unwrap().size.unwrap(),
|
||||||
UInt::try_from(32).unwrap()
|
UInt::try_from(32).unwrap()
|
||||||
);
|
);
|
||||||
assert_eq!(event.content.url, "https://example.com/image.jpg");
|
assert_eq!(content.url, "https://example.com/image.jpg");
|
||||||
assert_eq!(event.event_type, EventType::RoomAvatar);
|
|
||||||
assert_eq!(event.state_key, "");
|
assert_eq!(event.state_key, "");
|
||||||
assert_eq!(event.sender.to_string(), "@example:localhost");
|
assert_eq!(event.sender.to_string(), "@example:localhost");
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user