1pub mod candidate;
2pub mod client;
3pub mod lookup;
4
5
6#[cfg(test)]
7mod tests {
8 use serde_json::from_str;
9 use crate::international_street_api::client::InternationalStreetClient;
10 use crate::international_street_api::lookup::Lookup;
11 use crate::sdk::options::OptionsBuilder;
12 use crate::international_street_api::candidate::*;
13
14
15 #[test]
16 fn client_test() {
17 let client = InternationalStreetClient::new(OptionsBuilder::new(None).build()).unwrap();
18
19 assert_eq!(
20 client.client.url.to_string(),
21 "https://international-street.api.smarty.com/verify".to_string()
22 )
23 }
24
25 #[test]
26 fn lookup_test() {
27 let lookup = Lookup {
28 geocode: false,
29 organization: "John Doe".to_string(),
30 address1: "Rua Padre Antonio D'Angelo 121".to_string(),
31 address2: "Casa Verde".to_string(),
32 locality: "Sao Paulo".to_string(),
33 administrative_area: "SP".to_string(),
34 country: "Brazil".to_string(),
35 postal_code: "02516-050".to_string(),
36 ..Default::default()
37 };
38
39 let expected_results = vec![
40 ("country".to_string(), "Brazil".to_string()),
41 ("geocode".to_string(), "false".to_string()),
42 ("language".to_string(), "native".to_string()),
43 (
44 "address1".to_string(),
45 "Rua Padre Antonio D'Angelo 121".to_string(),
46 ),
47 ("address2".to_string(), "Casa Verde".to_string()),
48 ("organization".to_string(), "John Doe".to_string()),
49 ("locality".to_string(), "Sao Paulo".to_string()),
50 ("administrative_area".to_string(), "SP".to_string()),
51 ("postal_code".to_string(), "02516-050".to_string()),
52 ];
53
54 assert_eq!(lookup.into_param_array(), expected_results);
55 }
56
57 #[test]
58 fn candidate_test(){
59 let response_payload = r#"[{
60 "input_id": "12345678",
61 "organization": "1",
62 "address1": "2", "address2": "3", "address3": "4", "address4": "5",
63 "address5": "6", "address6": "7", "address7": "8", "address8": "9",
64 "address9": "10", "address10": "11", "address11": "12", "address12": "13",
65 "components": {
66 "country_iso_3": "14", "super_administrative_area": "15",
67 "administrative_area": "16", "administrative_area_iso2": "16.1",
68 "administrative_area_short": "16.2", "administrative_area_long": "16.3",
69 "sub_administrative_area": "17", "dependent_locality": "18",
70 "dependent_locality_name": "19", "double_dependent_locality": "20",
71 "locality": "21", "postal_code": "22", "postal_code_short": "23",
72 "postal_code_extra": "24", "premise": "25", "premise_extra": "26",
73 "premise_number": "27", "premise_prefix_number": "27.5", "premise_type": "28",
74 "thoroughfare": "29", "thoroughfare_predirection": "30", "thoroughfare_postdirection": "31",
75 "thoroughfare_name": "32", "thoroughfare_trailing_type": "33", "thoroughfare_type": "34",
76 "dependent_thoroughfare": "35", "dependent_thoroughfare_predirection": "36",
77 "dependent_thoroughfare_postdirection": "37", "dependent_thoroughfare_name": "38",
78 "dependent_thoroughfare_trailing_type": "39", "dependent_thoroughfare_type": "40",
79 "building": "41", "building_leading_type": "42", "building_name": "43",
80 "building_trailing_type": "44", "sub_building_type": "45", "sub_building_number": "46",
81 "sub_building_name": "47", "sub_building": "48", "level_type": "48.1", "level_number": "48.2",
82 "post_box": "49", "post_box_type": "50", "post_box_number": "51"
83 },
84 "metadata": {
85 "latitude": 52.0, "longitude": 53.0,
86 "geocode_precision": "54", "max_geocode_precision": "55",
87 "address_format": "56"
88 },
89 "analysis": {
90 "verification_status": "57", "address_precision": "58",
91 "max_address_precision": "59",
92 "changes": {
93 "organization": "60", "address1": "61", "address2": "62", "address3": "63",
94 "address4": "64", "address5": "65", "address6": "66", "address7": "67",
95 "address8": "68", "address9": "69", "address10": "70", "address11": "71",
96 "address12": "72",
97 "components": {
98 "super_administrative_area": "73", "administrative_area": "74",
99 "administrative_area_short": "74.1", "administrative_area_long": "74.2",
100 "sub_administrative_area": "75", "building": "76",
101 "dependent_locality": "77", "dependent_locality_name": "78",
102 "double_dependent_locality": "79", "country_iso_3": "80", "locality": "81",
103 "postal_code": "82", "postal_code_short": "83", "postal_code_extra": "84",
104 "premise": "85", "premise_extra": "86", "premise_number": "87",
105 "premise_type": "88", "premise_prefix_number": "89", "thoroughfare": "90",
106 "thoroughfare_predirection": "91", "thoroughfare_postdirection": "92",
107 "thoroughfare_name": "93", "thoroughfare_trailing_type": "94", "thoroughfare_type": "95",
108 "dependent_thoroughfare": "96", "dependent_thoroughfare_predirection": "97",
109 "dependent_thoroughfare_postdirection": "98", "dependent_thoroughfare_name": "99",
110 "dependent_thoroughfare_trailing_type": "100", "dependent_thoroughfare_type": "101",
111 "building_leading_type": "102", "building_name": "103", "building_trailing_type": "104",
112 "sub_building_type": "105", "sub_building_number": "106", "sub_building_name": "107",
113 "sub_building": "108", "level_type": "108.1", "level_number": "108.2",
114 "post_box": "109", "post_box_type": "110", "post_box_number": "111",
115 "additional_content": "112", "delivery_installation": "113",
116 "delivery_installation_type": "114", "delivery_installation_qualifier_name": "115",
117 "route": "116", "route_number": "117", "route_type": "118"
118 }
119 }
120 }
121 }]"#;
122
123 let candidates: Vec<Candidate> = from_str(response_payload).expect("Failed to deserialize JSON");
124 let candidate = &candidates[0];
125
126 assert_eq!(candidate.input_id, "12345678");
127 assert_eq!(candidate.root_level.organization, "1");
128 assert_eq!(candidate.root_level.address1, "2");
129 assert_eq!(candidate.root_level.address2, "3");
130 assert_eq!(candidate.root_level.address3, "4");
131 assert_eq!(candidate.root_level.address4, "5");
132 assert_eq!(candidate.root_level.address5, "6");
133 assert_eq!(candidate.root_level.address6, "7");
134 assert_eq!(candidate.root_level.address7, "8");
135 assert_eq!(candidate.root_level.address8, "9");
136 assert_eq!(candidate.root_level.address9, "10");
137 assert_eq!(candidate.root_level.address10, "11");
138 assert_eq!(candidate.root_level.address11, "12");
139 assert_eq!(candidate.root_level.address12, "13");
140 assert_eq!(candidate.components.country_iso_3, "14");
141 assert_eq!(candidate.components.super_administrative_area, "15");
142 assert_eq!(candidate.components.administrative_area, "16");
143 assert_eq!(candidate.components.administrative_area_iso2, "16.1");
144 assert_eq!(candidate.components.administrative_area_short, "16.2");
145 assert_eq!(candidate.components.administrative_area_long, "16.3");
146 assert_eq!(candidate.components.sub_administrative_area, "17");
147 assert_eq!(candidate.components.dependent_locality, "18");
148 assert_eq!(candidate.components.dependent_locality_name, "19");
149 assert_eq!(candidate.components.double_dependent_locality, "20");
150 assert_eq!(candidate.components.locality, "21");
151 assert_eq!(candidate.components.postal_code, "22");
152 assert_eq!(candidate.components.postal_code_short, "23");
153 assert_eq!(candidate.components.postal_code_extra, "24");
154 assert_eq!(candidate.components.premise, "25");
155 assert_eq!(candidate.components.premise_extra, "26");
156 assert_eq!(candidate.components.premise_number, "27");
157 assert_eq!(candidate.components.premise_prefix_number, "27.5");
158 assert_eq!(candidate.components.premise_type, "28");
159 assert_eq!(candidate.components.thoroughfare, "29");
160 assert_eq!(candidate.components.thoroughfare_predirection, "30");
161 assert_eq!(candidate.components.thoroughfare_postdirection, "31");
162 assert_eq!(candidate.components.thoroughfare_name, "32");
163 assert_eq!(candidate.components.thoroughfare_trailing_type, "33");
164 assert_eq!(candidate.components.thoroughfare_type, "34");
165 assert_eq!(candidate.components.dependent_thoroughfare, "35");
166 assert_eq!(candidate.components.dependent_thoroughfare_predirection, "36");
167 assert_eq!(candidate.components.dependent_thoroughfare_postdirection, "37");
168 assert_eq!(candidate.components.dependent_thoroughfare_name, "38");
169 assert_eq!(candidate.components.dependent_thoroughfare_trailing_type, "39");
170 assert_eq!(candidate.components.dependent_thoroughfare_type, "40");
171 assert_eq!(candidate.components.building, "41");
172 assert_eq!(candidate.components.building_leading_type, "42");
173 assert_eq!(candidate.components.building_name, "43");
174 assert_eq!(candidate.components.building_trailing_type, "44");
175 assert_eq!(candidate.components.sub_building_type, "45");
176 assert_eq!(candidate.components.sub_building_number, "46");
177 assert_eq!(candidate.components.sub_building_name, "47");
178 assert_eq!(candidate.components.sub_building, "48");
179 assert_eq!(candidate.components.level_type, "48.1");
180 assert_eq!(candidate.components.level_number, "48.2");
181 assert_eq!(candidate.components.post_box, "49");
182 assert_eq!(candidate.components.post_box_type, "50");
183 assert_eq!(candidate.components.post_box_number, "51");
184 assert_eq!(candidate.metadata.latitude, 52.0);
185 assert_eq!(candidate.metadata.longitude, 53.0);
186 assert_eq!(candidate.metadata.geocode_precision, "54");
187 assert_eq!(candidate.metadata.max_geocode_precision, "55");
188 assert_eq!(candidate.metadata.address_format, "56");
189 assert_eq!(candidate.analysis.verification_status, "57");
190 assert_eq!(candidate.analysis.address_precision, "58");
191 assert_eq!(candidate.analysis.max_address_precision, "59");
192 assert_eq!(candidate.analysis.changes.root_level.organization, "60");
193 assert_eq!(candidate.analysis.changes.root_level.address1, "61");
194 assert_eq!(candidate.analysis.changes.root_level.address2, "62");
195 assert_eq!(candidate.analysis.changes.root_level.address3, "63");
196 assert_eq!(candidate.analysis.changes.root_level.address4, "64");
197 assert_eq!(candidate.analysis.changes.root_level.address5, "65");
198 assert_eq!(candidate.analysis.changes.root_level.address6, "66");
199 assert_eq!(candidate.analysis.changes.root_level.address7, "67");
200 assert_eq!(candidate.analysis.changes.root_level.address8, "68");
201 assert_eq!(candidate.analysis.changes.root_level.address9, "69");
202 assert_eq!(candidate.analysis.changes.root_level.address10, "70");
203 assert_eq!(candidate.analysis.changes.root_level.address11, "71");
204 assert_eq!(candidate.analysis.changes.root_level.address12, "72");
205 assert_eq!(candidate.analysis.changes.components.super_administrative_area, "73");
206 assert_eq!(candidate.analysis.changes.components.administrative_area, "74");
207 assert_eq!(candidate.analysis.changes.components.administrative_area_short, "74.1");
208 assert_eq!(candidate.analysis.changes.components.administrative_area_long, "74.2");
209 assert_eq!(candidate.analysis.changes.components.sub_administrative_area, "75");
210 assert_eq!(candidate.analysis.changes.components.building, "76");
211 assert_eq!(candidate.analysis.changes.components.dependent_locality, "77");
212 assert_eq!(candidate.analysis.changes.components.dependent_locality_name, "78");
213 assert_eq!(candidate.analysis.changes.components.double_dependent_locality, "79");
214 assert_eq!(candidate.analysis.changes.components.country_iso_3, "80");
215 assert_eq!(candidate.analysis.changes.components.locality, "81");
216 assert_eq!(candidate.analysis.changes.components.postal_code, "82");
217 assert_eq!(candidate.analysis.changes.components.postal_code_short, "83");
218 assert_eq!(candidate.analysis.changes.components.postal_code_extra, "84");
219 assert_eq!(candidate.analysis.changes.components.premise, "85");
220 assert_eq!(candidate.analysis.changes.components.premise_extra, "86");
221 assert_eq!(candidate.analysis.changes.components.premise_number, "87");
222 assert_eq!(candidate.analysis.changes.components.premise_type, "88");
223 assert_eq!(candidate.analysis.changes.components.premise_prefix_number, "89");
224 assert_eq!(candidate.analysis.changes.components.thoroughfare, "90");
225 assert_eq!(candidate.analysis.changes.components.thoroughfare_predirection, "91");
226 assert_eq!(candidate.analysis.changes.components.thoroughfare_postdirection, "92");
227 assert_eq!(candidate.analysis.changes.components.thoroughfare_name, "93");
228 assert_eq!(candidate.analysis.changes.components.thoroughfare_trailing_type, "94");
229 assert_eq!(candidate.analysis.changes.components.thoroughfare_type, "95");
230 assert_eq!(candidate.analysis.changes.components.dependent_thoroughfare, "96");
231 assert_eq!(candidate.analysis.changes.components.dependent_thoroughfare_predirection, "97");
232 assert_eq!(candidate.analysis.changes.components.dependent_thoroughfare_postdirection, "98");
233 assert_eq!(candidate.analysis.changes.components.dependent_thoroughfare_name, "99");
234 assert_eq!(candidate.analysis.changes.components.dependent_thoroughfare_trailing_type, "100");
235 assert_eq!(candidate.analysis.changes.components.dependent_thoroughfare_type, "101");
236 assert_eq!(candidate.analysis.changes.components.building_leading_type, "102");
237 assert_eq!(candidate.analysis.changes.components.building_name, "103");
238 assert_eq!(candidate.analysis.changes.components.building_trailing_type, "104");
239 assert_eq!(candidate.analysis.changes.components.sub_building_type, "105");
240 assert_eq!(candidate.analysis.changes.components.sub_building_number, "106");
241 assert_eq!(candidate.analysis.changes.components.sub_building_name, "107");
242 assert_eq!(candidate.analysis.changes.components.sub_building, "108");
243 assert_eq!(candidate.analysis.changes.components.level_type, "108.1");
244 assert_eq!(candidate.analysis.changes.components.level_number, "108.2");
245 assert_eq!(candidate.analysis.changes.components.post_box, "109");
246 assert_eq!(candidate.analysis.changes.components.post_box_type, "110");
247 assert_eq!(candidate.analysis.changes.components.post_box_number, "111");
248 assert_eq!(candidate.analysis.changes.components.additional_content, "112");
249 assert_eq!(candidate.analysis.changes.components.delivery_installation, "113");
250 assert_eq!(candidate.analysis.changes.components.delivery_installation_type, "114");
251 assert_eq!(candidate.analysis.changes.components.delivery_installation_qualifier_name, "115");
252 assert_eq!(candidate.analysis.changes.components.route, "116");
253 assert_eq!(candidate.analysis.changes.components.route_number, "117");
254 assert_eq!(candidate.analysis.changes.components.route_type, "118");
255 }
256}