Refactoring & Testing (TBD)
summary
A hands-on TypeScript refactor replaces a hardcoded "@mojopi.com" string with a MojopiEmail value object, renames a boolean validate function to isValid and changes execute into a query-like method. The code is updated to use dependency injection so the domain validator is reused instead of being new-ed per call; IDE refactors (inline, introduce parameter, reorder) are applied. Tests are rewritten to avoid brittle boolean expectations—switching to a factory-throw semantics test—and validation stops using exceptions for normal domain rejection.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:04TypeScript code smells
- 3:00Identifying code issues
- 5:09Naming conventions
- 8:33Dependency injection testing
- 10:02Primitive obsession exceptions
- 13:02Refactoring to value objects
- 15:15Renaming for clarity
- 17:18Creating email value object
- 18:45Inline variable refactor
- 20:12Parameter introduction
- 21:16Removing validator
- 23:06Updating tests after refactor
- 24:24Domain value objects
- 25:52Summary
