use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NewNotification {
pub notification_type: String,
pub resource_type: String,
pub provider_id: String,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub notification: Option<Value>,
}
#[cfg(test)]
mod tests {
use serde_json::json;
use super::NewNotification;
#[test]
fn serde_1() {
let notification = NewNotification {
notification_type: "SHARE_ACCEPTED".to_string(),
resource_type: "file".to_string(),
provider_id: "7c084226-d9a1-11e6-bf26-cec0c932ce01".to_string(),
notification: Some(json!({
"message": "Recipient accepted the share",
"sharedSecret": "hfiuhworzwnur98d3wjiwhr"
}))
};
let json = json!({
"notificationType": "SHARE_ACCEPTED",
"resourceType": "file",
"providerId": "7c084226-d9a1-11e6-bf26-cec0c932ce01",
"notification": {
"message": "Recipient accepted the share",
"sharedSecret": "hfiuhworzwnur98d3wjiwhr"
}
});
assert_eq!(serde_json::to_value(notification).unwrap() ,json);
}
#[test]
fn serde_2() {
let notification = NewNotification {
notification_type: "USER_REMOVED".to_string(),
resource_type: "user".to_string(),
provider_id: "51dc30ddc473d43a6011e9ebba6ca770".to_string(),
notification: None
};
let json = json!({
"notificationType": "USER_REMOVED",
"resourceType": "user",
"providerId": "51dc30ddc473d43a6011e9ebba6ca770",
});
assert_eq!(serde_json::to_value(notification).unwrap() ,json);
}
}