Import push::Action tests from ruma-events
This commit is contained in:
parent
cf2747cc70
commit
97255eff60
@ -11,6 +11,7 @@ repository = "https://github.com/ruma/ruma-client-api"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
matches = "0.1.8"
|
||||||
ruma-serde = "0.1.3"
|
ruma-serde = "0.1.3"
|
||||||
serde = { version = "1.0.106", features = ["derive"] }
|
serde = { version = "1.0.106", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.52", features = ["raw_value"] }
|
serde_json = { version = "1.0.52", features = ["raw_value"] }
|
||||||
|
74
src/push.rs
74
src/push.rs
@ -117,3 +117,77 @@ impl Serialize for Action {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use matches::assert_matches;
|
||||||
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
|
use super::{Action, Tweak};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize_string_action() {
|
||||||
|
assert_eq!(to_json_value(&Action::Notify).unwrap(), json!("notify"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize_tweak_sound_action() {
|
||||||
|
assert_eq!(
|
||||||
|
to_json_value(&Action::SetTweak(Tweak::Sound("default".into()))).unwrap(),
|
||||||
|
json!({ "set_tweak": "sound", "value": "default" })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn serialize_tweak_highlight_action() {
|
||||||
|
assert_eq!(
|
||||||
|
to_json_value(&Action::SetTweak(Tweak::Highlight(true))).unwrap(),
|
||||||
|
json!({ "set_tweak": "highlight" })
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
to_json_value(&Action::SetTweak(Tweak::Highlight(false))).unwrap(),
|
||||||
|
json!({ "set_tweak": "highlight", "value": false })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_string_action() {
|
||||||
|
assert_matches!(
|
||||||
|
from_json_value::<Action>(json!("notify")).unwrap(),
|
||||||
|
Action::Notify
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_tweak_sound_action() {
|
||||||
|
let json_data = json!({
|
||||||
|
"set_tweak": "sound",
|
||||||
|
"value": "default"
|
||||||
|
});
|
||||||
|
assert_matches!(
|
||||||
|
&from_json_value::<Action>(json_data).unwrap(),
|
||||||
|
Action::SetTweak(Tweak::Sound(value)) if value == "default"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_tweak_highlight_action() {
|
||||||
|
let json_data = json!({
|
||||||
|
"set_tweak": "highlight",
|
||||||
|
"value": true
|
||||||
|
});
|
||||||
|
assert_matches!(
|
||||||
|
from_json_value::<Action>(json_data).unwrap(),
|
||||||
|
Action::SetTweak(Tweak::Highlight(true))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_tweak_highlight_action_with_default_value() {
|
||||||
|
assert_matches!(
|
||||||
|
from_json_value::<Action>(json!({ "set_tweak": "highlight" })).unwrap(),
|
||||||
|
Action::SetTweak(Tweak::Highlight(true))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user