From dd1516f5ed89e88b958b13f76704ab076994ef42 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 15 Aug 2021 23:38:56 +0200 Subject: [PATCH] client-api: Add a test for get_filter response (de)serialization --- .../src/r0/filter/get_filter.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/ruma-client-api/src/r0/filter/get_filter.rs b/crates/ruma-client-api/src/r0/filter/get_filter.rs index e0e3314b..c09456d1 100644 --- a/crates/ruma-client-api/src/r0/filter/get_filter.rs +++ b/crates/ruma-client-api/src/r0/filter/get_filter.rs @@ -47,3 +47,35 @@ impl Response { Self { filter } } } + +#[cfg(all(test, any(feature = "client", feature = "server")))] +mod tests { + use matches::assert_matches; + + use crate::r0::filter::IncomingFilterDefinition; + + #[cfg(feature = "client")] + #[test] + fn deserialize_response() { + use ruma_api::IncomingResponse; + + assert_matches!( + super::Response::try_from_http_response( + http::Response::builder().body(b"{}" as &[u8]).unwrap(), + ), + Ok(Incoming) + ); + } + + #[cfg(feature = "server")] + #[test] + fn serialize_response() { + use ruma_api::OutgoingResponse; + + assert_matches!( + super::Response::new(IncomingFilterDefinition::default()) + .try_into_http_response::>(), + Ok(res) if res.body() == b"{}" + ); + } +}