zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use crate::response::BaseResponse;

/// Represents the response to a `Delete Message` API request.
pub type Response = BaseResponse;

#[cfg(test)]
mod tests {
    use super::*;
    use crate::response::{ApiResult, ErrorCode, Response as _};

    #[test]
    fn test_success_response() {
        let msg = "test response";
        let msg_json = serde_json::to_string(&msg).unwrap();

        let result = ApiResult::Success;
        let result_json = serde_json::to_string(&result).unwrap();

        let response = Response::new().with_msg(msg).with_result(result);

        let response_json = format!(r#"{{"msg":{msg_json},"result":{result_json}}}"#);

        assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
        assert_eq!(
            serde_json::from_str::<Response>(&response_json).unwrap(),
            response
        );

        assert_eq!(response.msg(), msg);
        assert_eq!(response.result(), result);
        assert_eq!(response.code(), None);
    }

    #[test]
    fn test_error_response() {
        let msg = "test response";
        let msg_json = serde_json::to_string(&msg).unwrap();

        let result = ApiResult::Error;
        let result_json = serde_json::to_string(&result).unwrap();

        let code = ErrorCode::BadRequest;
        let code_json = serde_json::to_string(&code).unwrap();

        let response = Response::new()
            .with_msg(msg)
            .with_result(result)
            .with_code(code);

        let response_json =
            format!(r#"{{"msg":{msg_json},"result":{result_json},"code":{code_json}}}"#);

        assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
        assert_eq!(
            serde_json::from_str::<Response>(&response_json).unwrap(),
            response
        );

        assert_eq!(response.msg(), msg);
        assert_eq!(response.result(), result);
        assert_eq!(response.code(), Some(code));
    }
}