use serde::Serialize;
use std::path::PathBuf;
use crate::AnkiRequest;
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize)]
pub struct GuiImportFileRequest {
pub path: Option<PathBuf>,
}
impl AnkiRequest for GuiImportFileRequest {
type Response = ();
const ACTION: &'static str = "guiImportFile";
const VERSION: u8 = 6;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize_windows_path() {
let request = GuiImportFileRequest {
path: Some(PathBuf::from("C:/Users/Desktop/cards.txt")),
};
let json = serde_json::to_string_pretty(&request).unwrap();
assert_eq!(
json,
r#"{
"path": "C:/Users/Desktop/cards.txt"
}"#
);
}
#[test]
fn test_serialize_linux_path() {
let request = GuiImportFileRequest {
path: Some(PathBuf::from("/home/anki/My Files/Collection.txt")),
};
let json = serde_json::to_string_pretty(&request).unwrap();
assert_eq!(
json,
r#"{
"path": "/home/anki/My Files/Collection.txt"
}"#
);
}
}