Skip to content

Commit

Permalink
refactor: remove pace_testing crate and migrate it to integration test (
Browse files Browse the repository at this point in the history
#108)

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan authored Mar 24, 2024
1 parent 4599bae commit 82473ee
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 213 deletions.
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ members = [
"crates/cli",
"crates/core",
"crates/server",
"crates/testing",
"crates/time",
]

Expand Down Expand Up @@ -45,7 +44,6 @@ once_cell = "1.19.0"
open = "5.1.2"
pace_cli = { path = "crates/cli", version = "0" }
pace_core = { path = "crates/core", version = "0" }
pace_testing = { path = "crates/testing", version = "0" }
pace_time = { path = "crates/time", version = "0" }
parking_lot = "0.12.1"
predicates = "3.1.0"
Expand Down
1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ wildmatch = { workspace = true }
[dev-dependencies]
eyre = { workspace = true }
insta = { workspace = true, features = ["toml", "redactions"] }
pace_testing = { workspace = true }
rstest = { workspace = true }
similar-asserts = { workspace = true, features = ["serde"] }
simplelog = { workspace = true }
Expand Down
38 changes: 19 additions & 19 deletions crates/core/src/domain/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use typed_builder::TypedBuilder;
use ulid::Ulid;

use crate::{
domain::status::ActivityStatus,
domain::status::ActivityStatusKind,
error::{ActivityLogErrorKind, PaceResult},
};

Expand Down Expand Up @@ -246,7 +246,7 @@ pub struct Activity {
#[serde(default)]
#[builder(default)]
#[merge(strategy = crate::util::overwrite_left_with_right)]
status: ActivityStatus,
status: ActivityStatusKind,
}

#[derive(
Expand Down Expand Up @@ -357,40 +357,40 @@ impl Activity {
}

/// If the activity is held
pub fn is_held(&self) -> bool {
pub fn is_paused(&self) -> bool {
debug!("Checking if activity is held: {:?}", self);
self.status.is_held()
self.status.is_paused()
}

/// If the activity is active, so if it is currently being tracked
/// Intermissions are not considered active activities, please use
/// [`is_active_intermission`] for that
#[must_use]
pub fn is_active(&self) -> bool {
pub fn is_in_progress(&self) -> bool {
debug!("Checking if activity is active: {:?}", self);
self.activity_end_options().is_none()
&& (!self.kind.is_intermission() || !self.kind.is_pomodoro_intermission())
&& self.status.is_active()
&& self.status.is_in_progress()
}

/// Make the activity active
pub fn make_active(&mut self) {
debug!("Making activity active: {:?}", self);
self.status = ActivityStatus::Active;
self.status = ActivityStatusKind::InProgress;
}

/// Make the activity inactive
pub fn make_inactive(&mut self) {
debug!("Making activity inactive: {:?}", self);
self.status = ActivityStatus::Inactive;
self.status = ActivityStatusKind::Created;
}

/// Archive the activity
/// This is only possible if the activity is not active and has ended
pub fn archive(&mut self) {
if !self.is_active() && self.has_ended() {
if !self.is_in_progress() && self.is_completed() {
debug!("Archiving activity: {:?}", self);
self.status = ActivityStatus::Archived;
self.status = ActivityStatusKind::Archived;
}
}

Expand All @@ -399,14 +399,14 @@ impl Activity {
pub fn unarchive(&mut self) {
if self.is_archived() {
debug!("Unarchiving activity: {:?}", self);
self.status = ActivityStatus::Unarchived;
self.status = ActivityStatusKind::Unarchived;
}
}

/// If the activity is endable, meaning if it is active or held
pub fn is_endable(&self) -> bool {
pub fn is_completable(&self) -> bool {
debug!("Checking if activity is endable: {:?}", self);
self.is_active() || self.is_held()
self.is_in_progress() || self.is_paused()
}

/// If the activity is an active intermission
Expand All @@ -415,7 +415,7 @@ impl Activity {
debug!("Checking if activity is an active intermission: {:?}", self);
self.activity_end_options().is_none()
&& (self.kind.is_intermission() || self.kind.is_pomodoro_intermission())
&& self.status.is_active()
&& self.status.is_in_progress()
}

/// If the activity is archived
Expand All @@ -429,24 +429,24 @@ impl Activity {
#[must_use]
pub fn is_inactive(&self) -> bool {
debug!("Checking if activity is inactive: {:?}", self);
self.status.is_inactive()
self.status.is_created()
}

/// If the activity has ended and is not archived
#[must_use]
pub fn has_ended(&self) -> bool {
pub fn is_completed(&self) -> bool {
debug!("Checking if activity has ended: {:?}", self);
self.activity_end_options().is_some()
&& (!self.kind.is_intermission() || !self.kind.is_pomodoro_intermission())
&& !self.is_archived()
&& self.status.is_ended()
&& self.status.is_completed()
}

/// If the activity is resumable
#[must_use]
pub fn is_resumable(&self) -> bool {
debug!("Checking if activity is resumable: {:?}", self);
self.is_inactive() || self.is_archived() || self.is_held() || self.has_ended()
self.is_inactive() || self.is_archived() || self.is_paused() || self.is_completed()
}

/// End the activity
Expand All @@ -458,7 +458,7 @@ impl Activity {
pub fn end_activity(&mut self, end_opts: ActivityEndOptions) {
debug!("Ending activity: {:?}", self);
self.activity_end_options = Some(end_opts);
self.status = ActivityStatus::Ended;
self.status = ActivityStatusKind::Completed;
}

/// End the activity with a given end date and time
Expand Down
68 changes: 43 additions & 25 deletions crates/core/src/domain/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,61 +18,79 @@ pub enum TaskStatus {

#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "kebab-case")]
pub enum ActivityStatus {
Active,
Archived,
Ended,
pub enum ActivityStatusKind {
/// The initial state of an activity once it's created in the system but not yet started.
#[default]
Inactive,
Held,
Created,

/// The activity is scheduled to start at a specific time.
/// It remains in this state until the activity begins.
Scheduled,

/// The active state of an activity. It transitions to this state from "Scheduled" when
/// the activity begins or from "Paused" when it's resumed. The start time is recorded
/// upon entering this state for the first time, and the resume time is noted for
/// subsequent entries.
InProgress,

/// Represents an activity that has been temporarily halted.
/// This could apply to tasks being paused for a break or intermission.
/// The activity can move back to "InProgress" when work on it resumes.
Paused,

/// The final state of an activity, indicating it has been finished.
/// The end time of the activity is recorded, marking its completion.
Completed,

Archived,
Unarchived, // TODO: Do we need this or can be unarchiving done without it?
}

#[allow(clippy::trivially_copy_pass_by_ref)]
impl ActivityStatus {
/// Returns `true` if the activity status is [`Active`].
impl ActivityStatusKind {
/// Returns `true` if the activity status is [`InProgress`].
///
/// [`Active`]: ActivityStatus::Active
/// [`InProgress`]: ActivityStatusKind::InProgress
#[must_use]
pub const fn is_active(self) -> bool {
matches!(self, Self::Active)
pub const fn is_in_progress(self) -> bool {
matches!(self, Self::InProgress)
}

/// Returns `true` if the activity status is [`Archived`].
///
/// [`Archived`]: ActivityStatus::Archived
/// [`Archived`]: ActivityStatusKind::Archived
#[must_use]
pub const fn is_archived(self) -> bool {
matches!(self, Self::Archived)
}

/// Returns `true` if the activity status is [`Ended`].
/// Returns `true` if the activity status is [`Completed`].
///
/// [`Ended`]: ActivityStatus::Ended
/// [`Completed`]: ActivityStatusKind::Completed
#[must_use]
pub const fn is_ended(self) -> bool {
matches!(self, Self::Ended)
pub const fn is_completed(self) -> bool {
matches!(self, Self::Completed)
}

/// Returns `true` if the activity status is [`Inactive`].
/// Returns `true` if the activity status is [`Created`].
///
/// [`Inactive`]: ActivityStatus::Inactive
/// [`Created`]: ActivityStatusKind::Created
#[must_use]
pub const fn is_inactive(self) -> bool {
matches!(self, Self::Inactive)
pub const fn is_created(self) -> bool {
matches!(self, Self::Created)
}

/// Returns `true` if the activity status is [`Held`].
/// Returns `true` if the activity status is [`Paused`].
///
/// [`Held`]: ActivityStatus::Held
/// [`Paused`]: ActivityStatusKind::Paused
#[must_use]
pub const fn is_held(self) -> bool {
matches!(self, Self::Held)
pub const fn is_paused(self) -> bool {
matches!(self, Self::Paused)
}

/// Returns `true` if the activity status is [`Unarchived`].
///
/// [`Unarchived`]: ActivityStatus::Unarchived
/// [`Unarchived`]: ActivityStatusKind::Unarchived
#[must_use]
pub const fn is_unarchived(&self) -> bool {
matches!(self, Self::Unarchived)
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub mod prelude {
Highlights, ReflectionSummary, ReflectionsFormatKind, SummaryActivityGroup,
SummaryCategories, SummaryGroupByCategory,
},
status::ActivityStatus,
status::ActivityStatusKind,
},
error::{PaceError, PaceErrorKind, PaceOptResult, PaceResult, TestResult, UserMessage},
service::{activity_store::ActivityStore, activity_tracker::ActivityTracker},
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/service/activity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
category,
filter::{ActivityFilterKind, FilterOptions, FilteredActivities},
reflection::{SummaryActivityGroup, SummaryGroupByCategory},
status::ActivityStatus,
status::ActivityStatusKind,
},
error::{ActivityStoreErrorKind, PaceOptResult, PaceResult},
storage::{
Expand Down Expand Up @@ -380,7 +380,7 @@ impl ActivityQuerying for ActivityStore {
#[tracing::instrument(skip(self))]
fn group_activities_by_status(
&self,
) -> PaceOptResult<BTreeMap<ActivityStatus, Vec<ActivityItem>>> {
) -> PaceOptResult<BTreeMap<ActivityStatusKind, Vec<ActivityItem>>> {
self.storage.group_activities_by_status()
}
}
12 changes: 6 additions & 6 deletions crates/core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
domain::{
activity::{Activity, ActivityGuid, ActivityItem, ActivityKind},
filter::{ActivityFilterKind, FilteredActivities},
status::ActivityStatus,
status::ActivityStatusKind,
},
error::{PaceErrorKind, PaceOptResult, PaceResult},
service::activity_store::ActivityStore,
Expand Down Expand Up @@ -544,7 +544,7 @@ pub trait ActivityQuerying: ActivityReadOps {
/// If no activities are found, it should return `Ok(None)`.
fn group_activities_by_status(
&self,
) -> PaceOptResult<BTreeMap<ActivityStatus, Vec<ActivityItem>>>;
) -> PaceOptResult<BTreeMap<ActivityStatusKind, Vec<ActivityItem>>>;

/// List all current activities from the storage backend matching an `ActivityFilter`.
///
Expand Down Expand Up @@ -659,14 +659,14 @@ pub trait ActivityQuerying: ActivityReadOps {
debug!(
"Checking if Activity with id {:?} is active: {}",
activity_id,
if activity.activity().is_active() {
if activity.activity().is_in_progress() {
"yes"
} else {
"no"
}
);

Ok(activity.activity().is_active())
Ok(activity.activity().is_in_progress())
}

/// List all intermissions for an activity id from the storage backend.
Expand Down Expand Up @@ -794,7 +794,7 @@ pub trait ActivityQuerying: ActivityReadOps {
.find(|activity_id| {
self.read_activity(*activity_id)
.map(|activity| {
activity.activity().is_active()
activity.activity().is_in_progress()
&& activity.activity().kind().is_activity()
&& !activity.activity().is_active_intermission()
})
Expand Down Expand Up @@ -829,7 +829,7 @@ pub trait ActivityQuerying: ActivityReadOps {
.find(|activity_id| {
self.read_activity(*activity_id)
.map(|activity| {
activity.activity().is_held()
activity.activity().is_paused()
&& activity.activity().kind().is_activity()
&& !activity.activity().is_active_intermission()
})
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/storage/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
activity::{Activity, ActivityGuid, ActivityItem, ActivityKind},
activity_log::ActivityLog,
filter::{ActivityFilterKind, FilteredActivities},
status::ActivityStatus,
status::ActivityStatusKind,
},
error::{PaceErrorKind, PaceOptResult, PaceResult},
storage::{
Expand Down Expand Up @@ -285,7 +285,7 @@ impl ActivityQuerying for TomlActivityStorage {
#[tracing::instrument(skip(self))]
fn group_activities_by_status(
&self,
) -> PaceOptResult<BTreeMap<ActivityStatus, Vec<ActivityItem>>> {
) -> PaceOptResult<BTreeMap<ActivityStatusKind, Vec<ActivityItem>>> {
self.cache.group_activities_by_status()
}
}
Loading

0 comments on commit 82473ee

Please sign in to comment.