ilert/
lib.rs

1#![allow(dead_code,unused)]
2
3pub mod ilert;
4pub mod ilert_error;
5pub mod ilert_builders;
6
7#[cfg(test)]
8mod tests {
9
10    use serde_json::json;
11
12    use crate::ilert::ILert;
13    use crate::ilert_builders::{UserGetApiResource, EventApiResource, ScheduleGetApiResource, HeartbeatApiResource, ILertEventType, ILertPriority, EventImage, EventComment, AlertGetApiResource, AlertPutApiResource};
14
15    #[tokio::test]
16    async fn init() -> () {
17        env_logger::init();
18    }
19
20    #[tokio::test]
21    async fn user_test() {
22
23        let mut client = ILert::new_with_opts(Some("http://localhost:8080"), Some(10)).unwrap();
24        client.auth_via_user("chris@chris", "chris").unwrap();
25
26        let user_result = client
27            .get()
28            .skip(0)
29            .limit(10)
30            .users()
31            .execute()
32            .await
33            .unwrap();
34
35        assert_eq!(user_result.status, 200);
36    }
37
38    #[tokio::test]
39    async fn alert_test() {
40
41        let mut client = ILert::new_with_opts(Some("http://localhost:8080"), Some(10)).unwrap();
42        client.auth_via_user("chris@chris", "chris").unwrap();
43
44        let alert_result = client
45            .get()
46            .skip(0)
47            .limit(10)
48            .filter("states", "ACCEPTED")
49            .filter("states", "RESOLVED")
50            .alerts()
51            .execute()
52            .await
53            .unwrap();
54
55        assert_eq!(alert_result.status, 200);
56    }
57
58    #[tokio::test]
59    async fn schedule_test() {
60
61        let mut client = ILert::new_with_opts(Some("http://localhost:8080"), Some(10)).unwrap();
62        client.auth_via_user("chris@chris", "chris").unwrap();
63
64        let schedule_result = client
65            .get()
66            .schedule_shifts(99)
67            .execute()
68            .await
69            .unwrap();
70
71        assert_eq!(schedule_result.status, 404);
72    }
73
74    #[tokio::test]
75    async fn create_comment_and_resolve_event_test() {
76
77        let mut client = ILert::new_with_opts(Some("http://localhost:8080"), Some(10)).unwrap();
78
79        let event_result = client
80            .create()
81            .event_with_details(
82                "il1api0220953b09684c9e4fe8972f0d5d8c9cde78d79b6cc8fd",
83                ILertEventType::ALERT,
84                Some("Host srv/mail01 is CRITICAL".to_string()),
85                Some("bratwurst".to_string()),
86                Some("some detail message".to_string()),
87                Some(ILertPriority::LOW),
88                Some(vec![EventImage::new("https://i.giphy.com/media/VRhsYYBw8AE36/giphy.webp")]),
89                Some(vec![]),
90                Some(json!({"hehe": "test"})),
91                None
92            )
93            .execute()
94            .await
95            .unwrap();
96
97        assert_eq!(event_result.status, 202);
98
99        let event_comment_result = client
100            .create()
101            .event_with_comment(
102                "il1api0220953b09684c9e4fe8972f0d5d8c9cde78d79b6cc8fd",
103                Some("bratwurst".to_string()),
104                Some(vec![EventComment::new("Peter Parker",
105                                            "a comment ![alt text picture](https://i.giphy.com/media/VRhsYYBw8AE36/giphy.webp) salut")])
106            )
107            .execute()
108            .await
109            .unwrap();
110
111        assert_eq!(event_comment_result.status, 202);
112
113        let resolve_result = client
114            .create()
115            .event("il1api0220953b09684c9e4fe8972f0d5d8c9cde78d79b6cc8fd",
116                   ILertEventType::RESOLVE, None,
117                    Some("bratwurst".to_string()))
118            .execute()
119            .await
120            .unwrap();
121
122        assert_eq!(resolve_result.status, 202);
123    }
124
125    #[tokio::test]
126    async fn heartbeat_test() {
127
128        let mut client = ILert::new_with_opts(Some("http://localhost:8080"), Some(10)).unwrap();
129
130        let heartbeat_result = client
131            .get()
132            .heartbeat("43c7afdc-0b3e-4344-b48a-5379a963241f")
133            .execute()
134            .await
135            .unwrap();
136
137        assert_eq!(heartbeat_result.status, 202);
138    }
139}