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); + } +}