smarty_rust_sdk/us_zipcode_api/
mod.rs1pub mod client;
2
3pub mod lookup;
4
5pub mod candidate;
6
7#[cfg(test)]
9mod tests {
10 use crate::sdk::batch::Batch;
11 use crate::sdk::options::OptionsBuilder;
12 use crate::us_zipcode_api::client::USZipcodeClient;
13 use crate::us_zipcode_api::lookup::Lookup;
14
15 #[test]
16 fn client_test() {
17 let options = OptionsBuilder::new(None).build();
18 let client = USZipcodeClient::new(options).unwrap();
19
20 assert_eq!(
21 client.client.url.to_string(),
22 "https://us-zipcode.api.smarty.com/lookup".to_string()
23 )
24 }
25
26 #[test]
27 fn lookup_test() {
28 let lookup = Lookup {
29 city: "Provo".to_string(),
30 state: "UT".to_string(),
31 zipcode: "84604".to_string(),
32 ..Default::default()
33 };
34
35 let expected_result = vec![
36 ("city".to_string(), "Provo".to_string()),
37 ("state".to_string(), "UT".to_string()),
38 ("zipcode".to_string(), "84604".to_string()),
39 ];
40
41 assert_eq!(lookup.into_param_array(), expected_result);
42 }
43
44 #[test]
45 fn batch_test() {
46 let lookup = Lookup {
47 city: "Provo".to_string(),
48 state: "UT".to_string(),
49 zipcode: "84604".to_string(),
50 ..Default::default()
51 };
52
53 let expected_result = vec![
54 ("city".to_string(), "Provo".to_string()),
55 ("state".to_string(), "UT".to_string()),
56 ("zipcode".to_string(), "84604".to_string()),
57 ];
58
59 let mut batch = Batch::default();
60 batch.push(lookup.clone()).unwrap();
61 batch.push(lookup.clone()).unwrap();
62 batch.push(lookup).unwrap();
63
64 assert_eq!(
65 batch.records()[0].clone().into_param_array(),
66 expected_result
67 );
68 assert_eq!(batch.len(), 3);
69 }
70}