ChallengeHub Activity Tracker
I rebuilt the Record Activity feature of a wellness challenge app so bad input is rejected before anything is saved, and a failed save can no longer corrupt data. All 18 tests pass.
The problem
Participants log activities such as kilometers walked or sessions attended, and progress is worked out from those records. Progress affects how people are judged, so a bad record or a half-written file would make the results wrong.
What I built
- Checks before any record exists. Six rules run in order and stop at the first failure.
- The Strategy pattern for progress. A policy picked by activity type adds up amounts or counts records, and a new type only needs a new policy.
- Atomic saves. Data is written to a temporary file and then swapped in, so an interrupted write leaves the original file unchanged.
- A fix for save order. The record is saved first and added to memory only afterwards, so a failed save leaves the app state unchanged.
The six rules
| Check | Message when it fails |
|---|---|
| Participant exists | Unknown participant |
| Challenge exists | Unknown challenge |
| Participant joined the challenge | Participant is not enrolled |
| Amount above zero | Amount must be positive |
| Activity type matches the challenge | Activity type does not match challenge |
| Date is inside the challenge period | Activity date is outside the challenge period |
Testing
The 18 tests cover the original behavior, each of eight invalid requests, one valid request, a storage failure, an interrupted file write, and a check that the core code does not import storage or display modules. In my demo, an invalid amount of 0 changed nothing, with data files byte-for-byte identical.
Limits I documented
An activity dated before the participant joined is still accepted, because that rule was never decided. There is also no sign-in, so records cannot be tied to the person who submitted them.