Skip to content

feat: add equals() to Price and Uuid Value Objects#48

Merged
jorge07 merged 1 commit intojorge07:masterfrom
josecarlospeer-cloud:feat/value-object-equals
Feb 22, 2026
Merged

feat: add equals() to Price and Uuid Value Objects#48
jorge07 merged 1 commit intojorge07:masterfrom
josecarlospeer-cloud:feat/value-object-equals

Conversation

@josecarlospeer-cloud
Copy link
Contributor

Problem

Value Objects had no equals() method. Comparing two instances representing the same value with === always returns false (reference equality), making it impossible to express domain equality checks correctly.

const a = new Price("10.00", "EUR");
const b = new Price("10.00", "EUR");
a === b  // false — misleading and dangerous

Source: Evans (Blue Book), p. 98 — "Value objects should be testable for equality. [...] Use the fields of the object to determine equality."

Fix

  • Price.equals(other: Price): boolean — compares amount and currency
  • Uuid.equals(other: Uuid): boolean — compares string representations; TransactionId inherits this via extension

Tests

  • Price.test.ts — added equals() coverage (same, different amount, different currency) plus missing rejection tests (negative amount, non-numeric amount)
  • TransactionId.test.ts — new file; covers same/different UUID equality, auto-generated uniqueness, and invalid UUID rejection

All 23 tests pass.

D2.2 from Phase 2 roadmap.

Violation: Price and Uuid-based identities had no equals() method.
Reference equality (===) is always false for two separate instances
representing the same value.

Source: Evans (Blue Book), p. 98 — "Value objects should be testable
for equality. [...] Use the fields of the object to determine equality."

Fix:
- Price.equals(other: Price): compares amount and currency
- Uuid.equals(other: Uuid): compares toString() values
  (TransactionId inherits this via extension)

Tests: added equals() coverage to Price.test.ts and new
TransactionId.test.ts (also adds negative amount, non-numeric amount
rejection tests for completeness)
@jorge07 jorge07 merged commit 42d6ae2 into jorge07:master Feb 22, 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.

2 participants