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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! DTO traits and helpers.
use Serialize;
use cratePaperlessId;
/// Marker trait for update DTOs.
// #[cfg(test)]
// mod tests {
// use paperless_api_macros::{CreateDto as CreateDtoDerive, UpdateDto as UpdateDtoDerive};
// use serde::{Deserialize, Serialize};
// use super::{CreateDto, UpdateDto};
// #[derive(Debug, Default, Clone, Deserialize, Serialize, CreateDtoDerive, UpdateDtoDerive)]
// struct TestItem {
// #[dto(skip)]
// pub id: u32,
// pub name: String,
// #[serde(rename = "match")]
// pub match_pattern: String,
// pub optional: Option<bool>,
// #[dto(skip)]
// #[serde(default)]
// pub document_count: u32,
// }
// #[test]
// fn create_dto_has_correct_fields() {
// let dto = CreateTestItem {
// name: "hello".to_string(),
// match_pattern: "pattern".to_string(),
// optional: None,
// };
// let json = serde_json::to_string(&dto).unwrap();
// assert!(json.contains("\"name\""));
// assert!(json.contains("\"match\""));
// assert!(!json.contains("\"id\""));
// assert!(!json.contains("\"document_count\""));
// }
// #[test]
// fn update_dto_wraps_fields_in_option() {
// let dto = UpdateTestItem {
// name: Some("hello".to_string()),
// match_pattern: None,
// optional: Some(Some(true)),
// };
// let json = serde_json::to_string(&dto).unwrap();
// assert!(json.contains("\"name\":\"hello\""));
// assert!(!json.contains("\"match\""));
// assert!(json.contains("\"optional\":true"));
// assert!(!json.contains("\"id\""));
// }
// #[test]
// fn create_dto_implements_marker_trait() {
// fn assert_create<T: CreateDto>() {}
// assert_create::<CreateTestItem>();
// }
// #[test]
// fn update_dto_implements_marker_trait() {
// fn assert_update<T: UpdateDto>() {}
// assert_update::<UpdateTestItem>();
// }
// #[test]
// fn create_dto_default_works() {
// let dto = CreateTestItem::default();
// assert_eq!(dto.name, "");
// assert_eq!(dto.match_pattern, "");
// assert_eq!(dto.optional, None);
// }
// #[test]
// fn update_dto_default_is_all_none() {
// let dto = UpdateTestItem::default();
// assert_eq!(dto.name, None);
// assert_eq!(dto.match_pattern, None);
// assert_eq!(dto.optional, None);
// }
// }