mod errors; mod store; mod structs; pub use crate::errors::NoteStoreError; pub use crate::store::NoteStore; #[cfg(test)] mod tests { use super::*; use tokio; async fn fresh_inmemory_database() -> NoteStore { let storagepool = NoteStore::new("sqlite://:memory:").await; assert!(storagepool.is_ok()); let storagepool = storagepool.unwrap(); assert!(storagepool.reset_database().await.is_ok()); storagepool } #[tokio::test(threaded_scheduler)] async fn fetching_unfound_page_works() { let storagepool = fresh_inmemory_database().await; let unfoundpage = storagepool.fetch_page("nonexistent-page").await; assert!(unfoundpage.is_err()); } #[tokio::test(threaded_scheduler)] async fn fetching_unfound_note_works() { let storagepool = fresh_inmemory_database().await; let unfoundnote = storagepool.fetch_note("nonexistent-note").await; assert!(unfoundnote.is_err()); } #[tokio::test(threaded_scheduler)] async fn cloning_storagepool_is_ok() { let storagepool = fresh_inmemory_database().await; let storagepool2 = storagepool.clone(); let unfoundnote = storagepool2.fetch_note("nonexistent-note").await; assert!(unfoundnote.is_err()); let unfoundnote = storagepool.fetch_note("nonexistent-note").await; assert!(unfoundnote.is_err()); } #[tokio::test(threaded_scheduler)] async fn can_save_a_note() { let storagepool = fresh_inmemory_database().await; let note_id = storagepool.insert_note("noteid", "notecontent", "note").await; assert!(note_id.is_ok(), format!("note is not ok: {:?}", note_id)); let note_id = note_id.unwrap(); assert!(note_id > 0); let foundnote = storagepool.fetch_note("noteid").await; assert!(foundnote.is_ok(), format!("foundnote is not ok: {:?}", foundnote)); let foundnote = foundnote.unwrap(); assert_eq!(foundnote.content, "notecontent"); assert_eq!(foundnote.notetype, "note"); } }