Skip to content

feat: implement Adoption Lifecycle State Machine (Issue #59)#109

Merged
amina69 merged 1 commit into
amina69:mainfrom
NickiM84:feat/adoption-lifecycle-state-machine
May 30, 2026
Merged

feat: implement Adoption Lifecycle State Machine (Issue #59)#109
amina69 merged 1 commit into
amina69:mainfrom
NickiM84:feat/adoption-lifecycle-state-machine

Conversation

@NickiM84

Copy link
Copy Markdown
Contributor

Summary

Implements the Adoption Lifecycle State Machine as specified in Issue #59. This enforces strict domain integrity by controlling valid Adoption.status transitions and preventing invalid lifecycle mutations.

Changes

New Files

  • src/common/exceptions/domain.exception.ts - DomainException (HTTP 422) for invalid domain transitions
  • src/adoption/services/adoption-state-machine.service.ts - State machine service with explicit transition map
  • src/adoption/services/adoption-state-machine.service.spec.ts - Comprehensive unit tests for all transitions

Modified Files

  • src/adoption/adoption.service.ts - Enforce state machine before every status update
  • src/adoption/adoption.service.spec.ts - Add state machine mock and test for blocked invalid transitions
  • src/adoption/adoption.module.ts - Register and export AdoptionStateMachine
  • src/escrow/escrow.service.ts - Enforce adoption must be ESCROW_FUNDED before releasing escrow
  • src/escrow/escrow.service.spec.ts - Add state machine mock
  • src/escrow/escrow.module.ts - Import AdoptionModule for AdoptionStateMachine access

Valid Transitions

REQUESTED -> PENDING, REJECTED
PENDING -> APPROVED, REJECTED
APPROVED -> ESCROW_FUNDED, CANCELLED
ESCROW_FUNDED -> COMPLETED, CANCELLED
COMPLETED -> (terminal)
REJECTED -> (terminal)
CANCELLED -> (terminal)

Testing

  • 51 tests pass across 4 test suites
  • State machine tested for all valid transitions
  • State machine tested for all invalid transitions (backwards, self, terminal)
  • Integration verified in both AdoptionService and EscrowService

Closes #59

- Create AdoptionStateMachine service with explicit transition map

- Create DomainException for invalid domain transitions

- Enforce state machine in AdoptionService.updateAdoptionStatus

- Enforce state machine in EscrowService.releaseEscrow

- Add comprehensive unit tests covering all valid/invalid transitions

- Update module imports to wire all dependencies
@drips-wave

drips-wave Bot commented May 30, 2026

Copy link
Copy Markdown

@middalukawunti-lang Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@amina69 amina69 merged commit 58844aa into amina69:main May 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adoption Lifecycle State Machine

2 participants