complish 0.0.1

Core library for project-aware task management with git integration
Documentation
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct TaskNote {
  pub created_at: DateTime<Utc>,
  pub content: String,
  pub updated_at: DateTime<Utc>,
}

impl TaskNote {
  pub fn new(content: impl Into<String>) -> Self {
    let now = Utc::now();

    Self {
      created_at: now,
      content: content.into(),
      updated_at: now,
    }
  }

  pub fn edit_note(&mut self, content: impl Into<String>) {
    self.content = content.into();
    self.touch();
  }

  pub fn touch(&mut self) {
    self.updated_at = Utc::now();
  }
}

#[cfg(test)]
mod tests {
  use super::*;

  mod new {
    use pretty_assertions::assert_eq;

    use super::*;

    #[test]
    fn it_creates_a_new_task_note() {
      let note = TaskNote::new("a test note");

      assert_eq!(note.content, "a test note");
      assert!(note.created_at.timestamp() > 0);
      assert!(note.updated_at.timestamp() > 0);
    }
  }

  mod edit_note {
    use pretty_assertions::assert_eq;

    use super::*;

    #[test]
    fn it_edits_the_note() {
      let mut note = TaskNote::new("a test note");
      note.edit_note("an edited test note");

      assert_eq!(note.content, "an edited test note");
    }
  }

  mod touch {
    use pretty_assertions::assert_ne;

    use super::*;

    #[test]
    fn it_updates_the_lists_updated_at_timestamp() {
      let mut note = TaskNote::new("a test note");
      let old_updated_at = note.updated_at;

      note.updated_at = old_updated_at - chrono::Duration::seconds(1);
      let very_old_time = note.updated_at;

      note.touch();

      assert_ne!(note.updated_at, very_old_time);
      assert!(note.updated_at > very_old_time);
    }
  }
}