Skip to content

Commit 82473ee

Browse files
authored
refactor: remove pace_testing crate and migrate it to integration test (#108)
Signed-off-by: simonsan <[email protected]>
1 parent 4599bae commit 82473ee

File tree

19 files changed

+152
-213
lines changed

19 files changed

+152
-213
lines changed

Cargo.lock

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ members = [
33
"crates/cli",
44
"crates/core",
55
"crates/server",
6-
"crates/testing",
76
"crates/time",
87
]
98

@@ -45,7 +44,6 @@ once_cell = "1.19.0"
4544
open = "5.1.2"
4645
pace_cli = { path = "crates/cli", version = "0" }
4746
pace_core = { path = "crates/core", version = "0" }
48-
pace_testing = { path = "crates/testing", version = "0" }
4947
pace_time = { path = "crates/time", version = "0" }
5048
parking_lot = "0.12.1"
5149
predicates = "3.1.0"

crates/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ wildmatch = { workspace = true }
6262
[dev-dependencies]
6363
eyre = { workspace = true }
6464
insta = { workspace = true, features = ["toml", "redactions"] }
65-
pace_testing = { workspace = true }
6665
rstest = { workspace = true }
6766
similar-asserts = { workspace = true, features = ["serde"] }
6867
simplelog = { workspace = true }

crates/core/src/domain/activity.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use typed_builder::TypedBuilder;
1616
use ulid::Ulid;
1717

1818
use crate::{
19-
domain::status::ActivityStatus,
19+
domain::status::ActivityStatusKind,
2020
error::{ActivityLogErrorKind, PaceResult},
2121
};
2222

@@ -246,7 +246,7 @@ pub struct Activity {
246246
#[serde(default)]
247247
#[builder(default)]
248248
#[merge(strategy = crate::util::overwrite_left_with_right)]
249-
status: ActivityStatus,
249+
status: ActivityStatusKind,
250250
}
251251

252252
#[derive(
@@ -357,40 +357,40 @@ impl Activity {
357357
}
358358

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

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

376376
/// Make the activity active
377377
pub fn make_active(&mut self) {
378378
debug!("Making activity active: {:?}", self);
379-
self.status = ActivityStatus::Active;
379+
self.status = ActivityStatusKind::InProgress;
380380
}
381381

382382
/// Make the activity inactive
383383
pub fn make_inactive(&mut self) {
384384
debug!("Making activity inactive: {:?}", self);
385-
self.status = ActivityStatus::Inactive;
385+
self.status = ActivityStatusKind::Created;
386386
}
387387

388388
/// Archive the activity
389389
/// This is only possible if the activity is not active and has ended
390390
pub fn archive(&mut self) {
391-
if !self.is_active() && self.has_ended() {
391+
if !self.is_in_progress() && self.is_completed() {
392392
debug!("Archiving activity: {:?}", self);
393-
self.status = ActivityStatus::Archived;
393+
self.status = ActivityStatusKind::Archived;
394394
}
395395
}
396396

@@ -399,14 +399,14 @@ impl Activity {
399399
pub fn unarchive(&mut self) {
400400
if self.is_archived() {
401401
debug!("Unarchiving activity: {:?}", self);
402-
self.status = ActivityStatus::Unarchived;
402+
self.status = ActivityStatusKind::Unarchived;
403403
}
404404
}
405405

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

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

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

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

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

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

464464
/// End the activity with a given end date and time

crates/core/src/domain/status.rs

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,79 @@ pub enum TaskStatus {
1818

1919
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
2020
#[serde(rename_all = "kebab-case")]
21-
pub enum ActivityStatus {
22-
Active,
23-
Archived,
24-
Ended,
21+
pub enum ActivityStatusKind {
22+
/// The initial state of an activity once it's created in the system but not yet started.
2523
#[default]
26-
Inactive,
27-
Held,
24+
Created,
25+
26+
/// The activity is scheduled to start at a specific time.
27+
/// It remains in this state until the activity begins.
28+
Scheduled,
29+
30+
/// The active state of an activity. It transitions to this state from "Scheduled" when
31+
/// the activity begins or from "Paused" when it's resumed. The start time is recorded
32+
/// upon entering this state for the first time, and the resume time is noted for
33+
/// subsequent entries.
34+
InProgress,
35+
36+
/// Represents an activity that has been temporarily halted.
37+
/// This could apply to tasks being paused for a break or intermission.
38+
/// The activity can move back to "InProgress" when work on it resumes.
39+
Paused,
40+
41+
/// The final state of an activity, indicating it has been finished.
42+
/// The end time of the activity is recorded, marking its completion.
43+
Completed,
44+
45+
Archived,
2846
Unarchived, // TODO: Do we need this or can be unarchiving done without it?
2947
}
3048

3149
#[allow(clippy::trivially_copy_pass_by_ref)]
32-
impl ActivityStatus {
33-
/// Returns `true` if the activity status is [`Active`].
50+
impl ActivityStatusKind {
51+
/// Returns `true` if the activity status is [`InProgress`].
3452
///
35-
/// [`Active`]: ActivityStatus::Active
53+
/// [`InProgress`]: ActivityStatusKind::InProgress
3654
#[must_use]
37-
pub const fn is_active(self) -> bool {
38-
matches!(self, Self::Active)
55+
pub const fn is_in_progress(self) -> bool {
56+
matches!(self, Self::InProgress)
3957
}
4058

4159
/// Returns `true` if the activity status is [`Archived`].
4260
///
43-
/// [`Archived`]: ActivityStatus::Archived
61+
/// [`Archived`]: ActivityStatusKind::Archived
4462
#[must_use]
4563
pub const fn is_archived(self) -> bool {
4664
matches!(self, Self::Archived)
4765
}
4866

49-
/// Returns `true` if the activity status is [`Ended`].
67+
/// Returns `true` if the activity status is [`Completed`].
5068
///
51-
/// [`Ended`]: ActivityStatus::Ended
69+
/// [`Completed`]: ActivityStatusKind::Completed
5270
#[must_use]
53-
pub const fn is_ended(self) -> bool {
54-
matches!(self, Self::Ended)
71+
pub const fn is_completed(self) -> bool {
72+
matches!(self, Self::Completed)
5573
}
5674

57-
/// Returns `true` if the activity status is [`Inactive`].
75+
/// Returns `true` if the activity status is [`Created`].
5876
///
59-
/// [`Inactive`]: ActivityStatus::Inactive
77+
/// [`Created`]: ActivityStatusKind::Created
6078
#[must_use]
61-
pub const fn is_inactive(self) -> bool {
62-
matches!(self, Self::Inactive)
79+
pub const fn is_created(self) -> bool {
80+
matches!(self, Self::Created)
6381
}
6482

65-
/// Returns `true` if the activity status is [`Held`].
83+
/// Returns `true` if the activity status is [`Paused`].
6684
///
67-
/// [`Held`]: ActivityStatus::Held
85+
/// [`Paused`]: ActivityStatusKind::Paused
6886
#[must_use]
69-
pub const fn is_held(self) -> bool {
70-
matches!(self, Self::Held)
87+
pub const fn is_paused(self) -> bool {
88+
matches!(self, Self::Paused)
7189
}
7290

7391
/// Returns `true` if the activity status is [`Unarchived`].
7492
///
75-
/// [`Unarchived`]: ActivityStatus::Unarchived
93+
/// [`Unarchived`]: ActivityStatusKind::Unarchived
7694
#[must_use]
7795
pub const fn is_unarchived(&self) -> bool {
7896
matches!(self, Self::Unarchived)

crates/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub mod prelude {
5959
Highlights, ReflectionSummary, ReflectionsFormatKind, SummaryActivityGroup,
6060
SummaryCategories, SummaryGroupByCategory,
6161
},
62-
status::ActivityStatus,
62+
status::ActivityStatusKind,
6363
},
6464
error::{PaceError, PaceErrorKind, PaceOptResult, PaceResult, TestResult, UserMessage},
6565
service::{activity_store::ActivityStore, activity_tracker::ActivityTracker},

crates/core/src/service/activity_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
category,
2323
filter::{ActivityFilterKind, FilterOptions, FilteredActivities},
2424
reflection::{SummaryActivityGroup, SummaryGroupByCategory},
25-
status::ActivityStatus,
25+
status::ActivityStatusKind,
2626
},
2727
error::{ActivityStoreErrorKind, PaceOptResult, PaceResult},
2828
storage::{
@@ -380,7 +380,7 @@ impl ActivityQuerying for ActivityStore {
380380
#[tracing::instrument(skip(self))]
381381
fn group_activities_by_status(
382382
&self,
383-
) -> PaceOptResult<BTreeMap<ActivityStatus, Vec<ActivityItem>>> {
383+
) -> PaceOptResult<BTreeMap<ActivityStatusKind, Vec<ActivityItem>>> {
384384
self.storage.group_activities_by_status()
385385
}
386386
}

crates/core/src/storage.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
domain::{
1515
activity::{Activity, ActivityGuid, ActivityItem, ActivityKind},
1616
filter::{ActivityFilterKind, FilteredActivities},
17-
status::ActivityStatus,
17+
status::ActivityStatusKind,
1818
},
1919
error::{PaceErrorKind, PaceOptResult, PaceResult},
2020
service::activity_store::ActivityStore,
@@ -544,7 +544,7 @@ pub trait ActivityQuerying: ActivityReadOps {
544544
/// If no activities are found, it should return `Ok(None)`.
545545
fn group_activities_by_status(
546546
&self,
547-
) -> PaceOptResult<BTreeMap<ActivityStatus, Vec<ActivityItem>>>;
547+
) -> PaceOptResult<BTreeMap<ActivityStatusKind, Vec<ActivityItem>>>;
548548

549549
/// List all current activities from the storage backend matching an `ActivityFilter`.
550550
///
@@ -659,14 +659,14 @@ pub trait ActivityQuerying: ActivityReadOps {
659659
debug!(
660660
"Checking if Activity with id {:?} is active: {}",
661661
activity_id,
662-
if activity.activity().is_active() {
662+
if activity.activity().is_in_progress() {
663663
"yes"
664664
} else {
665665
"no"
666666
}
667667
);
668668

669-
Ok(activity.activity().is_active())
669+
Ok(activity.activity().is_in_progress())
670670
}
671671

672672
/// List all intermissions for an activity id from the storage backend.
@@ -794,7 +794,7 @@ pub trait ActivityQuerying: ActivityReadOps {
794794
.find(|activity_id| {
795795
self.read_activity(*activity_id)
796796
.map(|activity| {
797-
activity.activity().is_active()
797+
activity.activity().is_in_progress()
798798
&& activity.activity().kind().is_activity()
799799
&& !activity.activity().is_active_intermission()
800800
})
@@ -829,7 +829,7 @@ pub trait ActivityQuerying: ActivityReadOps {
829829
.find(|activity_id| {
830830
self.read_activity(*activity_id)
831831
.map(|activity| {
832-
activity.activity().is_held()
832+
activity.activity().is_paused()
833833
&& activity.activity().kind().is_activity()
834834
&& !activity.activity().is_active_intermission()
835835
})

crates/core/src/storage/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
activity::{Activity, ActivityGuid, ActivityItem, ActivityKind},
1717
activity_log::ActivityLog,
1818
filter::{ActivityFilterKind, FilteredActivities},
19-
status::ActivityStatus,
19+
status::ActivityStatusKind,
2020
},
2121
error::{PaceErrorKind, PaceOptResult, PaceResult},
2222
storage::{
@@ -285,7 +285,7 @@ impl ActivityQuerying for TomlActivityStorage {
285285
#[tracing::instrument(skip(self))]
286286
fn group_activities_by_status(
287287
&self,
288-
) -> PaceOptResult<BTreeMap<ActivityStatus, Vec<ActivityItem>>> {
288+
) -> PaceOptResult<BTreeMap<ActivityStatusKind, Vec<ActivityItem>>> {
289289
self.cache.group_activities_by_status()
290290
}
291291
}

0 commit comments

Comments
 (0)