forked from janek/mostr
test(task): verify state progression
This commit is contained in:
parent
d095c65b23
commit
ecc5b7686b
31
src/task.rs
31
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue