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
//! Mappings for APIs of *The Things Network*.

pub mod http;

#[cfg(test)]
mod test {
    use crate::http::Uplink;
    use serde_json::json;

    pub fn parse(json:&[u8]) -> Uplink {
        let uplink = serde_json::from_slice(json);

        println!("{:?}", uplink);

        assert!(uplink.is_ok());

        uplink.unwrap()
    }

    #[test]
    pub fn data1() {
        let uplink: Uplink = parse(include_bytes!("../test/data1.json"));

        assert_eq!("foo", uplink.app_id);
        assert_eq!("device-01", uplink.dev_id);
        assert_eq!(
            json!({
              "luminosity_21": 5
            }),
            uplink.payload_fields
        )
    }

    #[test]
    pub fn simulation() {
        let uplink: Uplink = parse(include_bytes!("../test/simulation.json"));

        assert_eq!("foo", uplink.app_id);
        assert_eq!("device_id", uplink.dev_id);
    }

}