1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::{
methods::Method,
request::{Form, Request},
types::{ChatId, InputFile},
};
#[derive(Debug)]
pub struct SetChatPhoto {
form: Form,
}
impl SetChatPhoto {
pub fn new<C, P>(chat_id: C, photo: P) -> Self
where
C: Into<ChatId>,
P: Into<InputFile>,
{
let mut form = Form::new();
form.insert_field("chat_id", chat_id.into());
form.insert_field("photo", photo.into());
SetChatPhoto { form }
}
}
impl Method for SetChatPhoto {
type Response = bool;
fn into_request(self) -> Request {
Request::form("setChatPhoto", self.form)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::request::{RequestBody, RequestMethod};
#[test]
fn set_chat_photo() {
let request = SetChatPhoto::new(1, InputFile::file_id("sticker-id")).into_request();
assert_eq!(request.get_method(), RequestMethod::Post);
assert_eq!(request.build_url("base-url", "token"), "base-url/bottoken/setChatPhoto");
if let RequestBody::Form(form) = request.into_body() {
assert_eq!(form.fields["chat_id"].get_text().unwrap(), "1");
assert!(form.fields["photo"].get_file().is_some());
} else {
panic!("Unexpected request body");
}
}
}