1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
pub mod client;

pub mod lookup;

pub mod candidate;

// Tests
#[cfg(test)]
mod tests {
    use crate::sdk::authentication::SecretKeyCredential;
    use crate::sdk::batch::Batch;
    use crate::sdk::options::OptionsBuilder;
    use crate::us_zipcode_api::client::USZipcodeClient;
    use crate::us_zipcode_api::lookup::Lookup;

    #[test]
    fn client_test() {
        let options = OptionsBuilder::new()
            .authenticate(SecretKeyCredential::new("".to_string(), "".to_string()))
            .build()
            .unwrap();
        let client = USZipcodeClient::new(options).unwrap();

        assert_eq!(
            client.client.url.to_string(),
            "https://us-zipcode.api.smarty.com/lookup".to_string()
        )
    }

    #[test]
    fn lookup_test() {
        let lookup = Lookup {
            city: "Provo".to_string(),
            state: "UT".to_string(),
            zipcode: "84604".to_string(),
            ..Default::default()
        };

        let expected_result = vec![
            ("city".to_string(), "Provo".to_string()),
            ("state".to_string(), "UT".to_string()),
            ("zipcode".to_string(), "84604".to_string()),
        ];

        assert_eq!(lookup.into_param_array(), expected_result);
    }

    #[test]
    fn batch_test() {
        let lookup = Lookup {
            city: "Provo".to_string(),
            state: "UT".to_string(),
            zipcode: "84604".to_string(),
            ..Default::default()
        };

        let expected_result = vec![
            ("city".to_string(), "Provo".to_string()),
            ("state".to_string(), "UT".to_string()),
            ("zipcode".to_string(), "84604".to_string()),
        ];

        let mut batch = Batch::default();
        batch.push(lookup.clone()).unwrap();
        batch.push(lookup.clone()).unwrap();
        batch.push(lookup).unwrap();

        assert_eq!(
            batch.records()[0].clone().into_param_array(),
            expected_result
        );
        assert_eq!(batch.len(), 3);
    }
}