use serde::Serialize;
use crate::AnkiRequest;
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize)]
pub struct GetMediaFilesNamesRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub pattern: Option<String>,
}
impl AnkiRequest for GetMediaFilesNamesRequest {
type Response = Vec<String>;
const ACTION: &'static str = "getMediaFilesNames";
const VERSION: u8 = 6;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize() {
let request = GetMediaFilesNamesRequest {
pattern: Some("_hell*.txt".to_string()),
};
let json = serde_json::to_string_pretty(&request).unwrap();
assert_eq!(
json,
r#"{
"pattern": "_hell*.txt"
}"#
);
}
#[test]
fn test_serialize_no_pattern() {
let request = GetMediaFilesNamesRequest {
..Default::default()
};
let json = serde_json::to_string_pretty(&request).unwrap();
assert_eq!(json, "{}");
}
#[test]
fn test_deserialize() {
let json = r#"["_hello.txt", "_hallo.txt", "_heeello.txt"]"#;
let response: <GetMediaFilesNamesRequest as AnkiRequest>::Response =
serde_json::from_str(json).unwrap();
assert_eq!(
response,
vec![
"_hello.txt".to_string(),
"_hallo.txt".to_string(),
"_heeello.txt".to_string()
]
);
}
}