Skip to main content

zulip_api/message/upload_file/
request.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents a upload file request to a Zulip server.
6#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
7pub struct Request {
8    file_path: String,
9}
10
11impl Request {
12    /// Creates a new [Request].
13    pub const fn new() -> Self {
14        Self {
15            file_path: String::new(),
16        }
17    }
18}
19
20field_access! {
21    Request {
22        file_path: cow { str },
23    }
24}
25
26impl_default!(Request);
27impl_display!(Request);
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn test_upload_file() {
35        let file_path = "/path/to/file.txt";
36        let file_path_json = serde_json::to_string(&file_path).unwrap();
37
38        let req = Request::new().with_file_path(file_path);
39
40        let req_json = format!(r#"{{"file_path":{file_path_json}}}"#);
41
42        assert_eq!(serde_json::to_string(&req).unwrap(), req_json);
43        assert_eq!(serde_json::from_str::<Request>(&req_json).unwrap(), req);
44        assert_eq!(req.file_path(), file_path);
45    }
46}