test display with old databases

This commit is contained in:
Abraham Toriz 2021-06-29 12:04:54 -05:00
parent 2e06994314
commit bd10e8582a
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
3 changed files with 45 additions and 0 deletions

BIN
assets/test_old_db.db Normal file

Binary file not shown.

View File

@ -39,6 +39,7 @@ impl FromStr for Sheet {
}
}
#[derive(Default)]
pub struct Args {
ids: bool,
start: Option<DateTime<Utc>>,
@ -96,3 +97,41 @@ impl<'a> Command<'a> for DisplayCommand {
)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::database::SqliteDatabase;
use crate::test_utils::PrettyString;
#[test]
fn display_as_local_time_if_previous_version() {
let args = Default::default();
let mut db = SqliteDatabase::from_path("assets/test_old_db.db").unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
let config = Default::default();
DisplayCommand::handle(args, &mut db, &mut out, &mut err, &config).unwrap();
assert_eq!(PrettyString(&String::from_utf8_lossy(&out)), PrettyString("Timesheet: default
Day Start End Duration Notes
Tue Jun 29, 2021 06:26:49 - 07:26:52 1:00:03 lets do some rust
1:00:03
---------------------------------------------------------------------
Total 1:00:03
"));
assert_eq!(
PrettyString(&String::from_utf8_lossy(&err)),
PrettyString("[WARNING] You are using the old timetrap format, it is advised that you update your database using t migrate")
);
}
#[test]
fn correctly_use_utc_if_new_version() {
assert!(false, "start with a newly created database");
assert!(false, "correctly display times in local timezone");
}
}

View File

@ -57,6 +57,12 @@ pub enum Formatter {
Custom(String),
}
impl Default for Formatter {
fn default() -> Formatter {
Formatter::Text
}
}
impl Formatter {
/// Prints the given entries to the specified output device.
///