From cc70f52849443ef0c5518356b9e1d6d584eac986 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 3 Dec 2021 23:59:03 +0800 Subject: [PATCH] test: add test for importer --- _fixtures/import_test/todo.json | 33 +++++++++++++++++++++++++++++ quake_analysis/src/main.rs | 2 +- quake_importer/src/main.rs | 22 +++++++++++++++---- quake_importer/test_temp/.gitignore | 3 +++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 _fixtures/import_test/todo.json create mode 100644 quake_importer/test_temp/.gitignore diff --git a/_fixtures/import_test/todo.json b/_fixtures/import_test/todo.json new file mode 100644 index 00000000..9be8884c --- /dev/null +++ b/_fixtures/import_test/todo.json @@ -0,0 +1,33 @@ +[ + { + "displayName": "Flagged Emails", + "id": "AQMkADAwATM0MDAAMS04N2E2LWRhMDItMDACLTAwCgAuAAADlaHHnFnn1UuoFE2pMt0j5QEAaMraZPkN_0mltv0IMNqe5wAEmScfOgAAAA==", + "wellknownListName": "flaggedEmails", + "children": [] + }, + { + "displayName": "任务", + "id": "AQMkADAwATM0MDAAMS04N2E2LWRhMDItMDACLTAwCgAuAAADlaHHnFnn1UuoFE2pMt0j5QEAaMraZPkN_0mltv0IMNqe5wAAAgESAAAA", + "wellknownListName": "defaultList", + "children": [ + { + "body": { + "content": "", + "contentType": "text" + }, + "bodyLastModifiedDateTime": null, + "completedDateTime": null, + "createdDateTime": "2021-11-05T07:43:38.2189068Z", + "dueDateTime": null, + "id": "AQMkADAwATM0MDAAMS04N2E2LWRhMDItMDACLTAwCgBGAAADlaHHnFnn1UuoFE2pMt0j5QcAaMraZPkN_0mltv0IMNqe5wAAAgESAAAAaMraZPkN_0mltv0IMNqe5wAEy-HmfAAAAA==", + "importance": "normal", + "isReminderOn": false, + "lastModifiedDateTime": "2021-11-05T07:53:39.9007193Z", + "recurrence": null, + "reminderDateTime": null, + "status": "notStarted", + "title": "Game Develop" + } + ] + } +] \ No newline at end of file diff --git a/quake_analysis/src/main.rs b/quake_analysis/src/main.rs index 2fd6423e..7d36c4fa 100644 --- a/quake_analysis/src/main.rs +++ b/quake_analysis/src/main.rs @@ -14,7 +14,7 @@ fn is_markdown(entry: &DirEntry) -> bool { } fn main() { - count_by_path(PathBuf::from("_fixtures").join("phodal_com")); + count_by_path(PathBuf::from("_fixtures").join("blog")); } fn count_by_path(path: PathBuf) { diff --git a/quake_importer/src/main.rs b/quake_importer/src/main.rs index 0318e531..29bbca7e 100644 --- a/quake_importer/src/main.rs +++ b/quake_importer/src/main.rs @@ -106,6 +106,7 @@ fn main() { #[cfg(test)] mod tests { + use quake_core::entry::entry_file::EntryFile; use std::fs; use std::path::PathBuf; @@ -126,12 +127,25 @@ mod tests { let path = PathBuf::from("..").join("_fixtures").join("notes"); let _ = dump_apple_notes("../dbs/mac_apt.db", path); } - #[ignore] + #[test] fn dump_todo() { - let path = PathBuf::from("..").join("_fixtures").join("microsoft_todo"); - let todo = fs::read_to_string("../dbs/todo-output.json").unwrap(); + let output_dir = PathBuf::from("test_temp").join("todo"); + fs::create_dir_all(&output_dir).unwrap(); + + let input = PathBuf::from("../") + .join("_fixtures") + .join("import_test") + .join("todo.json"); + + let todo = fs::read_to_string(format!("{:}", input.display())).unwrap(); let vec: Vec = serde_json::from_str(&*todo).unwrap(); - let _ = dump_microsoft_todo(vec, &path); + let _ = dump_microsoft_todo(vec, &output_dir); + + let str = fs::read_to_string(output_dir.join("0001-game-develop.md")).unwrap(); + let file = EntryFile::from(str.as_str(), 1).unwrap(); + + assert_eq!(file.field("title").unwrap(), "Game Develop"); + // fs::remove_dir_all(output_dir).unwrap(); } } diff --git a/quake_importer/test_temp/.gitignore b/quake_importer/test_temp/.gitignore new file mode 100644 index 00000000..a5baada1 --- /dev/null +++ b/quake_importer/test_temp/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +