Maintain unrecognized statuses

This commit is contained in:
Dustin J. Mitchell
2021-12-24 16:05:33 +00:00
parent 6a1d1a8c3c
commit 9965d10736

View File

@@ -1,9 +1,14 @@
/// The status of a task. The default status in "Pending". /// The status of a task, as defined by the task data model.
#[derive(Debug, PartialEq, Clone, strum_macros::Display)] #[derive(Debug, PartialEq, Clone, strum_macros::Display)]
pub enum Status { pub enum Status {
Pending, Pending,
Completed, Completed,
Deleted, Deleted,
/// Unknown signifies a status in the task DB that was not
/// recognized. This supports forward-compatibility if a
/// new status is added. Tasks with unknown status should
/// be ignored (but not deleted).
Unknown(String),
} }
impl Status { impl Status {
@@ -14,7 +19,7 @@ impl Status {
"pending" => Status::Pending, "pending" => Status::Pending,
"completed" => Status::Completed, "completed" => Status::Completed,
"deleted" => Status::Deleted, "deleted" => Status::Deleted,
_ => Status::Pending, v => Status::Unknown(v.to_string()),
} }
} }
@@ -24,6 +29,7 @@ impl Status {
Status::Pending => "pending", Status::Pending => "pending",
Status::Completed => "completed", Status::Completed => "completed",
Status::Deleted => "deleted", Status::Deleted => "deleted",
Status::Unknown(v) => v.as_ref(),
} }
} }
} }
@@ -38,6 +44,7 @@ mod test {
assert_eq!(Status::Pending.to_taskmap(), "pending"); assert_eq!(Status::Pending.to_taskmap(), "pending");
assert_eq!(Status::Completed.to_taskmap(), "completed"); assert_eq!(Status::Completed.to_taskmap(), "completed");
assert_eq!(Status::Deleted.to_taskmap(), "deleted"); assert_eq!(Status::Deleted.to_taskmap(), "deleted");
assert_eq!(Status::Unknown("wishful".into()).to_taskmap(), "wishful");
} }
#[test] #[test]
@@ -45,7 +52,10 @@ mod test {
assert_eq!(Status::from_taskmap("pending"), Status::Pending); assert_eq!(Status::from_taskmap("pending"), Status::Pending);
assert_eq!(Status::from_taskmap("completed"), Status::Completed); assert_eq!(Status::from_taskmap("completed"), Status::Completed);
assert_eq!(Status::from_taskmap("deleted"), Status::Deleted); assert_eq!(Status::from_taskmap("deleted"), Status::Deleted);
assert_eq!(Status::from_taskmap("something-else"), Status::Pending); assert_eq!(
Status::from_taskmap("something-else"),
Status::Unknown("something-else".into())
);
} }
#[test] #[test]
@@ -53,5 +63,6 @@ mod test {
assert_eq!(format!("{}", Status::Pending), "Pending"); assert_eq!(format!("{}", Status::Pending), "Pending");
assert_eq!(format!("{}", Status::Completed), "Completed"); assert_eq!(format!("{}", Status::Completed), "Completed");
assert_eq!(format!("{}", Status::Deleted), "Deleted"); assert_eq!(format!("{}", Status::Deleted), "Deleted");
assert_eq!(format!("{}", Status::Unknown("wishful".into())), "Unknown");
} }
} }