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

63 lines
2.1 KiB
Rust
Raw Normal View History

mod errors;
2020-10-06 15:01:25 +00:00
mod row_structs;
mod store;
mod structs;
pub use crate::errors::NoteStoreError;
pub use crate::store::NoteStore;
#[cfg(test)]
mod tests {
use chrono;
use super::*;
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
}
2020-10-06 15:01:25 +00:00
// Request for the page by slug.
// If the page exists, return it. If the page doesn't, return NotFound
#[tokio::test(threaded_scheduler)]
2020-10-06 15:01:25 +00:00
async fn fetching_unfound_page_by_slug_works() {
let storagepool = fresh_inmemory_database().await;
2020-10-06 15:01:25 +00:00
let unfoundpage = storagepool.get_page_by_slug("nonexistent-page").await;
assert!(unfoundpage.is_err());
}
2020-10-06 15:01:25 +00:00
// 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)]
2020-10-06 15:01:25 +00:00
async fn fetching_unfound_page_by_title_works() {
let title = "Nonexistent Page";
let _now = chrono::Utc::now();
let storagepool = fresh_inmemory_database().await;
2020-10-06 15:01:25 +00:00
let newpageresult = storagepool.get_page_by_title(&title).await;
assert!(newpageresult.is_ok(), "{:?}", newpageresult);
let (newpage, _newnotes) = newpageresult.unwrap();
2020-10-06 15:01:25 +00:00
assert_eq!(newpage.title, title, "{:?}", newpage.title);
assert_eq!(newpage.slug, "nonexistent-page");
}
2020-09-30 16:17:37 +00:00
2020-10-06 15:01:25 +00:00
// // 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());
// }
}