smarty_rust_sdk/us_autocomplete_pro_api/
mod.rs

1pub mod client;
2pub mod lookup;
3pub mod suggestion;
4
5#[cfg(test)]
6mod tests {
7    use crate::sdk::options::OptionsBuilder;
8    use crate::us_autocomplete_pro_api::client::USAutocompleteProClient;
9    use crate::us_autocomplete_pro_api::lookup::{Geolocation, Lookup};
10
11    #[test]
12    fn client_test() {
13        let client = USAutocompleteProClient::new(OptionsBuilder::new(None).build()).unwrap();
14
15        assert_eq!(
16            client.client.url.to_string(),
17            "https://us-autocomplete-pro.api.smarty.com/lookup".to_string()
18        )
19    }
20
21    #[test]
22    fn lookup_test() {
23        let lookup = Lookup {
24            search: "1042 W Center".to_string(),
25            max_results: 5,
26            city_filter: vec!["Denver,CO".to_string(), "Orem,UT".to_string()],
27            state_filter: vec!["CO".to_string(), "UT".to_string()],
28            prefer_state: vec!["CO".to_string()],
29            prefer_ratio: 3,
30            geolocation: Geolocation::GeolocateCity,
31            source: "all".to_string(),
32            ..Default::default()
33        };
34
35        let expected_results = vec![
36            ("search".to_string(), "1042 W Center".to_string()),
37            ("source".to_string(), "all".to_string()),
38            ("max_results".to_string(), "5".to_string()),
39            (
40                "include_only_cities".to_string(),
41                "Denver,CO;Orem,UT".to_string(),
42            ),
43            ("include_only_states".to_string(), "CO;UT".to_string()),
44            ("prefer_states".to_string(), "CO".to_string()),
45            ("prefer_ratio".to_string(), "3".to_string()),
46            ("prefer_geolocation".to_string(), "city".to_string()),
47        ];
48
49        assert_eq!(lookup.into_param_array(), expected_results)
50    }
51}