mangadex_api/v5/manga/id/follow/
post.rs1use derive_builder::Builder;
45use serde::Serialize;
46use uuid::Uuid;
47
48use crate::HttpClientRef;
49use mangadex_api_schema::NoData;
50use mangadex_api_types::error::Result;
51
52#[cfg_attr(
53 feature = "deserializable-endpoint",
54 derive(serde::Deserialize, getset::Getters, getset::Setters)
55)]
56#[derive(Debug, Serialize, Clone, Builder)]
57#[serde(rename_all = "camelCase")]
58#[builder(
59 setter(into, strip_option),
60 build_fn(error = "mangadex_api_types::error::BuilderError")
61)]
62#[cfg_attr(
63 feature = "custom_list_v2",
64 deprecated(
65 since = "3.0.0-rc.1",
66 note = "After the introduction of the Subscription system, this endpoint will be removed in v3"
67 )
68)]
69pub struct FollowManga {
70 #[doc(hidden)]
72 #[serde(skip)]
73 #[builder(pattern = "immutable")]
74 #[cfg_attr(feature = "deserializable-endpoint", getset(set = "pub", get = "pub"))]
75 pub http_client: HttpClientRef,
76
77 #[serde(skip_serializing)]
78 pub manga_id: Uuid,
79}
80
81endpoint! {
82 POST ("/manga/{}/follow", manga_id),
83 #[no_data auth] FollowManga,
84 #[discard_result] Result<NoData>,
85 FollowMangaBuilder
86}
87
88#[cfg(test)]
89mod tests {
90 use serde_json::json;
91 use url::Url;
92 use uuid::Uuid;
93 use wiremock::matchers::{header, method, path_regex};
94 use wiremock::{Mock, MockServer, ResponseTemplate};
95
96 use crate::v5::AuthTokens;
97 use crate::{HttpClient, MangaDexClient};
98
99 #[tokio::test]
100 async fn follow_manga_fires_a_request_to_base_url() -> anyhow::Result<()> {
101 let mock_server = MockServer::start().await;
102 let http_client = HttpClient::builder()
103 .base_url(Url::parse(&mock_server.uri())?)
104 .auth_tokens(AuthTokens {
105 session: "sessiontoken".to_string(),
106 refresh: "refreshtoken".to_string(),
107 })
108 .build()?;
109 let mangadex_client = MangaDexClient::new_with_http_client(http_client);
110
111 let manga_id = Uuid::new_v4();
112 let response_body = json!({
113 "result": "ok",
114 });
115
116 Mock::given(method("POST"))
117 .and(path_regex(r"/manga/[0-9a-fA-F-]+/follow"))
118 .and(header("Authorization", "Bearer sessiontoken"))
119 .respond_with(ResponseTemplate::new(200).set_body_json(response_body))
120 .expect(1)
121 .mount(&mock_server)
122 .await;
123
124 mangadex_client
125 .manga()
126 .id(manga_id)
127 .follow()
128 .post()
129 .send()
130 .await?;
131
132 Ok(())
133 }
134}