events: Split more test assertions
This commit is contained in:
parent
f0a8e14582
commit
7008161727
@ -206,24 +206,22 @@ fn plain_content_deserialization() {
|
||||
]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<ImageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
ImageEventContent { message, file, image, thumbnail, caption: Some(caption), .. }
|
||||
if message.find_plain() == Some("Upload: my_cat.png")
|
||||
&& message.find_html().is_none()
|
||||
&& file.url == "mxc://notareal.hs/abcdef"
|
||||
&& image.width == Some(uint!(668))
|
||||
&& image.height.is_none()
|
||||
&& thumbnail.is_empty()
|
||||
&& caption.find_plain() == Some("Look at my cat!")
|
||||
);
|
||||
let content = from_json_value::<ImageEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_cat.png"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert_matches!(content.file.encryption_info, None);
|
||||
assert_eq!(content.image.width, Some(uint!(668)));
|
||||
assert_eq!(content.image.height, None);
|
||||
assert!(content.thumbnail.is_empty());
|
||||
let caption = content.caption.unwrap();
|
||||
assert_eq!(caption.find_plain(), Some("Look at my cat!"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encrypted_content_deserialization() {
|
||||
let json_data = json!({
|
||||
"org.matrix.msc1767.text": "Upload: my_file.txt",
|
||||
"org.matrix.msc1767.text": "Upload: my_cat.png",
|
||||
"m.file": {
|
||||
"url": "mxc://notareal.hs/abcdef",
|
||||
"key": {
|
||||
@ -247,18 +245,16 @@ fn encrypted_content_deserialization() {
|
||||
]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<ImageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
ImageEventContent { message, file, image, thumbnail, caption: None, .. }
|
||||
if message.find_plain() == Some("Upload: my_file.txt")
|
||||
&& message.find_html().is_none()
|
||||
&& file.url == "mxc://notareal.hs/abcdef"
|
||||
&& file.encryption_info.is_some()
|
||||
&& image.width.is_none()
|
||||
&& image.height.is_none()
|
||||
&& thumbnail[0].file.url == "mxc://notareal.hs/thumbnail"
|
||||
);
|
||||
let content = from_json_value::<ImageEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_cat.png"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert!(content.file.encryption_info.is_some());
|
||||
assert_eq!(content.image.width, None);
|
||||
assert_eq!(content.image.height, None);
|
||||
assert_eq!(content.thumbnail.len(), 1);
|
||||
assert_eq!(content.thumbnail[0].file.url, "mxc://notareal.hs/thumbnail");
|
||||
assert_matches!(content.caption, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -284,41 +280,27 @@ fn message_event_deserialization() {
|
||||
"type": "m.image",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Image(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: ImageEventContent {
|
||||
message,
|
||||
file: FileContent {
|
||||
url,
|
||||
info: Some(info),
|
||||
..
|
||||
},
|
||||
image,
|
||||
thumbnail,
|
||||
caption: None,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("Upload: my_gnome.webp")
|
||||
&& message.find_html().is_none()
|
||||
&& url == "mxc://notareal.hs/abcdef"
|
||||
&& info.name.as_deref() == Some("my_gnome.webp")
|
||||
&& info.mimetype.as_deref() == Some("image/webp")
|
||||
&& info.size == Some(uint!(123_774))
|
||||
&& image.width == Some(uint!(1300))
|
||||
&& image.height == Some(uint!(837))
|
||||
&& thumbnail.is_empty()
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Image(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
|
||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(message_event.sender, "@user:notareal.hs");
|
||||
assert!(message_event.unsigned.is_empty());
|
||||
let content = message_event.content;
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_gnome.webp"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
let info = content.file.info.unwrap();
|
||||
assert_eq!(info.name.as_deref(), Some("my_gnome.webp"));
|
||||
assert_eq!(info.mimetype.as_deref(), Some("image/webp"));
|
||||
assert_eq!(info.size, Some(uint!(123_774)));
|
||||
assert_eq!(content.image.width, Some(uint!(1300)));
|
||||
assert_eq!(content.image.height, Some(uint!(837)));
|
||||
assert!(content.thumbnail.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -359,20 +341,16 @@ fn room_message_stable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::Image(_));
|
||||
if let MessageType::Image(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_image.jpg");
|
||||
assert_matches!(content.source, MediaSource::Plain(_));
|
||||
if let MediaSource::Plain(url) = content.source {
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_image.jpg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
let content = assert_matches!(event_content.msgtype, MessageType::Image(content) => content);
|
||||
assert_eq!(content.body, "Upload: my_image.jpg");
|
||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_image.jpg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -389,18 +367,14 @@ fn room_message_unstable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::Image(_));
|
||||
if let MessageType::Image(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_image.jpg");
|
||||
assert_matches!(content.source, MediaSource::Plain(_));
|
||||
if let MediaSource::Plain(url) = content.source {
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_image.jpg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
let content = assert_matches!(event_content.msgtype, MessageType::Image(content) => content);
|
||||
assert_eq!(content.body, "Upload: my_image.jpg");
|
||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_image.jpg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ use ruma_common::{
|
||||
message::{MessageContent, MessageEventContent, Text},
|
||||
notice::NoticeEventContent,
|
||||
room::message::{
|
||||
EmoteMessageEventContent, InReplyTo, MessageType, NoticeMessageEventContent, Relation,
|
||||
RoomMessageEventContent, TextMessageEventContent,
|
||||
EmoteMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEventContent,
|
||||
},
|
||||
AnyMessageLikeEvent, MessageLikeEvent, MessageLikeUnsigned, OriginalMessageLikeEvent,
|
||||
},
|
||||
@ -21,10 +20,8 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
||||
|
||||
#[test]
|
||||
fn try_from_valid() {
|
||||
assert_matches!(
|
||||
MessageContent::try_from(vec![Text::plain("A message")]),
|
||||
Ok(message) if message.len() == 1
|
||||
);
|
||||
let message = MessageContent::try_from(vec![Text::plain("A message")]).unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -154,13 +151,9 @@ fn plain_text_content_unstable_deserialization() {
|
||||
"org.matrix.msc1767.text": "This is my body",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<MessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
MessageEventContent { message, .. }
|
||||
if message.find_plain() == Some("This is my body")
|
||||
&& message.find_html().is_none()
|
||||
);
|
||||
let content = from_json_value::<MessageEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("This is my body"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -169,13 +162,9 @@ fn plain_text_content_stable_deserialization() {
|
||||
"m.text": "This is my body",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<MessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
MessageEventContent { message, .. }
|
||||
if message.find_plain() == Some("This is my body")
|
||||
&& message.find_html().is_none()
|
||||
);
|
||||
let content = from_json_value::<MessageEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("This is my body"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -187,13 +176,9 @@ fn html_text_content_unstable_deserialization() {
|
||||
]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<MessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
MessageEventContent { message, .. }
|
||||
if message.find_plain() == Some("Hello, New World!")
|
||||
&& message.find_html() == Some("Hello, <em>New World</em>!")
|
||||
);
|
||||
let content = from_json_value::<MessageEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Hello, New World!"));
|
||||
assert_eq!(content.message.find_html(), Some("Hello, <em>New World</em>!"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -205,13 +190,9 @@ fn html_text_content_stable_deserialization() {
|
||||
]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<MessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
MessageEventContent { message, .. }
|
||||
if message.find_plain() == Some("Hello, New World!")
|
||||
&& message.find_html() == Some("Hello, <em>New World</em>!")
|
||||
);
|
||||
let content = from_json_value::<MessageEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Hello, New World!"));
|
||||
assert_eq!(content.message.find_html(), Some("Hello, <em>New World</em>!"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -225,18 +206,15 @@ fn relates_to_content_deserialization() {
|
||||
}
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<MessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
MessageEventContent {
|
||||
message,
|
||||
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. } }),
|
||||
..
|
||||
}
|
||||
if message.find_plain() == Some("> <@test:example.com> test\n\ntest reply")
|
||||
&& message.find_html().is_none()
|
||||
&& event_id == event_id!("$15827405538098VGFWH:example.com")
|
||||
let content = from_json_value::<MessageEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("> <@test:example.com> test\n\ntest reply"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
|
||||
let event_id = assert_matches!(
|
||||
content.relates_to,
|
||||
Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. } }) => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$15827405538098VGFWH:example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -252,25 +230,16 @@ fn message_event_deserialization() {
|
||||
"type": "m.message",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Message(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: MessageEventContent {
|
||||
message,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("Hello, World!")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Message(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||
assert_eq!(message_event.content.message.find_plain(), Some("Hello, World!"));
|
||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(message_event.sender, "@user:notareal.hs");
|
||||
assert!(message_event.unsigned.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -281,21 +250,17 @@ fn room_message_plain_text_stable_deserialization() {
|
||||
"m.text": "test",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& message.len() == 1
|
||||
&& message[0].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -306,21 +271,17 @@ fn room_message_plain_text_unstable_deserialization() {
|
||||
"org.matrix.msc1767.text": "test",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& message.len() == 1
|
||||
&& message[0].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -336,23 +297,20 @@ fn room_message_html_text_stable_deserialization() {
|
||||
],
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: Some(formatted),
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& formatted.body == "<h1>test</h1>"
|
||||
&& message.len() == 2
|
||||
&& message[0].body == "<h1>test</h1>"
|
||||
&& message[1].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let formatted = content.formatted.unwrap();
|
||||
assert_eq!(formatted.body, "<h1>test</h1>");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 2);
|
||||
assert_eq!(message[0].body, "<h1>test</h1>");
|
||||
assert_eq!(message[1].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -368,23 +326,20 @@ fn room_message_html_text_unstable_deserialization() {
|
||||
],
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: Some(formatted),
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& formatted.body == "<h1>test</h1>"
|
||||
&& message.len() == 2
|
||||
&& message[0].body == "<h1>test</h1>"
|
||||
&& message[1].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let formatted = content.formatted.unwrap();
|
||||
assert_eq!(formatted.body, "<h1>test</h1>");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 2);
|
||||
assert_eq!(message[0].body, "<h1>test</h1>");
|
||||
assert_eq!(message[1].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -444,26 +399,20 @@ fn notice_event_stable_deserialization() {
|
||||
"type": "m.notice",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Notice(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: NoticeEventContent {
|
||||
message,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("Hello, I'm a robot!")
|
||||
&& message.find_html() == Some("Hello, I'm a <em>robot</em>!")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Notice(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
|
||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(message_event.sender, "@user:notareal.hs");
|
||||
assert!(message_event.unsigned.is_empty());
|
||||
|
||||
let message = message_event.content.message;
|
||||
assert_eq!(message.find_plain(), Some("Hello, I'm a robot!"));
|
||||
assert_eq!(message.find_html(), Some("Hello, I'm a <em>robot</em>!"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -482,26 +431,20 @@ fn notice_event_unstable_deserialization() {
|
||||
"type": "m.notice",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Notice(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: NoticeEventContent {
|
||||
message,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("Hello, I'm a robot!")
|
||||
&& message.find_html() == Some("Hello, I'm a <em>robot</em>!")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Notice(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
|
||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(message_event.sender, "@user:notareal.hs");
|
||||
assert!(message_event.unsigned.is_empty());
|
||||
|
||||
let message = message_event.content.message;
|
||||
assert_eq!(message.find_plain(), Some("Hello, I'm a robot!"));
|
||||
assert_eq!(message.find_html(), Some("Hello, I'm a <em>robot</em>!"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -512,21 +455,17 @@ fn room_message_notice_stable_deserialization() {
|
||||
"m.text": "test",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Notice(NoticeMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Notice(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& message.len() == 1
|
||||
&& message[0].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -537,21 +476,17 @@ fn room_message_notice_unstable_deserialization() {
|
||||
"org.matrix.msc1767.text": "test",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Notice(NoticeMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Notice(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& message.len() == 1
|
||||
&& message[0].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -615,26 +550,20 @@ fn emote_event_stable_deserialization() {
|
||||
"type": "m.emote",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Emote(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: EmoteEventContent {
|
||||
message,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("is testing some code…")
|
||||
&& message.find_html().is_none()
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Emote(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
|
||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(message_event.sender, "@user:notareal.hs");
|
||||
assert!(message_event.unsigned.is_empty());
|
||||
|
||||
let message = message_event.content.message;
|
||||
assert_eq!(message.find_plain(), Some("is testing some code…"));
|
||||
assert_eq!(message.find_html(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -650,26 +579,20 @@ fn emote_event_unstable_deserialization() {
|
||||
"type": "m.emote",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Emote(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: EmoteEventContent {
|
||||
message,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("is testing some code…")
|
||||
&& message.find_html().is_none()
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Emote(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
|
||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(message_event.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(message_event.sender, "@user:notareal.hs");
|
||||
assert!(message_event.unsigned.is_empty());
|
||||
|
||||
let message = message_event.content.message;
|
||||
assert_eq!(message.find_plain(), Some("is testing some code…"));
|
||||
assert_eq!(message.find_html(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -680,21 +603,17 @@ fn room_message_emote_stable_deserialization() {
|
||||
"m.text": "test",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Emote(EmoteMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Emote(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& message.len() == 1
|
||||
&& message[0].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -705,21 +624,17 @@ fn room_message_emote_unstable_deserialization() {
|
||||
"org.matrix.msc1767.text": "test",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Emote(EmoteMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
message: Some(message),
|
||||
..
|
||||
}),
|
||||
let content = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Emote(content),
|
||||
..
|
||||
} if body == "test"
|
||||
&& message.len() == 1
|
||||
&& message[0].body == "test"
|
||||
}) => content
|
||||
);
|
||||
assert_eq!(content.body, "test");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -203,56 +203,35 @@ fn deserialize_message_sticker() {
|
||||
"type": "m.sticker"
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Sticker(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: StickerEventContent {
|
||||
body,
|
||||
info: ImageInfo {
|
||||
height,
|
||||
width,
|
||||
mimetype: Some(mimetype),
|
||||
size,
|
||||
thumbnail_info: Some(thumbnail_info),
|
||||
thumbnail_source: Some(MediaSource::Plain(thumbnail_url)),
|
||||
#[cfg(feature = "unstable-msc2448")]
|
||||
blurhash: None,
|
||||
..
|
||||
},
|
||||
url,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& body == "Hello"
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
&& height == UInt::new(423)
|
||||
&& width == UInt::new(1011)
|
||||
&& mimetype == "image/png"
|
||||
&& size == UInt::new(84242)
|
||||
&& thumbnail_url == "mxc://matrix.org/irnsNRS2879"
|
||||
&& matches!(
|
||||
thumbnail_info.as_ref(),
|
||||
ThumbnailInfo {
|
||||
width: thumb_width,
|
||||
height: thumb_height,
|
||||
mimetype: thumb_mimetype,
|
||||
size: thumb_size,
|
||||
..
|
||||
} if *thumb_width == UInt::new(800)
|
||||
&& *thumb_height == UInt::new(334)
|
||||
&& *thumb_mimetype == Some("image/png".into())
|
||||
&& *thumb_size == UInt::new(82595)
|
||||
)
|
||||
&& url == "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD"
|
||||
&& unsigned.is_empty()
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Sticker(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
|
||||
assert_eq!(message_event.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(message_event.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||
assert_eq!(message_event.room_id, "!roomid:room.com");
|
||||
assert_eq!(message_event.sender, "@carl:example.com");
|
||||
assert!(message_event.unsigned.is_empty());
|
||||
|
||||
let content = message_event.content;
|
||||
assert_eq!(content.body, "Hello");
|
||||
assert_eq!(content.info.height, Some(uint!(423)));
|
||||
assert_eq!(content.info.width, Some(uint!(1011)));
|
||||
assert_eq!(content.info.mimetype.as_deref(), Some("image/png"));
|
||||
assert_eq!(content.info.size, Some(uint!(84242)));
|
||||
assert_eq!(content.url, "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD");
|
||||
|
||||
let thumbnail_url = assert_matches!(
|
||||
content.info.thumbnail_source,
|
||||
Some(MediaSource::Plain(thumbnail_url)) => thumbnail_url
|
||||
);
|
||||
assert_eq!(thumbnail_url, "mxc://matrix.org/irnsNRS2879");
|
||||
let thumbnail_info = content.info.thumbnail_info.unwrap();
|
||||
assert_eq!(thumbnail_info.width, Some(uint!(800)));
|
||||
assert_eq!(thumbnail_info.height, Some(uint!(334)));
|
||||
assert_eq!(thumbnail_info.mimetype.as_deref(), Some("image/png"));
|
||||
assert_eq!(thumbnail_info.size, Some(uint!(82595)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -29,10 +29,8 @@ fn poll_answers_deserialization_valid() {
|
||||
{ "id": "bbb", "m.text": "Second answer" },
|
||||
]);
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<PollAnswers>(json_data),
|
||||
Ok(answers) if answers.answers().len() == 2
|
||||
);
|
||||
let answers = from_json_value::<PollAnswers>(json_data).unwrap();
|
||||
assert_eq!(answers.answers().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -62,10 +60,8 @@ fn poll_answers_deserialization_truncate() {
|
||||
{ "id": "vvv", "m.text": "22th answer" },
|
||||
]);
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<PollAnswers>(json_data),
|
||||
Ok(answers) if answers.answers().len() == 20
|
||||
);
|
||||
let answers = from_json_value::<PollAnswers>(json_data).unwrap();
|
||||
assert_eq!(answers.answers().len(), 20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -320,10 +316,11 @@ fn response_event_unstable_deserialization() {
|
||||
let answers = message_event.content.poll_response.answers;
|
||||
assert_eq!(answers.len(), 1);
|
||||
assert_eq!(answers[0], "my-answer");
|
||||
assert_matches!(
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } if event_id == "$related_event:notareal.hs"
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -355,10 +352,11 @@ fn response_event_stable_deserialization() {
|
||||
assert_eq!(answers.len(), 2);
|
||||
assert_eq!(answers[0], "first-answer");
|
||||
assert_eq!(answers[1], "second-answer");
|
||||
assert_matches!(
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } if event_id == "$related_event:notareal.hs"
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -435,10 +433,11 @@ fn end_event_unstable_deserialization() {
|
||||
event,
|
||||
AnyMessageLikeEvent::PollEnd(MessageLikeEvent::Original(message_event)) => message_event
|
||||
);
|
||||
assert_matches!(
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } if event_id == "$related_event:notareal.hs"
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -463,8 +462,9 @@ fn end_event_stable_deserialization() {
|
||||
event,
|
||||
AnyMessageLikeEvent::PollEnd(MessageLikeEvent::Original(message_event)) => message_event
|
||||
);
|
||||
assert_matches!(
|
||||
let event_id = assert_matches!(
|
||||
message_event.content.relates_to,
|
||||
ReferenceRelation { event_id, .. } if event_id == "$related_event:notareal.hs"
|
||||
ReferenceRelation { event_id, .. } => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$related_event:notareal.hs");
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ use ruma_common::{
|
||||
},
|
||||
AnyMessageLikeEvent, AnyRoomEvent, AnySyncMessageLikeEvent, AnySyncRoomEvent,
|
||||
AnySyncStateEvent, EventContent, MessageLikeEvent, MessageLikeUnsigned, RedactContent,
|
||||
RedactedMessageLikeEvent, RedactedSyncMessageLikeEvent, RedactedSyncStateEvent,
|
||||
RedactedUnsigned, SyncMessageLikeEvent, SyncStateEvent,
|
||||
RedactedSyncMessageLikeEvent, RedactedSyncStateEvent, RedactedUnsigned,
|
||||
SyncMessageLikeEvent, SyncStateEvent,
|
||||
},
|
||||
room_id, server_name, user_id, MilliSecondsSinceUnixEpoch, RoomVersionId,
|
||||
server_name, user_id, MilliSecondsSinceUnixEpoch, RoomVersionId,
|
||||
};
|
||||
use serde_json::{
|
||||
from_value as from_json_value, json, to_value as to_json_value,
|
||||
@ -121,17 +121,14 @@ fn redacted_aliases_deserialize() {
|
||||
|
||||
let actual = to_json_value(&redacted).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(actual).unwrap(),
|
||||
AnySyncRoomEvent::State(AnySyncStateEvent::RoomAliases(
|
||||
SyncStateEvent::Redacted(RedactedSyncStateEvent {
|
||||
content: RedactedRoomAliasesEventContent { aliases, .. },
|
||||
event_id,
|
||||
..
|
||||
}),
|
||||
)) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& aliases.is_none()
|
||||
let redacted = assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(actual),
|
||||
Ok(AnySyncRoomEvent::State(AnySyncStateEvent::RoomAliases(
|
||||
SyncStateEvent::Redacted(redacted),
|
||||
))) => redacted
|
||||
);
|
||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(redacted.content.aliases, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -147,16 +144,14 @@ fn redacted_deserialize_any_room() {
|
||||
|
||||
let actual = to_json_value(&redacted).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(actual).unwrap(),
|
||||
AnyRoomEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
|
||||
MessageLikeEvent::Redacted(RedactedMessageLikeEvent {
|
||||
content: RedactedRoomMessageEventContent { .. },
|
||||
event_id, room_id, ..
|
||||
}),
|
||||
)) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
let redacted = assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(actual),
|
||||
Ok(AnyRoomEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(
|
||||
MessageLikeEvent::Redacted(redacted),
|
||||
))) => redacted
|
||||
);
|
||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(redacted.room_id, "!roomid:room.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -185,16 +180,13 @@ fn redacted_deserialize_any_room_sync() {
|
||||
|
||||
let actual = to_json_value(&redacted).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(actual).unwrap(),
|
||||
AnySyncRoomEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
|
||||
SyncMessageLikeEvent::Redacted(RedactedSyncMessageLikeEvent {
|
||||
content: RedactedRoomMessageEventContent { .. },
|
||||
event_id,
|
||||
..
|
||||
}),
|
||||
)) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
let redacted = assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(actual),
|
||||
Ok(AnySyncRoomEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
|
||||
SyncMessageLikeEvent::Redacted(redacted),
|
||||
))) => redacted
|
||||
);
|
||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -211,26 +203,19 @@ fn redacted_state_event_deserialize() {
|
||||
"type": "m.room.create",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(redacted)
|
||||
.unwrap(),
|
||||
AnySyncRoomEvent::State(AnySyncStateEvent::RoomCreate(
|
||||
SyncStateEvent::Redacted(RedactedSyncStateEvent {
|
||||
content: RedactedRoomCreateEventContent {
|
||||
creator, ..
|
||||
},
|
||||
event_id,
|
||||
unsigned,
|
||||
..
|
||||
}),
|
||||
)) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& unsigned.redacted_because.is_some()
|
||||
&& creator == user_id!("@carl:example.com")
|
||||
let redacted = assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(redacted),
|
||||
Ok(AnySyncRoomEvent::State(AnySyncStateEvent::RoomCreate(
|
||||
SyncStateEvent::Redacted(redacted),
|
||||
))) => redacted
|
||||
);
|
||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||
assert!(redacted.unsigned.redacted_because.is_some());
|
||||
assert_eq!(redacted.content.creator, "@carl:example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redacted_custom_event_serialize() {
|
||||
fn redacted_custom_event_deserialize() {
|
||||
let redacted = json!({
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"origin_server_ts": 1,
|
||||
@ -240,13 +225,11 @@ fn redacted_custom_event_serialize() {
|
||||
"type": "m.made.up",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(redacted.clone()),
|
||||
Ok(AnySyncRoomEvent::State(_))
|
||||
let state_ev = assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(redacted),
|
||||
Ok(AnySyncRoomEvent::State(state_ev)) => state_ev
|
||||
);
|
||||
|
||||
let x = from_json_value::<AnySyncStateEvent>(redacted).unwrap();
|
||||
assert_eq!(x.event_id(), event_id!("$h29iv0s8:example.com"));
|
||||
assert_eq!(state_ev.event_id(), "$h29iv0s8:example.com");
|
||||
}
|
||||
|
||||
/* #[test]
|
||||
@ -317,11 +300,12 @@ fn redact_state_content() {
|
||||
let raw_json = to_raw_json_value(&json).unwrap();
|
||||
let content = RoomCreateEventContent::from_parts("m.room.create", &raw_json).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
let creator = assert_matches!(
|
||||
content.redact(&RoomVersionId::V6),
|
||||
RedactedRoomCreateEventContent {
|
||||
creator,
|
||||
..
|
||||
} if creator == user_id!("@carl:example.com")
|
||||
} => creator
|
||||
);
|
||||
assert_eq!(creator, "@carl:example.com");
|
||||
}
|
||||
|
@ -50,22 +50,15 @@ fn serialize_redaction() {
|
||||
fn deserialize_redaction() {
|
||||
let json_data = redaction();
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::RoomRedaction(RoomRedactionEvent::Original(OriginalRoomRedactionEvent {
|
||||
content: RoomRedactionEventContent { reason: Some(reas), .. },
|
||||
redacts,
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned,
|
||||
})) if reas == "being a turd"
|
||||
&& event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& redacts == event_id!("$nomore:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
&& unsigned.is_empty()
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::RoomRedaction(RoomRedactionEvent::Original(ev))) => ev
|
||||
);
|
||||
assert_eq!(ev.content.reason.as_deref(), Some("being a turd"));
|
||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(ev.redacts, "$nomore:example.com");
|
||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||
assert_eq!(ev.room_id, "!roomid:room.com");
|
||||
assert_eq!(ev.sender, "@carl:example.com");
|
||||
assert!(ev.unsigned.is_empty());
|
||||
}
|
||||
|
@ -8,26 +8,25 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
|
||||
|
||||
#[test]
|
||||
fn reply_deserialize() {
|
||||
let ev_id = event_id!("$1598361704261elfgc:localhost");
|
||||
|
||||
let json = json!({
|
||||
"msgtype": "m.text",
|
||||
"body": "<text msg>",
|
||||
"m.relates_to": {
|
||||
"m.in_reply_to": {
|
||||
"event_id": ev_id,
|
||||
"event_id": "$1598361704261elfgc:localhost",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json).unwrap(),
|
||||
RoomMessageEventContent {
|
||||
let event_id = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(_),
|
||||
relates_to: Some(Relation::Reply { in_reply_to: InReplyTo { event_id, .. }, .. }),
|
||||
..
|
||||
} if event_id == ev_id
|
||||
}) => event_id
|
||||
);
|
||||
assert_eq!(event_id, "$1598361704261elfgc:localhost");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -123,8 +122,6 @@ fn replacement_serialize() {
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-msc2676")]
|
||||
fn replacement_deserialize() {
|
||||
use ruma_common::events::room::message::Replacement;
|
||||
|
||||
let json = json!({
|
||||
"msgtype": "m.text",
|
||||
"body": "<text msg>",
|
||||
@ -138,15 +135,17 @@ fn replacement_deserialize() {
|
||||
},
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json).unwrap(),
|
||||
RoomMessageEventContent {
|
||||
let replacement = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(_),
|
||||
relates_to: Some(Relation::Replacement(Replacement { event_id, new_content, .. })),
|
||||
relates_to: Some(Relation::Replacement(replacement)),
|
||||
..
|
||||
} if event_id == "$1598361704261elfgc"
|
||||
&& matches!(&new_content.msgtype, MessageType::Text(text) if text.body == "Hello! My name is bar")
|
||||
}) => replacement
|
||||
);
|
||||
assert_eq!(replacement.event_id, "$1598361704261elfgc");
|
||||
let text = assert_matches!(replacement.new_content.msgtype, MessageType::Text(text) => text);
|
||||
assert_eq!(text.body, "Hello! My name is bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -256,8 +255,6 @@ fn thread_reply_serialize() {
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-msc3440")]
|
||||
fn thread_stable_deserialize() {
|
||||
use ruma_common::events::room::message::Thread;
|
||||
|
||||
let json = json!({
|
||||
"msgtype": "m.text",
|
||||
"body": "<text msg>",
|
||||
@ -270,30 +267,22 @@ fn thread_stable_deserialize() {
|
||||
},
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json).unwrap(),
|
||||
RoomMessageEventContent {
|
||||
let thread = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(_),
|
||||
relates_to: Some(Relation::Thread(
|
||||
Thread {
|
||||
event_id,
|
||||
in_reply_to: InReplyTo { event_id: reply_to_event_id, .. },
|
||||
is_falling_back,
|
||||
..
|
||||
},
|
||||
)),
|
||||
relates_to: Some(Relation::Thread(thread)),
|
||||
..
|
||||
} if event_id == "$1598361704261elfgc"
|
||||
&& reply_to_event_id == "$latesteventid"
|
||||
&& !is_falling_back
|
||||
}) => thread
|
||||
);
|
||||
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
||||
assert_eq!(thread.in_reply_to.event_id, "$latesteventid");
|
||||
assert!(!thread.is_falling_back);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-msc3440")]
|
||||
fn thread_unstable_deserialize() {
|
||||
use ruma_common::events::room::message::Thread;
|
||||
|
||||
let json = json!({
|
||||
"msgtype": "m.text",
|
||||
"body": "<text msg>",
|
||||
@ -306,21 +295,15 @@ fn thread_unstable_deserialize() {
|
||||
},
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json).unwrap(),
|
||||
RoomMessageEventContent {
|
||||
let thread = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(_),
|
||||
relates_to: Some(Relation::Thread(
|
||||
Thread {
|
||||
event_id,
|
||||
in_reply_to: InReplyTo { event_id: reply_to_event_id, .. },
|
||||
is_falling_back,
|
||||
..
|
||||
},
|
||||
)),
|
||||
relates_to: Some(Relation::Thread(thread)),
|
||||
..
|
||||
} if event_id == "$1598361704261elfgc"
|
||||
&& reply_to_event_id == "$latesteventid"
|
||||
&& !is_falling_back
|
||||
}) => thread
|
||||
);
|
||||
assert_eq!(thread.event_id, "$1598361704261elfgc");
|
||||
assert_eq!(thread.in_reply_to.event_id, "$latesteventid");
|
||||
assert!(!thread.is_falling_back);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use ruma_common::{
|
||||
room::{
|
||||
message::{
|
||||
AudioMessageEventContent, KeyVerificationRequestEventContent, MessageType,
|
||||
OriginalRoomMessageEvent, RoomMessageEventContent, TextMessageEventContent,
|
||||
OriginalRoomMessageEvent, RoomMessageEventContent,
|
||||
},
|
||||
MediaSource,
|
||||
},
|
||||
@ -228,6 +228,8 @@ fn plain_text_content_serialization() {
|
||||
#[test]
|
||||
#[cfg(feature = "markdown")]
|
||||
fn markdown_content_serialization() {
|
||||
use ruma_common::events::room::message::TextMessageEventContent;
|
||||
|
||||
let formatted_message = RoomMessageEventContent::new(MessageType::Text(
|
||||
TextMessageEventContent::markdown("Testing **bold** and _italic_!"),
|
||||
));
|
||||
@ -345,39 +347,33 @@ fn edit_deserialization_061() {
|
||||
"msgtype": "m.text",
|
||||
"m.relates_to": {
|
||||
"rel_type": "m.replace",
|
||||
"event_id": event_id!("$1598361704261elfgc:localhost"),
|
||||
"event_id": "$1598361704261elfgc:localhost",
|
||||
},
|
||||
"m.new_content": {
|
||||
"body": "bar",
|
||||
},
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data).unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
..
|
||||
}),
|
||||
relates_to: Some(_),
|
||||
..
|
||||
} if body == "s/foo/bar"
|
||||
let content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert!(content.relates_to.is_some());
|
||||
|
||||
let text = assert_matches!(
|
||||
content.msgtype,
|
||||
MessageType::Text(text) => text
|
||||
);
|
||||
assert_eq!(text.body, "s/foo/bar");
|
||||
assert_matches!(text.formatted, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-msc2676")]
|
||||
fn edit_deserialization_future() {
|
||||
use ruma_common::events::room::message::Replacement;
|
||||
|
||||
let ev_id = event_id!("$1598361704261elfgc:localhost");
|
||||
let json_data = json!({
|
||||
"body": "s/foo/bar",
|
||||
"msgtype": "m.text",
|
||||
"m.relates_to": {
|
||||
"rel_type": "m.replace",
|
||||
"event_id": ev_id,
|
||||
"event_id": "$1598361704261elfgc:localhost",
|
||||
},
|
||||
"m.new_content": {
|
||||
"body": "bar",
|
||||
@ -385,30 +381,27 @@ fn edit_deserialization_future() {
|
||||
},
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data).unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
..
|
||||
}),
|
||||
relates_to: Some(Relation::Replacement(Replacement { event_id, new_content, .. })),
|
||||
..
|
||||
} if body == "s/foo/bar"
|
||||
&& event_id == ev_id
|
||||
&& matches!(
|
||||
&*new_content,
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: None,
|
||||
..
|
||||
}),
|
||||
..
|
||||
} if body == "bar"
|
||||
)
|
||||
let content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
|
||||
let text = assert_matches!(
|
||||
content.msgtype,
|
||||
MessageType::Text(text) => text
|
||||
);
|
||||
assert_eq!(text.body, "s/foo/bar");
|
||||
assert_matches!(text.formatted, None);
|
||||
|
||||
let replacement = assert_matches!(
|
||||
content.relates_to,
|
||||
Some(Relation::Replacement(replacement)) => replacement
|
||||
);
|
||||
assert_eq!(replacement.event_id, "$1598361704261elfgc:localhost");
|
||||
|
||||
let new_text = assert_matches!(
|
||||
replacement.new_content.msgtype,
|
||||
MessageType::Text(new_text) => new_text
|
||||
);
|
||||
assert_eq!(new_text.body, "bar");
|
||||
assert_matches!(new_text.formatted, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -428,22 +421,18 @@ fn verification_request_deserialization() {
|
||||
]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data).unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::VerificationRequest(KeyVerificationRequestEventContent {
|
||||
body,
|
||||
to,
|
||||
from_device,
|
||||
methods,
|
||||
..
|
||||
}),
|
||||
let verification = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::VerificationRequest(verification),
|
||||
..
|
||||
} if body == "@example:localhost is requesting to verify your key, ..."
|
||||
&& to == user_id
|
||||
&& from_device == device_id
|
||||
&& methods.contains(&VerificationMethod::SasV1)
|
||||
}) => verification
|
||||
);
|
||||
assert_eq!(verification.body, "@example:localhost is requesting to verify your key, ...");
|
||||
assert_eq!(verification.to, user_id);
|
||||
assert_eq!(verification.from_device, device_id);
|
||||
assert_eq!(verification.methods.len(), 3);
|
||||
assert!(verification.methods.contains(&VerificationMethod::SasV1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -478,19 +467,17 @@ fn content_deserialization() {
|
||||
"url": "mxc://example.org/ffed755USFFxlgbQYZGtryd"
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data)
|
||||
.unwrap(),
|
||||
RoomMessageEventContent {
|
||||
msgtype: MessageType::Audio(AudioMessageEventContent {
|
||||
body,
|
||||
info: None,
|
||||
source: MediaSource::Plain(url),
|
||||
..
|
||||
}),
|
||||
let audio = assert_matches!(
|
||||
from_json_value::<RoomMessageEventContent>(json_data),
|
||||
Ok(RoomMessageEventContent {
|
||||
msgtype: MessageType::Audio(audio),
|
||||
..
|
||||
} if body == "test" && url == "mxc://example.org/ffed755USFFxlgbQYZGtryd"
|
||||
}) => audio
|
||||
);
|
||||
assert_eq!(audio.body, "test");
|
||||
assert_matches!(audio.info, None);
|
||||
let url = assert_matches!(audio.source, MediaSource::Plain(url) => url);
|
||||
assert_eq!(url, "mxc://example.org/ffed755USFFxlgbQYZGtryd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -499,5 +486,5 @@ fn content_deserialization_failure() {
|
||||
"body": "test","msgtype": "m.location",
|
||||
"url": "http://example.com/audio.mp3"
|
||||
});
|
||||
assert!(from_json_value::<RoomMessageEventContent>(json_data).is_err());
|
||||
assert_matches!(from_json_value::<RoomMessageEventContent>(json_data), Err(_));
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
use assert_matches::assert_matches;
|
||||
use assign::assign;
|
||||
use js_int::{uint, UInt};
|
||||
use js_int::uint;
|
||||
use ruma_common::{
|
||||
event_id,
|
||||
events::{
|
||||
room::{
|
||||
aliases::RoomAliasesEventContent,
|
||||
avatar::{ImageInfo, RoomAvatarEventContent},
|
||||
ThumbnailInfo,
|
||||
},
|
||||
AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnySyncStateEvent, OriginalStateEvent,
|
||||
OriginalSyncStateEvent, StateEvent, StateEventType, StateUnsigned, SyncStateEvent,
|
||||
room::aliases::RoomAliasesEventContent, AnyRoomEvent, AnyStateEvent, AnyStateEventContent,
|
||||
AnySyncStateEvent, OriginalStateEvent, StateEvent, StateEventType, StateUnsigned,
|
||||
SyncStateEvent,
|
||||
},
|
||||
mxc_uri, room_alias_id, room_id,
|
||||
serde::Raw,
|
||||
@ -100,40 +96,31 @@ fn deserialize_aliases_content() {
|
||||
"aliases": [ "#somewhere:localhost" ]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
let content = assert_matches!(
|
||||
from_json_value::<Raw<AnyStateEventContent>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize_content(StateEventType::RoomAliases)
|
||||
.unwrap(),
|
||||
AnyStateEventContent::RoomAliases(content)
|
||||
if content.aliases == vec![room_alias_id!("#somewhere:localhost")]
|
||||
.deserialize_content(StateEventType::RoomAliases),
|
||||
Ok(AnyStateEventContent::RoomAliases(content)) => content
|
||||
);
|
||||
assert_eq!(content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_aliases_with_prev_content() {
|
||||
let json_data = aliases_event_with_prev_content();
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyStateEvent>(json_data).unwrap(),
|
||||
AnyStateEvent::RoomAliases(StateEvent::Original(OriginalStateEvent {
|
||||
content,
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned: StateUnsigned {
|
||||
prev_content: Some(prev_content),
|
||||
..
|
||||
},
|
||||
..
|
||||
})) if content.aliases == vec![room_alias_id!("#somewhere:localhost")]
|
||||
&& event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
|
||||
&& prev_content.aliases == vec![room_alias_id!("#inner:localhost")]
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnyStateEvent>(json_data),
|
||||
Ok(AnyStateEvent::RoomAliases(StateEvent::Original(ev))) => ev
|
||||
);
|
||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||
assert_eq!(ev.room_id, "!roomid:room.com");
|
||||
assert_eq!(ev.sender, "@carl:example.com");
|
||||
|
||||
let prev_content = ev.unsigned.prev_content.unwrap();
|
||||
assert_eq!(prev_content.aliases, vec![room_alias_id!("#inner:localhost")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -141,29 +128,20 @@ fn deserialize_aliases_sync_with_room_id() {
|
||||
// The same JSON can be used to create a sync event, it just ignores the `room_id` field
|
||||
let json_data = aliases_event_with_prev_content();
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnySyncStateEvent>(json_data)
|
||||
.unwrap(),
|
||||
AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(OriginalSyncStateEvent {
|
||||
content,
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
sender,
|
||||
unsigned: StateUnsigned {
|
||||
prev_content: Some(prev_content),
|
||||
..
|
||||
},
|
||||
..
|
||||
})) if content.aliases == vec![room_alias_id!("#somewhere:localhost")]
|
||||
&& event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
|
||||
&& prev_content.aliases == vec![room_alias_id!("#inner:localhost")]
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnySyncStateEvent>(json_data),
|
||||
Ok(AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(ev))) => ev
|
||||
);
|
||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||
assert_eq!(ev.sender, "@carl:example.com");
|
||||
|
||||
let prev_content = ev.unsigned.prev_content.unwrap();
|
||||
assert_eq!(prev_content.aliases, vec![room_alias_id!("#inner:localhost")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::cmp_owned)] // seems buggy
|
||||
fn deserialize_avatar_without_prev_content() {
|
||||
let json_data = json!({
|
||||
"content": {
|
||||
@ -190,56 +168,29 @@ fn deserialize_avatar_without_prev_content() {
|
||||
"type": "m.room.avatar"
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyStateEvent>(json_data).unwrap(),
|
||||
AnyStateEvent::RoomAvatar(StateEvent::Original(OriginalStateEvent {
|
||||
content: RoomAvatarEventContent {
|
||||
info: Some(info),
|
||||
url: Some(url),
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned,
|
||||
..
|
||||
})) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
&& sender == user_id!("@carl:example.com")
|
||||
&& matches!(
|
||||
info.as_ref(),
|
||||
ImageInfo {
|
||||
height,
|
||||
width,
|
||||
mimetype: Some(mimetype),
|
||||
size,
|
||||
thumbnail_info: Some(thumbnail_info),
|
||||
thumbnail_url: Some(thumbnail_url),
|
||||
..
|
||||
} if *height == UInt::new(423)
|
||||
&& *width == UInt::new(1011)
|
||||
&& *mimetype == "image/png"
|
||||
&& *size == UInt::new(84242)
|
||||
&& matches!(
|
||||
thumbnail_info.as_ref(),
|
||||
ThumbnailInfo {
|
||||
width: thumb_width,
|
||||
height: thumb_height,
|
||||
mimetype: thumb_mimetype,
|
||||
size: thumb_size,
|
||||
..
|
||||
} if *thumb_width == UInt::new(800)
|
||||
&& *thumb_height == UInt::new(334)
|
||||
&& *thumb_mimetype == Some("image/png".into())
|
||||
&& *thumb_size == UInt::new(82595)
|
||||
&& thumbnail_url == mxc_uri!("mxc://matrix.org/98irRSS23srs")
|
||||
)
|
||||
)
|
||||
&& url == mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs")
|
||||
&& unsigned.is_empty()
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnyStateEvent>(json_data),
|
||||
Ok(AnyStateEvent::RoomAvatar(StateEvent::Original(ev))) => ev
|
||||
);
|
||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||
assert_eq!(ev.room_id, "!roomid:room.com");
|
||||
assert_eq!(ev.sender, "@carl:example.com");
|
||||
assert!(ev.unsigned.is_empty());
|
||||
assert_eq!(ev.content.url.as_deref(), Some(mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs")));
|
||||
|
||||
let info = ev.content.info.unwrap();
|
||||
assert_eq!(info.height, Some(uint!(423)));
|
||||
assert_eq!(info.width, Some(uint!(1011)));
|
||||
assert_eq!(info.mimetype.as_deref(), Some("image/png"));
|
||||
assert_eq!(info.size, Some(uint!(84242)));
|
||||
assert_eq!(info.thumbnail_url.as_deref(), Some(mxc_uri!("mxc://matrix.org/98irRSS23srs")));
|
||||
|
||||
let thumbnail_info = info.thumbnail_info.unwrap();
|
||||
assert_eq!(thumbnail_info.width, Some(uint!(800)));
|
||||
assert_eq!(thumbnail_info.height, Some(uint!(334)));
|
||||
assert_eq!(thumbnail_info.mimetype.as_deref(), Some("image/png"));
|
||||
assert_eq!(thumbnail_info.size, Some(uint!(82595)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -262,22 +213,14 @@ fn deserialize_member_event_with_top_level_membership_field() {
|
||||
}
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(json_data)
|
||||
.unwrap(),
|
||||
AnyRoomEvent::State(AnyStateEvent::RoomMember(StateEvent::Original(
|
||||
OriginalStateEvent {
|
||||
content,
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
sender,
|
||||
..
|
||||
}
|
||||
))) if event_id == event_id!("$h29iv0s8:example.com")
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(1))
|
||||
&& sender == user_id!("@example:localhost")
|
||||
&& content.displayname == Some("example".into())
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(json_data),
|
||||
Ok(AnyRoomEvent::State(AnyStateEvent::RoomMember(StateEvent::Original(ev)))) => ev
|
||||
);
|
||||
assert_eq!(ev.event_id, "$h29iv0s8:example.com");
|
||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(1)));
|
||||
assert_eq!(ev.sender, "@example:localhost");
|
||||
assert_eq!(ev.content.displayname.as_deref(), Some("example"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -285,10 +228,10 @@ fn deserialize_full_event_convert_to_sync() {
|
||||
let json_data = aliases_event_with_prev_content();
|
||||
|
||||
let full_ev: AnyStateEvent = from_json_value(json_data).unwrap();
|
||||
let sync_ev = match AnySyncStateEvent::from(full_ev) {
|
||||
AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(ev)) => ev,
|
||||
ev => panic!("unexpected variant for event {ev:?}"),
|
||||
};
|
||||
let sync_ev = assert_matches!(
|
||||
AnySyncStateEvent::from(full_ev),
|
||||
AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(ev)) => ev
|
||||
);
|
||||
|
||||
assert_eq!(sync_ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
assert_eq!(sync_ev.event_id, "$h29iv0s8:example.com");
|
||||
|
@ -214,25 +214,24 @@ fn plain_content_deserialization() {
|
||||
]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<VideoEventContent>(json_data)
|
||||
.unwrap(),
|
||||
VideoEventContent { message, file, video, thumbnail, caption: Some(caption), .. }
|
||||
if message.find_plain() == Some("Video: my_cat.mp4")
|
||||
&& message.find_html().is_none()
|
||||
&& file.url == "mxc://notareal.hs/abcdef"
|
||||
&& video.width.is_none()
|
||||
&& video.height.is_none()
|
||||
&& video.duration == Some(Duration::from_millis(5_668))
|
||||
&& thumbnail.is_empty()
|
||||
&& caption.find_plain() == Some("Look at my cat!")
|
||||
);
|
||||
let content = from_json_value::<VideoEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Video: my_cat.mp4"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert_matches!(content.file.encryption_info, None);
|
||||
assert_eq!(content.video.width, None);
|
||||
assert_eq!(content.video.height, None);
|
||||
assert_eq!(content.video.duration, Some(Duration::from_millis(5_668)));
|
||||
assert!(content.thumbnail.is_empty());
|
||||
let caption = content.caption.unwrap();
|
||||
assert_eq!(caption.find_plain(), Some("Look at my cat!"));
|
||||
assert_eq!(caption.find_html(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encrypted_content_deserialization() {
|
||||
let json_data = json!({
|
||||
"m.text": "Upload: my_cat.mp4",
|
||||
"m.text": "Video: my_cat.mp4",
|
||||
"m.file": {
|
||||
"url": "mxc://notareal.hs/abcdef",
|
||||
"key": {
|
||||
@ -256,19 +255,17 @@ fn encrypted_content_deserialization() {
|
||||
]
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<VideoEventContent>(json_data)
|
||||
.unwrap(),
|
||||
VideoEventContent { message, file, video, thumbnail, caption: None, .. }
|
||||
if message.find_plain() == Some("Upload: my_cat.mp4")
|
||||
&& message.find_html().is_none()
|
||||
&& file.url == "mxc://notareal.hs/abcdef"
|
||||
&& file.encryption_info.is_some()
|
||||
&& video.width.is_none()
|
||||
&& video.height.is_none()
|
||||
&& video.duration.is_none()
|
||||
&& thumbnail[0].file.url == "mxc://notareal.hs/thumbnail"
|
||||
);
|
||||
let content = from_json_value::<VideoEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Video: my_cat.mp4"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert!(content.file.encryption_info.is_some());
|
||||
assert_eq!(content.video.width, None);
|
||||
assert_eq!(content.video.height, None);
|
||||
assert_eq!(content.video.duration, None);
|
||||
assert_eq!(content.thumbnail.len(), 1);
|
||||
assert_eq!(content.thumbnail[0].file.url, "mxc://notareal.hs/thumbnail");
|
||||
assert_matches!(content.caption, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -294,42 +291,29 @@ fn message_event_deserialization() {
|
||||
"type": "m.video",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Video(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: VideoEventContent {
|
||||
message,
|
||||
file: FileContent {
|
||||
url,
|
||||
info: Some(info),
|
||||
..
|
||||
},
|
||||
video,
|
||||
thumbnail,
|
||||
caption: None,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("Upload: my_gnome.webm")
|
||||
&& message.find_html().is_none()
|
||||
&& url == "mxc://notareal.hs/abcdef"
|
||||
&& info.name.as_deref() == Some("my_gnome.webm")
|
||||
&& info.mimetype.as_deref() == Some("video/webm")
|
||||
&& info.size == Some(uint!(123_774))
|
||||
&& video.width == Some(uint!(1300))
|
||||
&& video.height == Some(uint!(837))
|
||||
&& video.duration.is_none()
|
||||
&& thumbnail.is_empty()
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Video(MessageLikeEvent::Original(ev))) => ev
|
||||
);
|
||||
assert_eq!(ev.event_id, "$event:notareal.hs");
|
||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(ev.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(ev.sender, "@user:notareal.hs");
|
||||
assert!(ev.unsigned.is_empty());
|
||||
|
||||
let content = ev.content;
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_gnome.webm"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert_eq!(content.video.width, Some(uint!(1300)));
|
||||
assert_eq!(content.video.height, Some(uint!(837)));
|
||||
assert_eq!(content.video.duration, None);
|
||||
assert!(content.thumbnail.is_empty());
|
||||
|
||||
let info = content.file.info.unwrap();
|
||||
assert_eq!(info.name.as_deref(), Some("my_gnome.webm"));
|
||||
assert_eq!(info.mimetype.as_deref(), Some("video/webm"));
|
||||
assert_eq!(info.size, Some(uint!(123_774)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -370,20 +354,16 @@ fn room_message_stable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::Video(_));
|
||||
if let MessageType::Video(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_video.mp4");
|
||||
assert_matches!(content.source, MediaSource::Plain(_));
|
||||
if let MediaSource::Plain(url) = content.source {
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_video.mp4");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
let content = assert_matches!(event_content.msgtype, MessageType::Video(content) => content);
|
||||
assert_eq!(content.body, "Upload: my_video.mp4");
|
||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_video.mp4");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -400,18 +380,14 @@ fn room_message_unstable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::Video(_));
|
||||
if let MessageType::Video(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_video.mp4");
|
||||
assert_matches!(content.source, MediaSource::Plain(_));
|
||||
if let MediaSource::Plain(url) = content.source {
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_video.mp4");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
let content = assert_matches!(event_content.msgtype, MessageType::Video(content) => content);
|
||||
assert_eq!(content.body, "Upload: my_video.mp4");
|
||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_video.mp4");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
@ -113,38 +113,27 @@ fn message_event_deserialization() {
|
||||
"type": "m.voice",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Voice(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: VoiceEventContent {
|
||||
message,
|
||||
file: FileContent {
|
||||
url,
|
||||
info: Some(info),
|
||||
..
|
||||
},
|
||||
audio,
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("Voice message")
|
||||
&& message.find_html().is_none()
|
||||
&& url == "mxc://notareal.hs/abcdef"
|
||||
&& info.name.as_deref() == Some("voice_message.ogg")
|
||||
&& info.mimetype.as_deref() == Some("audio/opus")
|
||||
&& info.size == Some(uint!(123_774))
|
||||
&& audio.duration == Some(Duration::from_millis(5_300))
|
||||
&& audio.waveform.is_none()
|
||||
&& origin_server_ts == MilliSecondsSinceUnixEpoch(uint!(134_829_848))
|
||||
&& room_id == room_id!("!roomid:notareal.hs")
|
||||
&& sender == user_id!("@user:notareal.hs")
|
||||
&& unsigned.is_empty()
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data),
|
||||
Ok(AnyMessageLikeEvent::Voice(MessageLikeEvent::Original(ev))) => ev
|
||||
);
|
||||
assert_eq!(ev.event_id, "$event:notareal.hs");
|
||||
assert_eq!(ev.origin_server_ts, MilliSecondsSinceUnixEpoch(uint!(134_829_848)));
|
||||
assert_eq!(ev.room_id, "!roomid:notareal.hs");
|
||||
assert_eq!(ev.sender, "@user:notareal.hs");
|
||||
assert!(ev.unsigned.is_empty());
|
||||
|
||||
let content = ev.content;
|
||||
assert_eq!(content.message.find_plain(), Some("Voice message"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert_eq!(content.audio.duration, Some(Duration::from_millis(5_300)));
|
||||
assert_matches!(content.audio.waveform, None);
|
||||
|
||||
let info = content.file.info.unwrap();
|
||||
assert_eq!(info.name.as_deref(), Some("voice_message.ogg"));
|
||||
assert_eq!(info.mimetype.as_deref(), Some("audio/opus"));
|
||||
assert_eq!(info.size, Some(uint!(123_774)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -190,21 +179,17 @@ fn room_message_stable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::Audio(_));
|
||||
if let MessageType::Audio(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: voice_message.ogg");
|
||||
assert_matches!(content.source, MediaSource::Plain(_));
|
||||
if let MediaSource::Plain(url) = content.source {
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: voice_message.ogg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
assert!(content.voice.is_some());
|
||||
}
|
||||
let content = assert_matches!(event_content.msgtype, MessageType::Audio(content) => content);
|
||||
assert_eq!(content.body, "Upload: voice_message.ogg");
|
||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: voice_message.ogg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
assert!(content.voice.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -222,19 +207,15 @@ fn room_message_unstable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::Audio(_));
|
||||
if let MessageType::Audio(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: voice_message.ogg");
|
||||
assert_matches!(content.source, MediaSource::Plain(_));
|
||||
if let MediaSource::Plain(url) = content.source {
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: voice_message.ogg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
assert!(content.voice.is_some());
|
||||
}
|
||||
let content = assert_matches!(event_content.msgtype, MessageType::Audio(content) => content);
|
||||
assert_eq!(content.body, "Upload: voice_message.ogg");
|
||||
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
|
||||
assert_eq!(url, "mxc://notareal.hs/file");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: voice_message.ogg");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
assert!(content.voice.is_some());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user