Skip to main content

zulip_api/message/delete_message/
response.rs

1use crate::response::BaseResponse;
2
3/// Represents the response to a `Delete Message` API request.
4pub type Response = BaseResponse;
5
6#[cfg(test)]
7mod tests {
8    use super::*;
9    use crate::response::{ApiResult, ErrorCode, Response as _};
10
11    #[test]
12    fn test_success_response() {
13        let msg = "test response";
14        let msg_json = serde_json::to_string(&msg).unwrap();
15
16        let result = ApiResult::Success;
17        let result_json = serde_json::to_string(&result).unwrap();
18
19        let response = Response::new().with_msg(msg).with_result(result);
20
21        let response_json = format!(r#"{{"msg":{msg_json},"result":{result_json}}}"#);
22
23        assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
24        assert_eq!(
25            serde_json::from_str::<Response>(&response_json).unwrap(),
26            response
27        );
28
29        assert_eq!(response.msg(), msg);
30        assert_eq!(response.result(), result);
31        assert_eq!(response.code(), None);
32    }
33
34    #[test]
35    fn test_error_response() {
36        let msg = "test response";
37        let msg_json = serde_json::to_string(&msg).unwrap();
38
39        let result = ApiResult::Error;
40        let result_json = serde_json::to_string(&result).unwrap();
41
42        let code = ErrorCode::BadRequest;
43        let code_json = serde_json::to_string(&code).unwrap();
44
45        let response = Response::new()
46            .with_msg(msg)
47            .with_result(result)
48            .with_code(code);
49
50        let response_json =
51            format!(r#"{{"msg":{msg_json},"result":{result_json},"code":{code_json}}}"#);
52
53        assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
54        assert_eq!(
55            serde_json::from_str::<Response>(&response_json).unwrap(),
56            response
57        );
58
59        assert_eq!(response.msg(), msg);
60        assert_eq!(response.result(), result);
61        assert_eq!(response.code(), Some(code));
62    }
63}