ocm_types/
notification.rs1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct NewNotification {
7 pub notification_type: String,
15 pub resource_type: String,
17 pub provider_id: String,
22 #[serde(skip_serializing_if = "Option::is_none", default)]
25 pub notification: Option<Value>,
26}
27
28#[cfg(test)]
29mod tests {
30 use serde_json::json;
31
32 use super::NewNotification;
33
34 #[test]
35 fn serde_1() {
36 let notification = NewNotification {
37 notification_type: "SHARE_ACCEPTED".to_string(),
38 resource_type: "file".to_string(),
39 provider_id: "7c084226-d9a1-11e6-bf26-cec0c932ce01".to_string(),
40 notification: Some(json!({
41 "message": "Recipient accepted the share",
42 "sharedSecret": "hfiuhworzwnur98d3wjiwhr"
43 }))
44 };
45
46 let json = json!({
47 "notificationType": "SHARE_ACCEPTED",
48 "resourceType": "file",
49 "providerId": "7c084226-d9a1-11e6-bf26-cec0c932ce01",
50 "notification": {
51 "message": "Recipient accepted the share",
52 "sharedSecret": "hfiuhworzwnur98d3wjiwhr"
53 }
54 });
55 assert_eq!(serde_json::to_value(notification).unwrap() ,json);
56 }
57
58 #[test]
59 fn serde_2() {
60 let notification = NewNotification {
61 notification_type: "USER_REMOVED".to_string(),
62 resource_type: "user".to_string(),
63 provider_id: "51dc30ddc473d43a6011e9ebba6ca770".to_string(),
64 notification: None
65 };
66
67 let json = json!({
68 "notificationType": "USER_REMOVED",
69 "resourceType": "user",
70 "providerId": "51dc30ddc473d43a6011e9ebba6ca770",
71 });
72 assert_eq!(serde_json::to_value(notification).unwrap() ,json);
73 }
74}
75