betfair_xml_parser/
simple_type.rs1use serde::{Deserialize, Serialize};
4
5use crate::common::ValidValues;
6
7#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
9#[serde(rename_all = "camelCase")]
10pub struct SimpleType {
11 pub name: String,
13 pub r#type: String,
15 pub valid_values: Option<ValidValues>,
17}
18
19#[cfg(test)]
20#[expect(clippy::unwrap_used)]
21#[expect(clippy::indexing_slicing)]
22mod tests {
23
24 use serde_xml_rs::from_str;
25
26 use super::*;
27 use crate::common::{Description, Value};
28
29 #[rstest::rstest]
30 fn test_simple_raw_type() {
31 let xml = r#"
32 <simpleType name="MarketType" type="string"/>
33 "#;
34
35 let simple_type: SimpleType = from_str(xml).unwrap();
36 assert_eq!(simple_type.name, "MarketType");
37 assert_eq!(simple_type.r#type, "string");
38 assert_eq!(simple_type.valid_values, None);
39 }
40 #[rstest::rstest]
41 fn test_simple_raw_type_2() {
42 let xml = r#"
43 <simpleType name="Handicap" type="double"/>
44 "#;
45
46 let simple_type: SimpleType = from_str(xml).unwrap();
47 assert_eq!(simple_type.name, "Handicap");
48 assert_eq!(simple_type.r#type, "double");
49 assert_eq!(simple_type.valid_values, None);
50 }
51
52 #[rstest::rstest]
53 fn test_simple_enum_type() {
54 let xml = r#"
55 <simpleType name="MarketProjection" type="string">
56 <validValues>
57 <value name="COMPETITION">
58 <description>If not selected then the competition will not be returned with marketCatalogue
59 </description>
60 </value>
61 <value name="EVENT">
62 <description>If not selected then the event will not be returned with marketCatalogue</description>
63 </value>
64 <value name="EVENT_TYPE">
65 <description>If not selected then the eventType will not be returned with marketCatalogue</description>
66 </value>
67 </validValues>
68 </simpleType>
69 "#;
70
71 let simple_type: SimpleType = from_str(xml).unwrap();
72 assert_eq!(simple_type.name, "MarketProjection");
73 assert_eq!(simple_type.r#type, "string");
74 assert_eq!(simple_type.valid_values.as_ref().unwrap().items.len(), 3);
75 assert_eq!(simple_type.valid_values.unwrap().items, vec![
76 Value {
77 id: None,
78 name: "COMPETITION".to_owned(),
79 description: Description {value: Some("If not selected then the competition will not be returned with marketCatalogue".to_owned() )},
80 },
81 Value {
82 id: None,
83 name: "EVENT".to_owned(),
84 description: Description {value: Some("If not selected then the event will not be returned with marketCatalogue".to_owned() )},
85 },
86 Value {
87 id: None,
88 name: "EVENT_TYPE".to_owned(),
89 description: Description {value: Some("If not selected then the eventType will not be returned with marketCatalogue".to_owned() )},
90 },
91 ]);
92 }
93
94 #[rstest::rstest]
95 fn test_simple_enum_type_2() {
96 let xml = r#"
97 <simpleType name="InstructionReportStatus" type="string">
98 <validValues>
99 <value name="SUCCESS">
100 <description/>
101 </value>
102 <value name="FAILURE">
103 <description/>
104 </value>
105 <value name="TIMEOUT">
106 <description/>
107 </value>
108 </validValues>
109 </simpleType>
110 "#;
111
112 let simple_type: SimpleType = from_str(xml).unwrap();
113 assert_eq!(simple_type.name, "InstructionReportStatus");
114 assert_eq!(simple_type.r#type, "string");
115 assert_eq!(simple_type.valid_values.as_ref().unwrap().items.len(), 3);
116 assert_eq!(
117 simple_type.valid_values.unwrap().items,
118 vec![
119 Value {
120 id: None,
121 name: "SUCCESS".to_owned(),
122 description: Description { value: None },
123 },
124 Value {
125 id: None,
126 name: "FAILURE".to_owned(),
127 description: Description { value: None },
128 },
129 Value {
130 id: None,
131 name: "TIMEOUT".to_owned(),
132 description: Description { value: None },
133 },
134 ]
135 );
136 }
137}