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