ed_journals/modules/logs/content/log_event_content/
missions_event.rs

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
use serde::{Deserialize, Serialize};

use crate::modules::station::MissionType;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct MissionsEvent {
    pub active: Vec<MissionEventEntry>,
    pub failed: Vec<MissionEventEntry>,
    pub complete: Vec<MissionEventEntry>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct MissionEventEntry {
    #[serde(rename = "MissionID")]
    pub mission_id: u64,
    pub name: MissionType,
    pub passenger_mission: bool,
    pub expires: u64,
}

#[cfg(test)]
mod tests {
    use serde_json::json;

    use crate::logs::content::log_event_content::missions_event::{
        MissionEventEntry, MissionsEvent,
    };
    use crate::modules::station::MissionType;

    #[test]
    fn mission_event_is_parsed_correctly() {
        let value: MissionsEvent = serde_json::from_value(json!({
            "Active": [
                {
                    "MissionID": 65380900,
                    "Name": "Mission_Courier_name",
                    "PassengerMission": false,
                    "Expires": 82751
                }
            ],
            "Failed": [],
            "Complete": []
        }))
        .unwrap();

        let expected = MissionsEvent {
            active: vec![MissionEventEntry {
                mission_id: 65380900,
                name: MissionType("Mission_Courier_name".to_string()),
                passenger_mission: false,
                expires: 82751,
            }],
            failed: vec![],
            complete: vec![],
        };

        assert_eq!(value, expected);
    }
}