mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-05 22:47:02 -04:00
feat(tests): Add a macro to assert that a TimelineEventKind was encrypted
This commit is contained in:
@@ -222,6 +222,50 @@ macro_rules! assert_next_eq_with_timeout {
|
||||
};
|
||||
}
|
||||
|
||||
/// Given a [`TimelineEvent`] assert that the event was decrypted and that the
|
||||
/// message matches the expected value.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # async {
|
||||
/// # let client: matrix_sdk::Client = unreachable!();
|
||||
/// # let room_id: ruma::OwnedRoomId = unreachable!();
|
||||
/// # let event_id: ruma::OwnedEventId = unreachable!();
|
||||
/// use matrix_sdk::assert_decrypted_message_eq;
|
||||
///
|
||||
/// let room =
|
||||
/// client.get_room(&room_id).expect("Bob should have received the invite");
|
||||
///
|
||||
/// let event = room.event(&event_id, None).await?;
|
||||
///
|
||||
/// assert_decrypted_message_eq!(
|
||||
/// event,
|
||||
/// "It's a secret to everybody!",
|
||||
/// "The decrypted event should match the expected secret message"
|
||||
/// );
|
||||
/// # anyhow::Ok(()) };
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! assert_decrypted_message_eq {
|
||||
($event:expr, $expected:expr, $($msg:tt)*) => {{
|
||||
assert_matches2::assert_let!($crate::deserialized_responses::TimelineEventKind::Decrypted(decrypted_event) = $event.kind);
|
||||
|
||||
let deserialized_event = decrypted_event
|
||||
.event
|
||||
.deserialize()
|
||||
.expect("We should be able to deserialize the decrypted event");
|
||||
|
||||
let content =
|
||||
deserialized_event.original_content().expect("The event should not have been redacted");
|
||||
assert_matches2::assert_let!($crate::ruma::events::AnyMessageLikeEventContent::RoomMessage(content) = content);
|
||||
assert_eq!(content.body(), $expected, $($msg)*);
|
||||
}};
|
||||
($event:expr, $expected:expr) => {{
|
||||
assert_decrypted_message_eq!($event, $expected, "The decrypted content did not match to the expected value");
|
||||
}};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! assert_next_eq_with_timeout_impl {
|
||||
|
||||
Reference in New Issue
Block a user