forked from janek/mostr
1
0
Fork 0

test(task): verify state progression

This commit is contained in:
xeruf 2024-11-14 18:29:47 +01:00
parent d095c65b23
commit ecc5b7686b
1 changed files with 31 additions and 0 deletions

View File

@ -343,3 +343,34 @@ impl Display for State {
fmt::Debug::fmt(self, f) 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);
}
}