This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7291bbd
commit e2acf4f
Showing
5 changed files
with
129 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ mod note; | |
mod prompts; | ||
mod return_to_main; | ||
mod utilities; | ||
mod tests; | ||
|
||
use crate::{ | ||
note::Note, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#[cfg(test)] | ||
use crate::{api, note::Note}; | ||
use chrono::prelude::Local; | ||
use async_std::path::PathBuf; | ||
use tempfile::tempdir; | ||
|
||
#[test] | ||
fn test_db_init() -> Result<(), Box<dyn std::error::Error>> { | ||
let dir = tempdir()?; | ||
let data_directory = PathBuf::from(dir.path()); | ||
let db_file = data_directory.join("notes.db"); | ||
assert!(api::init_db(&data_directory, &db_file).is_ok()); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_save_note() -> Result<(), Box<dyn std::error::Error>> { | ||
let dir = tempdir()?; | ||
let data_directory = PathBuf::from(dir.path()); | ||
let db_file: PathBuf = data_directory.join("notes.db"); | ||
api::init_db(&data_directory, &db_file)?; | ||
|
||
let note = Note { | ||
id: 0, | ||
name: "Test".to_string(), | ||
content: "Test".to_string(), | ||
created: format!("{}", Local::now().format("%A %e %B, %H:%M")), | ||
}; | ||
|
||
assert!(api::save_note(¬e, &db_file).is_ok()); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_delete_notes() { | ||
let dir = tempdir().unwrap(); | ||
let data_directory = PathBuf::from(dir.path()); | ||
let db_file = data_directory.join("notes.db"); | ||
api::init_db(&data_directory, &db_file).unwrap(); | ||
|
||
let note = Note { | ||
id: 0, | ||
name: "Test".to_string(), | ||
content: "Test".to_string(), | ||
created: format!("{}", Local::now().format("%A %e %B, %H:%M")), | ||
}; | ||
|
||
api::save_note(¬e, &db_file).unwrap(); | ||
let notes = api::get_notes(&db_file).unwrap(); | ||
let ids: Vec<usize> = notes.iter().map(|note| note.id).collect(); | ||
api::delete_notes(ids, &db_file).unwrap(); | ||
assert!(api::get_notes(&db_file).unwrap().is_empty()); | ||
} | ||
|
||
#[test] | ||
fn test_get_notes() -> Result<(), Box<dyn std::error::Error>> { | ||
let dir = tempdir()?; | ||
let data_directory = PathBuf::from(dir.path()); | ||
let db_file = data_directory.join("notes.db"); | ||
api::init_db(&data_directory, &db_file)?; | ||
|
||
let note = Note { | ||
id: 0, | ||
name: "Test".to_string(), | ||
content: "Test".to_string(), | ||
created: format!("{}", Local::now().format("%A %e %B, %H:%M")), | ||
}; | ||
|
||
api::save_note(¬e, &db_file)?; | ||
assert!(!api::get_notes(&db_file)?.is_empty()); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod api; |