mangadex_api/v5/scanlation_group/id/
get.rs1use derive_builder::Builder;
30use serde::Serialize;
31use uuid::Uuid;
32
33use crate::HttpClientRef;
34use mangadex_api_schema::v5::GroupResponse;
35use mangadex_api_types::ReferenceExpansionResource;
36
37#[cfg_attr(
38 feature = "deserializable-endpoint",
39 derive(serde::Deserialize, getset::Getters, getset::Setters)
40)]
41#[derive(Debug, Serialize, Clone, Builder)]
42#[serde(rename_all = "camelCase")]
43#[builder(
44 setter(into, strip_option),
45 build_fn(error = "mangadex_api_types::error::BuilderError")
46)]
47pub struct GetGroup {
48 #[doc(hidden)]
50 #[serde(skip)]
51 #[builder(pattern = "immutable")]
52 #[cfg_attr(feature = "deserializable-endpoint", getset(set = "pub", get = "pub"))]
53 pub http_client: HttpClientRef,
54
55 #[serde(skip_serializing)]
56 pub group_id: Uuid,
57
58 #[builder(setter(each = "include"), default)]
59 pub includes: Vec<ReferenceExpansionResource>,
60}
61
62endpoint! {
63 GET ("/group/{}", group_id),
64 #[query] GetGroup,
65 #[flatten_result] GroupResponse,
66 GetGroupBuilder
67}
68
69#[cfg(test)]
70mod tests {
71 use serde_json::json;
72 use time::OffsetDateTime;
73 use url::Url;
74 use uuid::Uuid;
75 use wiremock::matchers::{method, path_regex};
76 use wiremock::{Mock, MockServer, ResponseTemplate};
77
78 use crate::{HttpClient, MangaDexClient};
79 use mangadex_api_types::MangaDexDateTime;
80
81 #[tokio::test]
82 async fn get_group_fires_a_request_to_base_url() -> anyhow::Result<()> {
83 let mock_server = MockServer::start().await;
84 let http_client = HttpClient::builder()
85 .base_url(Url::parse(&mock_server.uri())?)
86 .build()?;
87 let mangadex_client = MangaDexClient::new_with_http_client(http_client);
88
89 let group_id = Uuid::new_v4();
90
91 let datetime = MangaDexDateTime::new(&OffsetDateTime::now_utc());
92
93 let response_body = json!({
94 "result": "ok",
95 "response": "entity",
96 "data": {
97 "id": group_id,
98 "type": "scanlation_group",
99 "attributes": {
100 "name": "Scanlation Group",
101 "altNames": [
102 {
103 "en": "Alternative Name"
104 }
105 ],
106 "website": "https://example.org",
107 "ircServer": null,
108 "ircChannel": null,
109 "discord": null,
110 "contactEmail": null,
111 "description": null,
112 "twitter": null,
113 "focusedLanguages": ["en"],
114 "locked": false,
115 "official": false,
116 "verified": false,
117 "inactive": false,
118 "publishDelay": "P6WT5M",
119 "version": 1,
120 "createdAt": datetime.to_string(),
121 "updatedAt": datetime.to_string(),
122 },
123 "relationships": []
124 }
125 });
126
127 Mock::given(method("GET"))
128 .and(path_regex(r"/group/[0-9a-fA-F-]+"))
129 .respond_with(ResponseTemplate::new(200).set_body_json(response_body))
130 .expect(1)
131 .mount(&mock_server)
132 .await;
133
134 let _ = mangadex_client
135 .scanlation_group()
136 .id(group_id)
137 .get()
138 .send()
139 .await?;
140
141 Ok(())
142 }
143}