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
use crate::types::location::Location;
use serde::Deserialize;

/// Venue
#[derive(Clone, Debug, Deserialize)]
pub struct Venue {
    /// Venue location
    pub location: Location,
    /// Name of the venue
    pub title: String,
    /// Address of the venue
    pub address: String,
    /// Foursquare identifier of the venue
    pub foursquare_id: Option<String>,
    /// Foursquare type of the venue
    /// For example: “arts_entertainment/default”,
    /// “arts_entertainment/aquarium” or “food/icecream”
    pub foursquare_type: Option<String>,
}

#[cfg(test)]
mod tests {
    #![allow(clippy::float_cmp)]
    use super::*;

    #[test]
    fn deserialize_full() {
        let data: Venue = serde_json::from_value(serde_json::json!({
            "location": {
                "latitude": 1.1,
                "longitude": 2.0
            },
            "title": "venue title",
            "address": "venue address",
            "foursquare_id": "f-id",
            "foursquare_type": "f-type"
        }))
        .unwrap();

        assert_eq!(data.location.latitude, 1.1);
        assert_eq!(data.location.longitude, 2.0);
        assert_eq!(data.title, "venue title");
        assert_eq!(data.address, "venue address");
        assert_eq!(data.foursquare_id.unwrap(), "f-id");
        assert_eq!(data.foursquare_type.unwrap(), "f-type");
    }

    #[test]
    fn deserialize_partial() {
        let data: Venue = serde_json::from_value(serde_json::json!({
            "location": {
                "latitude": 1.1,
                "longitude": 2.0
            },
            "title": "venue title",
            "address": "venue address"
        }))
        .unwrap();

        assert_eq!(data.location.latitude, 1.1);
        assert_eq!(data.location.longitude, 2.0);
        assert_eq!(data.title, "venue title");
        assert_eq!(data.address, "venue address");
        assert!(data.foursquare_id.is_none());
        assert!(data.foursquare_type.is_none());
    }
}