From ecc5b7686b172d8785f138fcc4bc9168e425142f Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 14 Nov 2024 18:29:47 +0100 Subject: [PATCH] test(task): verify state progression --- src/task.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/task.rs b/src/task.rs index 8dfcaa3..a21b5aa 100644 --- a/src/task.rs +++ b/src/task.rs @@ -343,3 +343,34 @@ impl Display for State { fmt::Debug::fmt(self, f) } } + +#[cfg(test)] +mod tasks_test { + use super::*; + use nostr_sdk::{EventBuilder, Keys}; + + #[test] + fn test_state() { + let keys = Keys::generate(); + let mut task = Task::new( + EventBuilder::new(TASK_KIND, "task", [Tag::hashtag("tag1")]) + .to_event(&keys).unwrap()); + assert_eq!(task.pure_state(), State::Open); + assert_eq!(task.get_hashtags().count(), 1); + task.props.insert( + EventBuilder::new(State::Done.into(), "", []) + .to_event(&keys).unwrap()); + assert_eq!(task.pure_state(), State::Done); + task.props.insert( + EventBuilder::new(State::Open.into(), "", [Tag::hashtag("tag2")]) + .custom_created_at(Timestamp::from(Timestamp::now() - 2)) + .to_event(&keys).unwrap()); + assert_eq!(task.pure_state(), State::Done); + assert_eq!(task.get_hashtags().count(), 2); + task.props.insert( + EventBuilder::new(State::Closed.into(), "", []) + .custom_created_at(Timestamp::from(Timestamp::now() + 1)) + .to_event(&keys).unwrap()); + assert_eq!(task.pure_state(), State::Closed); + } +}