1use derive_builder::Builder;
4use serde::Serialize;
5
6use crate::schema::legacy::*;
7
8#[derive(Debug, Builder, Serialize, Clone, PartialEq, Eq)]
12#[builder(setter(into))]
13#[serde(rename_all = "camelCase")]
14pub struct LegacyMapping {
15 #[builder(setter(name = "query_type"))]
17 pub r#type: MappingType,
18
19 #[builder(setter(each = "add_id"))]
21 pub ids: Vec<u32>,
22}
23
24impl_endpoint! {
25 POST "/legacy/mapping",
26 #[body] LegacyMapping,
27 Vec<MappingIdResponse>
28}
29
30#[cfg(test)]
31mod tests {
32 use crate::Client;
33
34 use super::*;
35 use httpmock::{Method::POST, MockServer};
36 use pretty_assertions::assert_eq;
37 use serde_json::json;
38 use uuid::Uuid;
39
40 #[tokio::test]
41 async fn legacy_mapping() {
42 let server = MockServer::start_async().await;
43 let mock = server
44 .mock_async(|when, then| {
45 when.method(POST)
46 .path("/legacy/mapping")
47 .header("Content-Type", "application/json")
48 .json_body(json!({
49 "type": "manga",
50 "ids": [1]
51 }));
52 then.header("Content-Type", "application/json")
53 .json_body(json!([
54 {
55 "result": "ok",
56 "data": {
57 "id": "24b6d026-a7cb-498e-8717-26b2831cf318",
58 "type": "mapping_id",
59 "attributes": {
60 "type": "manga",
61 "legacyId": 1,
62 "newId": "c0ee660b-f9f2-45c3-8068-5123ff53f84a",
63 },
64 }
65 }
66 ]));
67 })
68 .await;
69
70 let client = Client::new(&server.base_url()).unwrap();
71 let mappings = LegacyMapping {
72 r#type: MappingType::Manga,
73 ids: vec![1],
74 }
75 .send(&client)
76 .await
77 .expect("Failed to parse");
78
79 mock.assert_async().await;
80 assert_eq!(mappings.len(), 1);
81
82 let mapping = mappings[0].as_ref().unwrap();
83 assert_eq!(mapping.relationships.len(), 0);
84 assert_eq!(
85 mapping.data,
86 MappingId {
87 id: Uuid::parse_str("24b6d026-a7cb-498e-8717-26b2831cf318").unwrap(),
88 r#type: MappingIdType::MappingId,
89 attributes: MappingIdAttributes {
90 r#type: MappingType::Manga,
91 legacy_id: 1,
92 new_id: Uuid::parse_str("c0ee660b-f9f2-45c3-8068-5123ff53f84a").unwrap()
93 }
94 }
95 );
96 }
97}