notesmachine/server/nm-store/src/lib.rs

63 lines
2.1 KiB
Rust

mod errors;
mod row_structs;
mod store;
mod structs;
pub use crate::errors::NoteStoreError;
pub use crate::store::NoteStore;
#[cfg(test)]
mod tests {
use super::*;
use chrono;
use tokio;
async fn fresh_inmemory_database() -> NoteStore {
let storagepool = NoteStore::new("sqlite://:memory:").await;
assert!(storagepool.is_ok(), "{:?}", storagepool);
let storagepool = storagepool.unwrap();
let reset = storagepool.reset_database().await;
assert!(reset.is_ok(), "{:?}", reset);
storagepool
}
// Request for the page by slug.
// If the page exists, return it. If the page doesn't, return NotFound
#[tokio::test(threaded_scheduler)]
async fn fetching_unfound_page_by_slug_works() {
let storagepool = fresh_inmemory_database().await;
let unfoundpage = storagepool.get_page_by_slug("nonexistent-page").await;
assert!(unfoundpage.is_err());
}
// Request for the page by title. If the page exists, return it.
// If the page doesn't exist, create it then return it anyway.
// There should be at least one note, the root note.
#[tokio::test(threaded_scheduler)]
async fn fetching_unfound_page_by_title_works() {
let title = "Nonexistent Page";
let _now = chrono::Utc::now();
let storagepool = fresh_inmemory_database().await;
let newpageresult = storagepool.get_page_by_title(&title).await;
assert!(newpageresult.is_ok(), "{:?}", newpageresult);
let (newpage, _newnotes) = newpageresult.unwrap();
assert_eq!(newpage.title, title, "{:?}", newpage.title);
assert_eq!(newpage.slug, "nonexistent-page");
}
// // TODO: This should be 1, not 0
// assert_eq!(newnotes.len(), 0);
// // assert_eq!(newnotes[0].notetype, "root");
// // assert_eq!(newpage.note_id, newnotes[0].id);
//
// assert!((newpage.creation_date - now).num_minutes() < 1.0);
// assert!((newpage.updated_date - now).num_minutes() < 1.0);
// assert!((newpage.lastview_date - now).num_minutes() < 1.0);
// assert!(newpage.deleted_date.is_none());
// }
}