events: Split more test assertions
This commit is contained in:
parent
c3d573e943
commit
a796b5e54d
@ -33,22 +33,17 @@ fn waveform_deserialization_pass() {
|
||||
13, 34, 987, 937, 345, 648, 1, 366, 235, 125, 904, 783, 734,
|
||||
]);
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<Waveform>(json_data),
|
||||
Ok(waveform) if waveform.amplitudes().len() == 52
|
||||
);
|
||||
let waveform = from_json_value::<Waveform>(json_data).unwrap();
|
||||
assert_eq!(waveform.amplitudes().len(), 52);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn waveform_deserialization_not_enough() {
|
||||
let json_data = json!([]);
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<Waveform>(json_data),
|
||||
Err(err)
|
||||
if err.is_data()
|
||||
&& format!("{}", err) == format!("{}", WaveformError::NotEnoughValues)
|
||||
);
|
||||
let err = from_json_value::<Waveform>(json_data).unwrap_err();
|
||||
assert!(err.is_data());
|
||||
assert_eq!(err.to_string(), WaveformError::NotEnoughValues.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -58,10 +53,8 @@ fn waveform_deserialization_clamp_amplitude() {
|
||||
2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000,
|
||||
]);
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<Waveform>(json_data).unwrap(),
|
||||
waveform if waveform.amplitudes().iter().all(|amp| amp.get() == Amplitude::MAX.into())
|
||||
);
|
||||
let waveform = from_json_value::<Waveform>(json_data).unwrap();
|
||||
assert!(waveform.amplitudes().iter().all(|amp| amp.get() == Amplitude::MAX.into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -272,20 +265,12 @@ fn plain_content_deserialization() {
|
||||
}
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AudioEventContent>(json_data)
|
||||
.unwrap(),
|
||||
AudioEventContent {
|
||||
message,
|
||||
file,
|
||||
audio: AudioContent { duration: None, waveform: Some(waveform), .. },
|
||||
..
|
||||
}
|
||||
if message.find_plain() == Some("Upload: my_new_song.webm")
|
||||
&& message.find_html().is_none()
|
||||
&& file.url == "mxc://notareal.hs/abcdef"
|
||||
&& waveform.amplitudes().len() == 52
|
||||
);
|
||||
let content = from_json_value::<AudioEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_new_song.webm"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
let waveform = content.audio.waveform.unwrap();
|
||||
assert_eq!(waveform.amplitudes().len(), 52);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -310,20 +295,11 @@ fn encrypted_content_deserialization() {
|
||||
"m.audio": {},
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AudioEventContent>(json_data)
|
||||
.unwrap(),
|
||||
AudioEventContent {
|
||||
message,
|
||||
file,
|
||||
audio: AudioContent { duration: None, waveform: 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()
|
||||
);
|
||||
let content = from_json_value::<AudioEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_file.txt"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert!(content.file.encryption_info.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -348,38 +324,27 @@ fn message_event_deserialization() {
|
||||
"type": "m.audio",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
let message_event = assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::Audio(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: AudioEventContent {
|
||||
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("Upload: airplane_sound.opus")
|
||||
&& message.find_html().is_none()
|
||||
&& url == "mxc://notareal.hs/abcdef"
|
||||
&& info.name.as_deref() == Some("airplane_sound.opus")
|
||||
&& 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()
|
||||
AnyMessageLikeEvent::Audio(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: airplane_sound.opus"));
|
||||
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("airplane_sound.opus"));
|
||||
assert_eq!(info.mimetype.as_deref(), Some("audio/opus"));
|
||||
assert_eq!(info.size, Some(uint!(123_774)));
|
||||
assert_eq!(content.audio.duration, Some(Duration::from_millis(5_300)));
|
||||
assert_matches!(content.audio.waveform, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -420,20 +385,16 @@ 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: my_song.mp3");
|
||||
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_song.mp3");
|
||||
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::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");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_song.mp3");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -450,18 +411,14 @@ 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: my_song.mp3");
|
||||
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_song.mp3");
|
||||
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::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");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_song.mp3");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use assert_matches::assert_matches;
|
||||
use js_int::uint;
|
||||
use js_int::{int, uint};
|
||||
use ruma_common::{
|
||||
event_id,
|
||||
events::{MessageLikeEvent, StateEvent, SyncMessageLikeEvent, SyncStateEvent},
|
||||
@ -13,7 +13,7 @@ use ruma_common::{
|
||||
events::{
|
||||
room::{
|
||||
aliases::RoomAliasesEventContent,
|
||||
message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
|
||||
message::{MessageType, RoomMessageEventContent},
|
||||
power_levels::RoomPowerLevelsEventContent,
|
||||
},
|
||||
AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyRoomEvent, AnyStateEvent,
|
||||
@ -127,7 +127,7 @@ fn power_event_sync_deserialization() {
|
||||
}
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
let ban = assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(json_data),
|
||||
Ok(AnySyncRoomEvent::State(
|
||||
AnySyncStateEvent::RoomPowerLevels(SyncStateEvent::Original(
|
||||
@ -138,46 +138,44 @@ fn power_event_sync_deserialization() {
|
||||
..
|
||||
},
|
||||
)),
|
||||
))
|
||||
if ban == js_int::Int::new(50).unwrap()
|
||||
)) => ban
|
||||
);
|
||||
assert_eq!(ban, int!(50));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn message_event_sync_deserialization() {
|
||||
let json_data = message_event_sync();
|
||||
|
||||
assert_matches!(
|
||||
let text_content = assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(json_data),
|
||||
Ok(AnySyncRoomEvent::MessageLike(
|
||||
AnySyncMessageLikeEvent::RoomMessage(SyncMessageLikeEvent::Original(
|
||||
OriginalSyncMessageLikeEvent {
|
||||
content: RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: Some(formatted),
|
||||
..
|
||||
}),
|
||||
msgtype: MessageType::Text(text_content),
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
))
|
||||
))
|
||||
if body == "baba" && formatted.body == "<strong>baba</strong>"
|
||||
)) => text_content
|
||||
);
|
||||
assert_eq!(text_content.body, "baba");
|
||||
let formatted = text_content.formatted.unwrap();
|
||||
assert_eq!(formatted.body, "<strong>baba</strong>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aliases_event_sync_deserialization() {
|
||||
let json_data = aliases_event_sync();
|
||||
|
||||
let ev = match from_json_value::<AnySyncRoomEvent>(json_data) {
|
||||
let ev = assert_matches!(
|
||||
from_json_value::<AnySyncRoomEvent>(json_data),
|
||||
Ok(AnySyncRoomEvent::State(AnySyncStateEvent::RoomAliases(SyncStateEvent::Original(
|
||||
ev,
|
||||
)))) => ev,
|
||||
res => panic!("unexpected result: {:?}", res),
|
||||
};
|
||||
)))) => ev
|
||||
);
|
||||
|
||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
}
|
||||
@ -186,25 +184,23 @@ fn aliases_event_sync_deserialization() {
|
||||
fn message_room_event_deserialization() {
|
||||
let json_data = message_event();
|
||||
|
||||
assert_matches!(
|
||||
let text_content = assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(json_data),
|
||||
Ok(AnyRoomEvent::MessageLike(
|
||||
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(
|
||||
OriginalMessageLikeEvent {
|
||||
content: RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: Some(formatted),
|
||||
..
|
||||
}),
|
||||
msgtype: MessageType::Text(text_content),
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
))
|
||||
))
|
||||
if body == "baba" && formatted.body == "<strong>baba</strong>"
|
||||
)) => text_content
|
||||
);
|
||||
assert_eq!(text_content.body, "baba");
|
||||
let formatted = text_content.formatted.unwrap();
|
||||
assert_eq!(formatted.body, "<strong>baba</strong>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -235,7 +231,7 @@ fn message_event_serialization() {
|
||||
fn alias_room_event_deserialization() {
|
||||
let json_data = aliases_event();
|
||||
|
||||
assert_matches!(
|
||||
let aliases = assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(json_data),
|
||||
Ok(AnyRoomEvent::State(
|
||||
AnyStateEvent::RoomAliases(StateEvent::Original(OriginalStateEvent {
|
||||
@ -245,39 +241,37 @@ fn alias_room_event_deserialization() {
|
||||
},
|
||||
..
|
||||
}))
|
||||
))
|
||||
if aliases == vec![room_alias_id!("#somewhere:localhost")]
|
||||
)) => aliases
|
||||
);
|
||||
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn message_event_deserialization() {
|
||||
let json_data = message_event();
|
||||
|
||||
assert_matches!(
|
||||
let text_content = assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(json_data),
|
||||
Ok(AnyRoomEvent::MessageLike(
|
||||
AnyMessageLikeEvent::RoomMessage(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: RoomMessageEventContent {
|
||||
msgtype: MessageType::Text(TextMessageEventContent {
|
||||
body,
|
||||
formatted: Some(formatted),
|
||||
..
|
||||
}),
|
||||
msgtype: MessageType::Text(text_content),
|
||||
..
|
||||
},
|
||||
..
|
||||
}))
|
||||
))
|
||||
if body == "baba" && formatted.body == "<strong>baba</strong>"
|
||||
)) => text_content
|
||||
);
|
||||
assert_eq!(text_content.body, "baba");
|
||||
let formatted = text_content.formatted.unwrap();
|
||||
assert_eq!(formatted.body, "<strong>baba</strong>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_event_deserialization() {
|
||||
let json_data = aliases_event();
|
||||
|
||||
assert_matches!(
|
||||
let aliases = assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(json_data),
|
||||
Ok(AnyRoomEvent::State(
|
||||
AnyStateEvent::RoomAliases(StateEvent::Original(OriginalStateEvent {
|
||||
@ -287,30 +281,27 @@ fn alias_event_deserialization() {
|
||||
},
|
||||
..
|
||||
}))
|
||||
))
|
||||
if aliases == vec![room_alias_id!("#somewhere:localhost")]
|
||||
)) => aliases
|
||||
);
|
||||
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_event_field_access() {
|
||||
let json_data = aliases_event();
|
||||
|
||||
assert_matches!(
|
||||
let state_event = assert_matches!(
|
||||
from_json_value::<AnyRoomEvent>(json_data.clone()),
|
||||
Ok(AnyRoomEvent::State(state_event))
|
||||
if state_event.state_key() == "room.com"
|
||||
&& state_event.room_id() == room_id!("!room:room.com")
|
||||
&& state_event.event_id() == event_id!("$152037280074GZeOm:localhost")
|
||||
&& state_event.sender() == user_id!("@example:localhost")
|
||||
Ok(AnyRoomEvent::State(state_event)) => state_event
|
||||
);
|
||||
assert_eq!(state_event.state_key(), "room.com");
|
||||
assert_eq!(state_event.room_id(), "!room:room.com");
|
||||
assert_eq!(state_event.event_id(), "$152037280074GZeOm:localhost");
|
||||
assert_eq!(state_event.sender(), "@example:localhost");
|
||||
|
||||
let deser = from_json_value::<AnyStateEvent>(json_data).unwrap();
|
||||
if let AnyStateEvent::RoomAliases(StateEvent::Original(ev)) = &deser {
|
||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")])
|
||||
} else {
|
||||
panic!("the `Any*Event` enum's accessor methods may have been altered")
|
||||
}
|
||||
let ev = assert_matches!(&deser, AnyStateEvent::RoomAliases(StateEvent::Original(ev)) => ev);
|
||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")]);
|
||||
assert_eq!(deser.event_type().to_string(), "m.room.aliases");
|
||||
}
|
||||
|
||||
@ -327,11 +318,11 @@ fn ephemeral_event_deserialization() {
|
||||
"type": "m.typing"
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
let ephem = assert_matches!(
|
||||
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
||||
Ok(ephem @ AnyEphemeralRoomEvent::Typing(_))
|
||||
if ephem.room_id() == room_id!("!jEsUZKDJdhlrceRyVU:example.org")
|
||||
Ok(ephem @ AnyEphemeralRoomEvent::Typing(_)) => ephem
|
||||
);
|
||||
assert_eq!(ephem.room_id(), "!jEsUZKDJdhlrceRyVU:example.org");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -39,14 +39,12 @@ fn deserialize_ephemeral_typing() {
|
||||
"type": "m.typing"
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyEphemeralRoomEvent>(json_data).unwrap(),
|
||||
AnyEphemeralRoomEvent::Typing(EphemeralRoomEvent {
|
||||
content: TypingEventContent { user_ids, .. },
|
||||
room_id,
|
||||
}) if user_ids[0] == user_id!("@carl:example.com")
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
let typing_event = assert_matches!(
|
||||
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
||||
Ok(AnyEphemeralRoomEvent::Typing(typing_event)) => typing_event
|
||||
);
|
||||
assert_eq!(typing_event.content.user_ids[0], "@carl:example.com");
|
||||
assert_eq!(typing_event.room_id, "!roomid:room.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -98,18 +96,16 @@ fn deserialize_ephemeral_receipt() {
|
||||
"type": "m.receipt"
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyEphemeralRoomEvent>(json_data).unwrap(),
|
||||
AnyEphemeralRoomEvent::Receipt(EphemeralRoomEvent {
|
||||
content: ReceiptEventContent(receipts),
|
||||
room_id,
|
||||
}) if !receipts.is_empty() && receipts.contains_key(event_id)
|
||||
&& room_id == room_id!("!roomid:room.com")
|
||||
&& receipts
|
||||
.get(event_id)
|
||||
.map(|r| r.get(&ReceiptType::Read).unwrap().get(user_id).unwrap())
|
||||
.map(|r| r.ts)
|
||||
.unwrap()
|
||||
== Some(MilliSecondsSinceUnixEpoch(uint!(1)))
|
||||
let receipt_event = assert_matches!(
|
||||
from_json_value::<AnyEphemeralRoomEvent>(json_data),
|
||||
Ok(AnyEphemeralRoomEvent::Receipt(receipt_event)) => receipt_event
|
||||
);
|
||||
let receipts = receipt_event.content.0;
|
||||
assert!(!receipts.is_empty());
|
||||
assert!(receipts.contains_key(event_id));
|
||||
assert_eq!(receipt_event.room_id, "!roomid:room.com");
|
||||
let event_receipts = assert_matches!(receipts.get(event_id), Some(r) => r);
|
||||
let type_receipts = assert_matches!(event_receipts.get(&ReceiptType::Read), Some(r) => r);
|
||||
let user_receipt = assert_matches!(type_receipts.get(user_id), Some(r) => r);
|
||||
assert_eq!(user_receipt.ts, Some(MilliSecondsSinceUnixEpoch(uint!(1))));
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use js_int::uint;
|
||||
use ruma_common::{
|
||||
event_id,
|
||||
events::{
|
||||
file::{EncryptedContentInit, FileContent, FileContentInfo, FileEventContent},
|
||||
file::{EncryptedContentInit, FileContentInfo, FileEventContent},
|
||||
message::MessageContent,
|
||||
room::{
|
||||
message::{
|
||||
@ -160,14 +160,10 @@ fn plain_content_deserialization() {
|
||||
}
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<FileEventContent>(json_data)
|
||||
.unwrap(),
|
||||
FileEventContent { message, file, .. }
|
||||
if message.find_plain() == Some("Upload: my_file.txt")
|
||||
&& message.find_html().is_none()
|
||||
&& file.url.as_str() == "mxc://notareal.hs/abcdef"
|
||||
);
|
||||
let content = from_json_value::<FileEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_file.txt"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -191,15 +187,11 @@ fn encrypted_content_deserialization() {
|
||||
}
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<FileEventContent>(json_data)
|
||||
.unwrap(),
|
||||
FileEventContent { message, file, .. }
|
||||
if message.find_plain() == Some("Upload: my_file.txt")
|
||||
&& message.find_html().is_none()
|
||||
&& file.url.as_str() == "mxc://notareal.hs/abcdef"
|
||||
&& file.encryption_info.is_some()
|
||||
);
|
||||
let content = from_json_value::<FileEventContent>(json_data).unwrap();
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_file.txt"));
|
||||
assert_eq!(content.message.find_html(), None);
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
assert!(content.file.encryption_info.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -224,35 +216,23 @@ fn message_event_deserialization() {
|
||||
"type": "m.file",
|
||||
});
|
||||
|
||||
assert_matches!(
|
||||
from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
|
||||
AnyMessageLikeEvent::File(MessageLikeEvent::Original(OriginalMessageLikeEvent {
|
||||
content: FileEventContent {
|
||||
message,
|
||||
file: FileContent {
|
||||
url,
|
||||
info: Some(info),
|
||||
..
|
||||
},
|
||||
..
|
||||
},
|
||||
event_id,
|
||||
origin_server_ts,
|
||||
room_id,
|
||||
sender,
|
||||
unsigned
|
||||
})) if event_id == event_id!("$event:notareal.hs")
|
||||
&& message.find_plain() == Some("Upload: my_file.txt")
|
||||
&& message.find_html() == Some("Upload: <strong>my_file.txt</strong>")
|
||||
&& url.as_str() == "mxc://notareal.hs/abcdef"
|
||||
&& info.name.as_deref() == Some("my_file.txt")
|
||||
&& info.mimetype.as_deref() == Some("text/plain")
|
||||
&& info.size == Some(uint!(774))
|
||||
&& 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::File(MessageLikeEvent::Original(message_event))) => message_event
|
||||
);
|
||||
assert_eq!(message_event.event_id, "$event:notareal.hs");
|
||||
let content = message_event.content;
|
||||
assert_eq!(content.message.find_plain(), Some("Upload: my_file.txt"));
|
||||
assert_eq!(content.message.find_html(), Some("Upload: <strong>my_file.txt</strong>"));
|
||||
assert_eq!(content.file.url, "mxc://notareal.hs/abcdef");
|
||||
let info = content.file.info.unwrap();
|
||||
assert_eq!(info.name.as_deref(), Some("my_file.txt"));
|
||||
assert_eq!(info.mimetype.as_deref(), Some("text/plain"));
|
||||
assert_eq!(info.size, Some(uint!(774)));
|
||||
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]
|
||||
@ -357,20 +337,16 @@ fn room_message_plain_content_stable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::File(_));
|
||||
if let MessageType::File(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_file.txt");
|
||||
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_file.txt");
|
||||
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::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");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_file.txt");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -386,20 +362,16 @@ fn room_message_plain_content_unstable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::File(_));
|
||||
if let MessageType::File(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_file.txt");
|
||||
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_file.txt");
|
||||
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::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");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_file.txt");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(!file.is_encrypted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -441,20 +413,16 @@ fn room_message_encrypted_content_stable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::File(_));
|
||||
if let MessageType::File(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_file.txt");
|
||||
assert_matches!(content.source, MediaSource::Encrypted(_));
|
||||
if let MediaSource::Encrypted(encrypted_file) = content.source {
|
||||
assert_eq!(encrypted_file.url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_file.txt");
|
||||
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::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");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_file.txt");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(file.is_encrypted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -496,18 +464,14 @@ fn room_message_encrypted_content_unstable_deserialization() {
|
||||
});
|
||||
|
||||
let event_content = from_json_value::<RoomMessageEventContent>(json_data).unwrap();
|
||||
assert_matches!(event_content.msgtype, MessageType::File(_));
|
||||
if let MessageType::File(content) = event_content.msgtype {
|
||||
assert_eq!(content.body, "Upload: my_file.txt");
|
||||
assert_matches!(content.source, MediaSource::Encrypted(_));
|
||||
if let MediaSource::Encrypted(encrypted_file) = content.source {
|
||||
assert_eq!(encrypted_file.url, "mxc://notareal.hs/file");
|
||||
}
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_file.txt");
|
||||
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::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");
|
||||
let message = content.message.unwrap();
|
||||
assert_eq!(message.len(), 1);
|
||||
assert_eq!(message[0].body, "Upload: my_file.txt");
|
||||
let file = content.file.unwrap();
|
||||
assert_eq!(file.url, "mxc://notareal.hs/file");
|
||||
assert!(file.is_encrypted());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user