events: Reorganize tests

Move tests to the proper files, streamline test names and remove
duplicates.
This commit is contained in:
Kévin Commaille 2023-02-23 19:01:42 +01:00 committed by Kévin Commaille
parent 54d27f1083
commit 32901da35f
11 changed files with 977 additions and 1032 deletions

View File

@ -12,10 +12,7 @@ use ruma_common::{
file::{EncryptedContentInit, FileContent, FileContentInfo},
message::MessageContent,
relation::InReplyTo,
room::{
message::{AudioMessageEventContent, MessageType, Relation, RoomMessageEventContent},
JsonWebKeyInit, MediaSource,
},
room::{message::Relation, JsonWebKeyInit},
AnyMessageLikeEvent, MessageLikeEvent,
},
mxc_uri,
@ -329,37 +326,3 @@ fn message_event_deserialization() {
assert_eq!(content.audio.duration, Some(Duration::from_millis(5_300)));
assert_matches!(content.audio.waveform, None);
}
#[test]
fn room_message_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
"Upload: my_song.mp3".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_song.mp3",
"url": "mxc://notareal.hs/file",
"msgtype": "m.audio",
})
);
}
#[test]
fn room_message_deserialization() {
let json_data = json!({
"body": "Upload: my_song.mp3",
"url": "mxc://notareal.hs/file",
"msgtype": "m.audio",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::Audio(content) => content);
assert_eq!(content.body, "Upload: my_song.mp3");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_eq!(url, "mxc://notareal.hs/file");
}

View File

@ -1,27 +1,131 @@
#![cfg(feature = "unstable-msc2746")]
use assert_matches::assert_matches;
use assign::assign;
use js_int::uint;
use ruma_common::{
events::{
call::{
answer::CallAnswerEventContent,
candidates::{CallCandidatesEventContent, Candidate},
hangup::{CallHangupEventContent, Reason},
hangup::CallHangupEventContent,
invite::CallInviteEventContent,
negotiate::CallNegotiateEventContent,
reject::CallRejectEventContent,
select_answer::CallSelectAnswerEventContent,
AnswerSessionDescription, CallCapabilities, OfferSessionDescription,
SessionDescription, SessionDescriptionType,
AnswerSessionDescription, OfferSessionDescription,
},
AnyMessageLikeEvent, MessageLikeEvent,
AnyMessageLikeEvent, AnySyncMessageLikeEvent, MessageLikeEvent,
},
VoipVersionId,
room_id,
serde::CanBeEmpty,
MilliSecondsSinceUnixEpoch, VoipVersionId,
};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
#[test]
fn answer_content_serialization() {
let event_content = CallAnswerEventContent::version_0(
AnswerSessionDescription::new("not a real sdp".to_owned()),
"abcdef".into(),
);
assert_eq!(
to_json_value(&event_content).unwrap(),
json!({
"call_id": "abcdef",
"version": 0,
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
})
);
}
#[test]
fn answer_content_deserialization() {
let json_data = json!({
"answer": {
"type": "answer",
"sdp": "Hello"
},
"call_id": "foofoo",
"version": 0
});
let content = from_json_value::<CallAnswerEventContent>(json_data).unwrap();
assert_eq!(content.answer.sdp, "Hello");
assert_eq!(content.call_id, "foofoo");
assert_eq!(content.version, VoipVersionId::V0);
}
#[test]
fn answer_event_deserialization() {
let json_data = json!({
"content": {
"answer": {
"type": "answer",
"sdp": "Hello"
},
"call_id": "foofoo",
"version": 0
},
"event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1,
"room_id": "!roomid:room.com",
"sender": "@carl:example.com",
"type": "m.call.answer"
});
let message_event = assert_matches!(
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
AnyMessageLikeEvent::CallAnswer(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.answer.sdp, "Hello");
assert_eq!(content.call_id, "foofoo");
assert_eq!(content.version, VoipVersionId::V0);
}
#[test]
fn answer_event_deserialization_then_convert_to_full() {
let rid = room_id!("!roomid:room.com");
let json_data = json!({
"content": {
"answer": {
"type": "answer",
"sdp": "Hello",
},
"call_id": "foofoo",
"version": 0,
},
"event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1,
"sender": "@carl:example.com",
"type": "m.call.answer",
});
let sync_ev: AnySyncMessageLikeEvent = from_json_value(json_data).unwrap();
let message_event = assert_matches!(
sync_ev.into_full_event(rid.to_owned()),
AnyMessageLikeEvent::CallAnswer(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.answer.sdp, "Hello");
assert_eq!(content.call_id, "foofoo");
assert_eq!(content.version, VoipVersionId::V0);
}
#[test]
fn invite_content_serialization() {
let event_content = CallInviteEventContent::version_0(
@ -44,6 +148,67 @@ fn invite_content_serialization() {
);
}
#[test]
fn candidates_content_serialization() {
let event_content = CallCandidatesEventContent::version_0(
"abcdef".into(),
vec![Candidate::new("not a real candidate".to_owned(), "0".to_owned(), uint!(0))],
);
assert_eq!(
to_json_value(&event_content).unwrap(),
json!({
"call_id": "abcdef",
"version": 0,
"candidates": [
{
"candidate": "not a real candidate",
"sdpMid": "0",
"sdpMLineIndex": 0,
},
],
})
);
}
#[test]
fn hangup_content_serialization() {
let event_content = CallHangupEventContent::version_0("abcdef".into());
assert_eq!(
to_json_value(&event_content).unwrap(),
json!({
"call_id": "abcdef",
"version": 0,
"reason": "user_hangup",
})
);
}
#[cfg(feature = "unstable-msc2746")]
mod msc2746 {
use assert_matches::assert_matches;
use assign::assign;
use js_int::uint;
use ruma_common::{
events::{
call::{
answer::CallAnswerEventContent,
candidates::{CallCandidatesEventContent, Candidate},
hangup::{CallHangupEventContent, Reason},
invite::CallInviteEventContent,
negotiate::CallNegotiateEventContent,
reject::CallRejectEventContent,
select_answer::CallSelectAnswerEventContent,
AnswerSessionDescription, CallCapabilities, OfferSessionDescription,
SessionDescription, SessionDescriptionType,
},
AnyMessageLikeEvent, MessageLikeEvent,
},
VoipVersionId,
};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
#[test]
fn invite_event_serialization() {
let content = CallInviteEventContent::version_1(
@ -103,26 +268,6 @@ fn invite_event_deserialization() {
assert!(!content.capabilities.dtmf);
}
#[test]
fn answer_content_serialization() {
let event_content = CallAnswerEventContent::version_0(
AnswerSessionDescription::new("not a real sdp".to_owned()),
"abcdef".into(),
);
assert_eq!(
to_json_value(&event_content).unwrap(),
json!({
"call_id": "abcdef",
"version": 0,
"answer": {
"type": "answer",
"sdp": "not a real sdp",
},
})
);
}
#[test]
fn answer_event_serialization() {
let content = CallAnswerEventContent::version_1(
@ -184,29 +329,6 @@ fn answer_event_deserialization() {
assert!(content.capabilities.dtmf);
}
#[test]
fn candidates_content_serialization() {
let event_content = CallCandidatesEventContent::version_0(
"abcdef".into(),
vec![Candidate::new("not a real candidate".to_owned(), "0".to_owned(), uint!(0))],
);
assert_eq!(
to_json_value(&event_content).unwrap(),
json!({
"call_id": "abcdef",
"version": 0,
"candidates": [
{
"candidate": "not a real candidate",
"sdpMid": "0",
"sdpMLineIndex": 0,
},
],
})
);
}
#[test]
fn candidates_event_serialization() {
let content = CallCandidatesEventContent::version_1(
@ -285,20 +407,6 @@ fn candidates_event_deserialization() {
assert_eq!(content.candidates[1].sdp_m_line_index, uint!(1));
}
#[test]
fn hangup_content_serialization() {
let event_content = CallHangupEventContent::version_0("abcdef".into());
assert_eq!(
to_json_value(&event_content).unwrap(),
json!({
"call_id": "abcdef",
"version": 0,
"reason": "user_hangup",
})
);
}
#[test]
fn hangup_event_serialization() {
let content =
@ -480,3 +588,4 @@ fn select_answer_event_deserialization() {
assert_eq!(content.selected_party_id, "6336");
assert_eq!(content.version, VoipVersionId::V1);
}
}

View File

@ -9,10 +9,7 @@ use ruma_common::{
file::{EncryptedContentInit, FileContentInfo, FileEventContent},
message::MessageContent,
relation::InReplyTo,
room::{
message::{FileMessageEventContent, MessageType, Relation, RoomMessageEventContent},
EncryptedFileInit, JsonWebKeyInit, MediaSource,
},
room::{message::Relation, JsonWebKeyInit},
AnyMessageLikeEvent, MessageLikeEvent,
},
mxc_uri,
@ -217,116 +214,3 @@ fn message_event_deserialization() {
assert_eq!(message_event.sender, "@user:notareal.hs");
assert!(message_event.unsigned.is_empty());
}
#[test]
fn room_message_plain_content_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::File(FileMessageEventContent::plain(
"Upload: my_file.txt".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_file.txt",
"url": "mxc://notareal.hs/file",
"msgtype": "m.file",
})
);
}
#[test]
fn room_message_encrypted_content_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::File(FileMessageEventContent::encrypted(
"Upload: my_file.txt".to_owned(),
EncryptedFileInit {
url: mxc_uri!("mxc://notareal.hs/file").to_owned(),
key: JsonWebKeyInit {
kty: "oct".to_owned(),
key_ops: vec!["encrypt".to_owned(), "decrypt".to_owned()],
alg: "A256CTR".to_owned(),
k: Base64::parse("TLlG_OpX807zzQuuwv4QZGJ21_u7weemFGYJFszMn9A").unwrap(),
ext: true,
}
.into(),
iv: Base64::parse("S22dq3NAX8wAAAAAAAAAAA").unwrap(),
hashes: [(
"sha256".to_owned(),
Base64::parse("aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q").unwrap(),
)]
.into(),
v: "v2".to_owned(),
}
.into(),
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_file.txt",
"file": {
"url": "mxc://notareal.hs/file",
"key": {
"kty": "oct",
"key_ops": ["encrypt", "decrypt"],
"alg": "A256CTR",
"k": "TLlG_OpX807zzQuuwv4QZGJ21_u7weemFGYJFszMn9A",
"ext": true
},
"iv": "S22dq3NAX8wAAAAAAAAAAA",
"hashes": {
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
},
"v": "v2",
},
"msgtype": "m.file",
})
);
}
#[test]
fn room_message_plain_content_deserialization() {
let json_data = json!({
"body": "Upload: my_file.txt",
"url": "mxc://notareal.hs/file",
"msgtype": "m.file",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::File(content) => content);
assert_eq!(content.body, "Upload: my_file.txt");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_eq!(url, "mxc://notareal.hs/file");
}
#[test]
fn room_message_encrypted_content_deserialization() {
let json_data = json!({
"body": "Upload: my_file.txt",
"file": {
"url": "mxc://notareal.hs/file",
"key": {
"kty": "oct",
"key_ops": ["encrypt", "decrypt"],
"alg": "A256CTR",
"k": "TLlG_OpX807zzQuuwv4QZGJ21_u7weemFGYJFszMn9A",
"ext": true
},
"iv": "S22dq3NAX8wAAAAAAAAAAA",
"hashes": {
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
},
"v": "v2",
},
"msgtype": "m.file",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::File(content) => content);
assert_eq!(content.body, "Upload: my_file.txt");
let encrypted_file = assert_matches!(content.source, MediaSource::Encrypted(f) => f);
assert_eq!(encrypted_file.url, "mxc://notareal.hs/file");
}

View File

@ -13,10 +13,7 @@ use ruma_common::{
},
message::MessageContent,
relation::InReplyTo,
room::{
message::{ImageMessageEventContent, MessageType, Relation, RoomMessageEventContent},
JsonWebKeyInit, MediaSource,
},
room::{message::Relation, JsonWebKeyInit},
AnyMessageLikeEvent, MessageLikeEvent,
},
mxc_uri,
@ -285,37 +282,3 @@ fn message_event_deserialization() {
assert_eq!(content.image.height, Some(uint!(837)));
assert_eq!(content.thumbnail.len(), 0);
}
#[test]
fn room_message_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Image(ImageMessageEventContent::plain(
"Upload: my_image.jpg".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_image.jpg",
"url": "mxc://notareal.hs/file",
"msgtype": "m.image",
})
);
}
#[test]
fn room_message_deserialization() {
let json_data = json!({
"body": "Upload: my_image.jpg",
"url": "mxc://notareal.hs/file",
"msgtype": "m.image",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
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");
}

View File

@ -9,9 +9,7 @@ use ruma_common::{
location::{AssetType, LocationContent, LocationEventContent, ZoomLevel, ZoomLevelError},
message::MessageContent,
relation::InReplyTo,
room::message::{
LocationMessageEventContent, MessageType, Relation, RoomMessageEventContent,
},
room::message::Relation,
AnyMessageLikeEvent, MessageLikeEvent,
},
room_id,
@ -178,36 +176,3 @@ fn message_event_deserialization() {
assert_eq!(ev.sender, user_id!("@user:notareal.hs"));
assert!(ev.unsigned.is_empty());
}
#[test]
fn room_message_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Location(LocationMessageEventContent::new(
"Alice was at geo:51.5008,0.1247;u=35".to_owned(),
"geo:51.5008,0.1247;u=35".to_owned(),
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Alice was at geo:51.5008,0.1247;u=35",
"geo_uri": "geo:51.5008,0.1247;u=35",
"msgtype": "m.location",
})
);
}
#[test]
fn room_message_deserialization() {
let json_data = json!({
"body": "Alice was at geo:51.5008,0.1247;u=35",
"geo_uri": "geo:51.5008,0.1247;u=35",
"msgtype": "m.location",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::Location(c) => c);
assert_eq!(content.body, "Alice was at geo:51.5008,0.1247;u=35");
assert_eq!(content.geo_uri, "geo:51.5008,0.1247;u=35");
}

View File

@ -10,7 +10,7 @@ use ruma_common::{
message::{MessageContent, MessageEventContent, Text},
notice::NoticeEventContent,
relation::InReplyTo,
room::message::{EmoteMessageEventContent, MessageType, Relation, RoomMessageEventContent},
room::message::Relation,
AnyMessageLikeEvent, MessageLikeEvent,
},
serde::CanBeEmpty,
@ -295,44 +295,6 @@ fn message_event_deserialization() {
assert!(message_event.unsigned.is_empty());
}
#[test]
fn room_message_plain_text_deserialization() {
let json_data = json!({
"body": "test",
"msgtype": "m.text",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(content),
..
}) => content
);
assert_eq!(content.body, "test");
}
#[test]
fn room_message_html_and_text_deserialization() {
let json_data = json!({
"body": "test",
"formatted_body": "<h1>test</h1>",
"format": "org.matrix.custom.html",
"msgtype": "m.text",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(content),
..
}) => content
);
assert_eq!(content.body, "test");
let formatted = content.formatted.unwrap();
assert_eq!(formatted.body, "<h1>test</h1>");
}
#[test]
fn notice_event_serialization() {
let content = NoticeEventContent::plain("Hello, I'm a robot!");
@ -342,20 +304,6 @@ fn notice_event_serialization() {
);
}
#[test]
fn room_message_notice_serialization() {
let message_event_content =
RoomMessageEventContent::notice_plain("> <@test:example.com> test\n\ntest reply");
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "> <@test:example.com> test\n\ntest reply",
"msgtype": "m.notice",
})
);
}
#[test]
fn notice_event_stable_deserialization() {
let json_data = json!({
@ -420,23 +368,6 @@ fn notice_event_unstable_deserialization() {
assert_eq!(message.find_html(), Some("Hello, I'm a <em>robot</em>!"));
}
#[test]
fn room_message_notice_deserialization() {
let json_data = json!({
"body": "test",
"msgtype": "m.notice",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Notice(content),
..
}) => content
);
assert_eq!(content.body, "test");
}
#[test]
fn emote_event_serialization() {
let content =
@ -451,21 +382,6 @@ fn emote_event_serialization() {
);
}
#[test]
fn room_message_emote_serialization() {
let message_event_content = RoomMessageEventContent::new(MessageType::Emote(
EmoteMessageEventContent::plain("> <@test:example.com> test\n\ntest reply"),
));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "> <@test:example.com> test\n\ntest reply",
"msgtype": "m.emote",
})
);
}
#[test]
fn emote_event_stable_deserialization() {
let json_data = json!({
@ -524,23 +440,6 @@ fn emote_event_unstable_deserialization() {
assert_eq!(message.find_html(), None);
}
#[test]
fn room_message_emote_deserialization() {
let json_data = json!({
"body": "test",
"msgtype": "m.emote",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Emote(content),
..
}) => content
);
assert_eq!(content.body, "test");
}
#[test]
#[cfg(feature = "unstable-msc3554")]
fn lang_serialization() {

View File

@ -1,203 +0,0 @@
use assert_matches::assert_matches;
use assign::assign;
use js_int::{uint, UInt};
use ruma_common::{
events::{
call::answer::CallAnswerEventContent,
room::{ImageInfo, MediaSource, ThumbnailInfo},
sticker::StickerEventContent,
AnyMessageLikeEvent, AnySyncMessageLikeEvent, MessageLikeEvent,
},
mxc_uri, room_id,
serde::CanBeEmpty,
MilliSecondsSinceUnixEpoch, VoipVersionId,
};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
#[test]
fn message_serialize_sticker() {
let content = StickerEventContent::new(
"Hello".into(),
assign!(ImageInfo::new(), {
height: UInt::new(423),
width: UInt::new(1011),
mimetype: Some("image/png".into()),
size: UInt::new(84242),
thumbnail_info: Some(Box::new(assign!(ThumbnailInfo::new(), {
width: UInt::new(800),
height: UInt::new(334),
mimetype: Some("image/png".into()),
size: UInt::new(82595),
}))),
thumbnail_source: Some(MediaSource::Plain(mxc_uri!("mxc://matrix.org/irsns989Rrsn").to_owned())),
}),
mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs").to_owned(),
);
let actual = to_json_value(&content).unwrap();
let expected = json!({
"body": "Hello",
"info": {
"h": 423,
"mimetype": "image/png",
"size": 84242,
"thumbnail_info": {
"h": 334,
"mimetype": "image/png",
"size": 82595,
"w": 800
},
"thumbnail_url": "mxc://matrix.org/irsns989Rrsn",
"w": 1011
},
"url": "mxc://matrix.org/rnsldl8srs98IRrs",
});
assert_eq!(actual, expected);
}
#[test]
fn deserialize_message_call_answer_content() {
let json_data = json!({
"answer": {
"type": "answer",
"sdp": "Hello"
},
"call_id": "foofoo",
"version": 0
});
let content = from_json_value::<CallAnswerEventContent>(json_data).unwrap();
assert_eq!(content.answer.sdp, "Hello");
assert_eq!(content.call_id, "foofoo");
assert_eq!(content.version, VoipVersionId::V0);
}
#[test]
fn deserialize_message_call_answer() {
let json_data = json!({
"content": {
"answer": {
"type": "answer",
"sdp": "Hello"
},
"call_id": "foofoo",
"version": 0
},
"event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1,
"room_id": "!roomid:room.com",
"sender": "@carl:example.com",
"type": "m.call.answer"
});
let message_event = assert_matches!(
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
AnyMessageLikeEvent::CallAnswer(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.answer.sdp, "Hello");
assert_eq!(content.call_id, "foofoo");
assert_eq!(content.version, VoipVersionId::V0);
}
#[test]
fn deserialize_message_sticker() {
let json_data = json!({
"content": {
"body": "Hello",
"info": {
"h": 423,
"mimetype": "image/png",
"size": 84242,
"thumbnail_info": {
"h": 334,
"mimetype": "image/png",
"size": 82595,
"w": 800
},
"thumbnail_url": "mxc://matrix.org/irnsNRS2879",
"w": 1011
},
"url": "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD"
},
"event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1,
"room_id": "!roomid:room.com",
"sender": "@carl:example.com",
"type": "m.sticker"
});
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]
fn deserialize_message_then_convert_to_full() {
let rid = room_id!("!roomid:room.com");
let json_data = json!({
"content": {
"answer": {
"type": "answer",
"sdp": "Hello"
},
"call_id": "foofoo",
"version": 0
},
"event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1,
"sender": "@carl:example.com",
"type": "m.call.answer"
});
let sync_ev: AnySyncMessageLikeEvent = from_json_value(json_data).unwrap();
let message_event = assert_matches!(
sync_ev.into_full_event(rid.to_owned()),
AnyMessageLikeEvent::CallAnswer(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.answer.sdp, "Hello");
assert_eq!(content.call_id, "foofoo");
assert_eq!(content.version, VoipVersionId::V0);
}

View File

@ -13,7 +13,6 @@ mod image;
mod initial_state;
mod location;
mod message;
mod message_event;
mod pdu;
mod poll;
mod redacted;

View File

@ -8,15 +8,18 @@ use ruma_common::{
key::verification::VerificationMethod,
room::{
message::{
AudioMessageEventContent, ForwardThread, KeyVerificationRequestEventContent,
MessageType, OriginalRoomMessageEvent, RoomMessageEventContent,
TextMessageEventContent,
AudioMessageEventContent, EmoteMessageEventContent, FileMessageEventContent,
ForwardThread, ImageMessageEventContent, KeyVerificationRequestEventContent,
LocationMessageEventContent, MessageType, OriginalRoomMessageEvent,
RoomMessageEventContent, TextMessageEventContent, VideoMessageEventContent,
},
MediaSource,
EncryptedFileInit, JsonWebKeyInit, MediaSource,
},
MessageLikeUnsigned,
},
mxc_uri, room_id, user_id, MilliSecondsSinceUnixEpoch, OwnedDeviceId,
mxc_uri, room_id,
serde::Base64,
user_id, MilliSecondsSinceUnixEpoch, OwnedDeviceId,
};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -32,44 +35,6 @@ macro_rules! json_object {
};
}
#[test]
fn serialization() {
let content =
RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
"test".into(),
mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd").to_owned(),
None,
)));
assert_eq!(
to_json_value(content).unwrap(),
json!({
"body": "test",
"msgtype": "m.audio",
"url": "mxc://example.org/ffed755USFFxlgbQYZGtryd",
})
);
}
#[test]
fn content_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
"test".into(),
mxc_uri!("mxc://example.org/ffed755USFFxlgbQYZGtryd").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "test",
"msgtype": "m.audio",
"url": "mxc://example.org/ffed755USFFxlgbQYZGtryd"
})
);
}
#[test]
fn custom_msgtype_serialization() {
let json_data = json_object! {
@ -91,7 +56,7 @@ fn custom_msgtype_serialization() {
}
#[test]
fn custom_content_deserialization() {
fn custom_msgtype_deserialization() {
let json_data = json!({
"msgtype": "my_custom_msgtype",
"body": "my custom message",
@ -112,7 +77,7 @@ fn custom_content_deserialization() {
}
#[test]
fn formatted_body_serialization() {
fn text_msgtype_formatted_body_serialization() {
let message_event_content =
RoomMessageEventContent::text_html("Hello, World!", "Hello, <em>World</em>!");
@ -128,7 +93,7 @@ fn formatted_body_serialization() {
}
#[test]
fn plain_text_content_serialization() {
fn text_msgtype_plain_text_serialization() {
let message_event_content =
RoomMessageEventContent::text_plain("> <@test:example.com> test\n\ntest reply");
@ -143,7 +108,7 @@ fn plain_text_content_serialization() {
#[test]
#[cfg(feature = "markdown")]
fn markdown_content_serialization() {
fn text_msgtype_markdown_serialization() {
use ruma_common::events::room::message::TextMessageEventContent;
let formatted_message = RoomMessageEventContent::new(MessageType::Text(
@ -232,7 +197,7 @@ fn markdown_options() {
}
#[test]
fn verification_request_deserialization() {
fn verification_request_msgtype_deserialization() {
let user_id = user_id!("@example2:localhost");
let device_id: OwnedDeviceId = "XOWLHHFSWM".into();
@ -264,7 +229,7 @@ fn verification_request_deserialization() {
}
#[test]
fn verification_request_serialization() {
fn verification_request_msgtype_serialization() {
let user_id = user_id!("@example2:localhost").to_owned();
let device_id: OwnedDeviceId = "XOWLHHFSWM".into();
let body = "@example:localhost is requesting to verify your key, ...".to_owned();
@ -287,31 +252,11 @@ fn verification_request_serialization() {
assert_eq!(to_json_value(&content).unwrap(), json_data,);
}
#[test]
fn content_deserialization() {
let json_data = json!({
"body": "test",
"msgtype": "m.audio",
"url": "mxc://example.org/ffed755USFFxlgbQYZGtryd"
});
let content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let audio = assert_matches!(
content.msgtype,
MessageType::Audio(audio) => 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");
assert_matches!(content.relates_to, None);
}
#[test]
fn content_deserialization_failure() {
let json_data = json!({
"body": "test","msgtype": "m.location",
"body": "test",
"msgtype": "m.location",
"url": "http://example.com/audio.mp3"
});
assert_matches!(from_json_value::<RoomMessageEventContent>(json_data), Err(_));
@ -529,3 +474,352 @@ fn make_replacement_with_reply() {
"
);
}
#[test]
fn audio_msgtype_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
"Upload: my_song.mp3".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_song.mp3",
"url": "mxc://notareal.hs/file",
"msgtype": "m.audio",
})
);
}
#[test]
fn audio_msgtype_deserialization() {
let json_data = json!({
"body": "Upload: my_song.mp3",
"url": "mxc://notareal.hs/file",
"msgtype": "m.audio",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::Audio(content) => content);
assert_eq!(content.body, "Upload: my_song.mp3");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_eq!(url, "mxc://notareal.hs/file");
}
#[test]
fn file_msgtype_plain_content_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::File(FileMessageEventContent::plain(
"Upload: my_file.txt".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_file.txt",
"url": "mxc://notareal.hs/file",
"msgtype": "m.file",
})
);
}
#[test]
fn file_msgtype_encrypted_content_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::File(FileMessageEventContent::encrypted(
"Upload: my_file.txt".to_owned(),
EncryptedFileInit {
url: mxc_uri!("mxc://notareal.hs/file").to_owned(),
key: JsonWebKeyInit {
kty: "oct".to_owned(),
key_ops: vec!["encrypt".to_owned(), "decrypt".to_owned()],
alg: "A256CTR".to_owned(),
k: Base64::parse("TLlG_OpX807zzQuuwv4QZGJ21_u7weemFGYJFszMn9A").unwrap(),
ext: true,
}
.into(),
iv: Base64::parse("S22dq3NAX8wAAAAAAAAAAA").unwrap(),
hashes: [(
"sha256".to_owned(),
Base64::parse("aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q").unwrap(),
)]
.into(),
v: "v2".to_owned(),
}
.into(),
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_file.txt",
"file": {
"url": "mxc://notareal.hs/file",
"key": {
"kty": "oct",
"key_ops": ["encrypt", "decrypt"],
"alg": "A256CTR",
"k": "TLlG_OpX807zzQuuwv4QZGJ21_u7weemFGYJFszMn9A",
"ext": true
},
"iv": "S22dq3NAX8wAAAAAAAAAAA",
"hashes": {
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
},
"v": "v2",
},
"msgtype": "m.file",
})
);
}
#[test]
fn file_msgtype_plain_content_deserialization() {
let json_data = json!({
"body": "Upload: my_file.txt",
"url": "mxc://notareal.hs/file",
"msgtype": "m.file",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::File(content) => content);
assert_eq!(content.body, "Upload: my_file.txt");
let url = assert_matches!(content.source, MediaSource::Plain(url) => url);
assert_eq!(url, "mxc://notareal.hs/file");
}
#[test]
fn file_msgtype_encrypted_content_deserialization() {
let json_data = json!({
"body": "Upload: my_file.txt",
"file": {
"url": "mxc://notareal.hs/file",
"key": {
"kty": "oct",
"key_ops": ["encrypt", "decrypt"],
"alg": "A256CTR",
"k": "TLlG_OpX807zzQuuwv4QZGJ21_u7weemFGYJFszMn9A",
"ext": true
},
"iv": "S22dq3NAX8wAAAAAAAAAAA",
"hashes": {
"sha256": "aWOHudBnDkJ9IwaR1Nd8XKoI7DOrqDTwt6xDPfVGN6Q"
},
"v": "v2",
},
"msgtype": "m.file",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::File(content) => content);
assert_eq!(content.body, "Upload: my_file.txt");
let encrypted_file = assert_matches!(content.source, MediaSource::Encrypted(f) => f);
assert_eq!(encrypted_file.url, "mxc://notareal.hs/file");
}
#[test]
fn image_msgtype_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Image(ImageMessageEventContent::plain(
"Upload: my_image.jpg".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_image.jpg",
"url": "mxc://notareal.hs/file",
"msgtype": "m.image",
})
);
}
#[test]
fn image_msgtype_deserialization() {
let json_data = json!({
"body": "Upload: my_image.jpg",
"url": "mxc://notareal.hs/file",
"msgtype": "m.image",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
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");
}
#[test]
fn location_msgtype_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Location(LocationMessageEventContent::new(
"Alice was at geo:51.5008,0.1247;u=35".to_owned(),
"geo:51.5008,0.1247;u=35".to_owned(),
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Alice was at geo:51.5008,0.1247;u=35",
"geo_uri": "geo:51.5008,0.1247;u=35",
"msgtype": "m.location",
})
);
}
#[test]
fn location_msgtype_deserialization() {
let json_data = json!({
"body": "Alice was at geo:51.5008,0.1247;u=35",
"geo_uri": "geo:51.5008,0.1247;u=35",
"msgtype": "m.location",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
let content = assert_matches!(event_content.msgtype, MessageType::Location(c) => c);
assert_eq!(content.body, "Alice was at geo:51.5008,0.1247;u=35");
assert_eq!(content.geo_uri, "geo:51.5008,0.1247;u=35");
}
#[test]
fn text_msgtype_body_deserialization() {
let json_data = json!({
"body": "test",
"msgtype": "m.text",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(content),
..
}) => content
);
assert_eq!(content.body, "test");
}
#[test]
fn text_msgtype_formatted_body_and_body_deserialization() {
let json_data = json!({
"body": "test",
"formatted_body": "<h1>test</h1>",
"format": "org.matrix.custom.html",
"msgtype": "m.text",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Text(content),
..
}) => content
);
assert_eq!(content.body, "test");
let formatted = content.formatted.unwrap();
assert_eq!(formatted.body, "<h1>test</h1>");
}
#[test]
fn notice_msgtype_serialization() {
let message_event_content =
RoomMessageEventContent::notice_plain("> <@test:example.com> test\n\ntest reply");
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "> <@test:example.com> test\n\ntest reply",
"msgtype": "m.notice",
})
);
}
#[test]
fn notice_msgtype_deserialization() {
let json_data = json!({
"body": "test",
"msgtype": "m.notice",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Notice(content),
..
}) => content
);
assert_eq!(content.body, "test");
}
#[test]
fn emote_msgtype_serialization() {
let message_event_content = RoomMessageEventContent::new(MessageType::Emote(
EmoteMessageEventContent::plain("> <@test:example.com> test\n\ntest reply"),
));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "> <@test:example.com> test\n\ntest reply",
"msgtype": "m.emote",
})
);
}
#[test]
fn emote_msgtype_deserialization() {
let json_data = json!({
"body": "test",
"msgtype": "m.emote",
});
let content = assert_matches!(
from_json_value::<RoomMessageEventContent>(json_data),
Ok(RoomMessageEventContent {
msgtype: MessageType::Emote(content),
..
}) => content
);
assert_eq!(content.body, "test");
}
#[test]
fn video_msgtype_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Video(VideoMessageEventContent::plain(
"Upload: my_video.mp4".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_video.mp4",
"url": "mxc://notareal.hs/file",
"msgtype": "m.video",
})
);
}
#[test]
fn video_msgtype_deserialization() {
let json_data = json!({
"body": "Upload: my_video.mp4",
"url": "mxc://notareal.hs/file",
"msgtype": "m.video",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
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");
}

View File

@ -1,6 +1,15 @@
use assert_matches::assert_matches;
use assign::assign;
use js_int::{uint, UInt};
use ruma_common::{
events::{room::ImageInfo, sticker::StickerEventContent},
events::{
room::{ImageInfo, MediaSource, ThumbnailInfo},
sticker::StickerEventContent,
AnyMessageLikeEvent, MessageLikeEvent,
},
mxc_uri,
serde::CanBeEmpty,
MilliSecondsSinceUnixEpoch,
};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -22,6 +31,48 @@ fn content_serialization() {
);
}
#[test]
fn event_serialization() {
let content = StickerEventContent::new(
"Hello".into(),
assign!(ImageInfo::new(), {
height: UInt::new(423),
width: UInt::new(1011),
mimetype: Some("image/png".into()),
size: UInt::new(84242),
thumbnail_info: Some(Box::new(assign!(ThumbnailInfo::new(), {
width: UInt::new(800),
height: UInt::new(334),
mimetype: Some("image/png".into()),
size: UInt::new(82595),
}))),
thumbnail_source: Some(MediaSource::Plain(mxc_uri!("mxc://matrix.org/irsns989Rrsn").to_owned())),
}),
mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs").to_owned(),
);
let actual = to_json_value(&content).unwrap();
let expected = json!({
"body": "Hello",
"info": {
"h": 423,
"mimetype": "image/png",
"size": 84242,
"thumbnail_info": {
"h": 334,
"mimetype": "image/png",
"size": 82595,
"w": 800
},
"thumbnail_url": "mxc://matrix.org/irsns989Rrsn",
"w": 1011
},
"url": "mxc://matrix.org/rnsldl8srs98IRrs",
});
assert_eq!(actual, expected);
}
#[test]
fn content_deserialization() {
let json_data = json!({
@ -34,3 +85,61 @@ fn content_deserialization() {
assert_eq!(content.body, "Upload: my_image.jpg");
assert_eq!(content.url, "mxc://notareal.hs/file");
}
#[test]
fn event_deserialization() {
let json_data = json!({
"content": {
"body": "Hello",
"info": {
"h": 423,
"mimetype": "image/png",
"size": 84242,
"thumbnail_info": {
"h": 334,
"mimetype": "image/png",
"size": 82595,
"w": 800
},
"thumbnail_url": "mxc://matrix.org/irnsNRS2879",
"w": 1011
},
"url": "mxc://matrix.org/jxPXTKpyydzdHJkdFNZjTZrD"
},
"event_id": "$h29iv0s8:example.com",
"origin_server_ts": 1,
"room_id": "!roomid:room.com",
"sender": "@carl:example.com",
"type": "m.sticker"
});
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)));
}

View File

@ -12,10 +12,7 @@ use ruma_common::{
image::{ThumbnailContent, ThumbnailFileContent, ThumbnailFileContentInfo},
message::MessageContent,
relation::InReplyTo,
room::{
message::{MessageType, Relation, RoomMessageEventContent, VideoMessageEventContent},
JsonWebKeyInit, MediaSource,
},
room::{message::Relation, JsonWebKeyInit},
video::{VideoContent, VideoEventContent},
AnyMessageLikeEvent, MessageLikeEvent,
},
@ -298,37 +295,3 @@ fn message_event_deserialization() {
assert_eq!(info.mimetype.as_deref(), Some("video/webm"));
assert_eq!(info.size, Some(uint!(123_774)));
}
#[test]
fn room_message_serialization() {
let message_event_content =
RoomMessageEventContent::new(MessageType::Video(VideoMessageEventContent::plain(
"Upload: my_video.mp4".to_owned(),
mxc_uri!("mxc://notareal.hs/file").to_owned(),
None,
)));
assert_eq!(
to_json_value(&message_event_content).unwrap(),
json!({
"body": "Upload: my_video.mp4",
"url": "mxc://notareal.hs/file",
"msgtype": "m.video",
})
);
}
#[test]
fn room_message_deserialization() {
let json_data = json!({
"body": "Upload: my_video.mp4",
"url": "mxc://notareal.hs/file",
"msgtype": "m.video",
});
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
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");
}