mangadex_api/v5/user/follows/list/
get.rs1use derive_builder::Builder;
44use serde::Serialize;
45
46use crate::HttpClientRef;
47use mangadex_api_schema::v5::CustomListListResponse;
48
49#[cfg_attr(
50 feature = "deserializable-endpoint",
51 derive(serde::Deserialize, getset::Getters, getset::Setters)
52)]
53#[derive(Debug, Serialize, Clone, Builder, Default)]
54#[serde(rename_all = "camelCase")]
55#[builder(
56 setter(into, strip_option),
57 default,
58 build_fn(error = "mangadex_api_types::error::BuilderError")
59)]
60#[cfg_attr(
61 feature = "custom_list_v2",
62 deprecated(
63 since = "3.0.0-rc.1",
64 note = "After the introduction of the Subscription system, this endpoint will be removed in v3"
65 )
66)]
67pub struct GetFollowedCustomLists {
68 #[doc(hidden)]
70 #[serde(skip)]
71 #[builder(pattern = "immutable")]
72 #[cfg_attr(feature = "deserializable-endpoint", getset(set = "pub", get = "pub"))]
73 pub http_client: HttpClientRef,
74
75 #[serde(skip_serializing_if = "Option::is_none")]
79 pub limit: Option<u32>,
80 #[serde(skip_serializing_if = "Option::is_none")]
84 pub offset: Option<u32>,
85}
86
87endpoint! {
88 GET "/user/follows/list",
89 #[query auth] GetFollowedCustomLists,
90 #[flatten_result] CustomListListResponse,
91 GetFollowedCustomListsBuilder
92}
93
94#[cfg(test)]
95mod tests {
96 use fake::faker::name::en::Name;
97 use fake::Fake;
98 use serde_json::json;
99 use url::Url;
100 use uuid::Uuid;
101 use wiremock::matchers::{header, method, path};
102 use wiremock::{Mock, MockServer, ResponseTemplate};
103
104 use crate::v5::AuthTokens;
105 use crate::{HttpClient, MangaDexClient};
106
107 #[tokio::test]
108 async fn get_followed_custom_lists_fires_a_request_to_base_url() -> anyhow::Result<()> {
109 let mock_server = MockServer::start().await;
110 let http_client = HttpClient::builder()
111 .base_url(Url::parse(&mock_server.uri())?)
112 .auth_tokens(AuthTokens {
113 session: "sessiontoken".to_string(),
114 refresh: "refreshtoken".to_string(),
115 })
116 .build()?;
117 let mangadex_client = MangaDexClient::new_with_http_client(http_client);
118
119 let list_id = Uuid::new_v4();
120 let list_name: String = Name().fake();
121 let response_body = json!({
122 "result": "ok",
123 "response": "collection",
124 "data": [
125 {
126 "id": list_id,
127 "type": "custom_list",
128 "attributes": {
129 "name": list_name,
130 "visibility": "private",
131 "version": 1
132 },
133 "relationships": []
134 }
135 ],
136 "limit": 1,
137 "offset": 0,
138 "total": 1
139 });
140
141 Mock::given(method("GET"))
142 .and(path(r"/user/follows/list"))
143 .and(header("Authorization", "Bearer sessiontoken"))
144 .respond_with(ResponseTemplate::new(200).set_body_json(response_body))
145 .expect(1)
146 .mount(&mock_server)
147 .await;
148
149 let _ = mangadex_client
150 .user()
151 .follows()
152 .list()
153 .get()
154 .limit(1_u32)
155 .send()
156 .await?;
157
158 Ok(())
159 }
160}