0012 · Presentation holds use case ports; routes are tested with mocks
Status: Accepted (2026-10-11). Amends 0004: the
field generate use-case adds is Arc<dyn …UseCaseTrait>.
Context
Section titled “Context”architecture.md says dependencies are injected as Arc<dyn Trait>, never concrete types. The
application layer honoured it; {Entity}Api did not — it held Arc<CreateProductUseCaseImpl>.
Presentation was coupled to business::application, and a route could not be exercised without
the real use case and a repository behind it. Generated projects shipped no presentation
tests.
Decision
Section titled “Decision”{Entity}Apifields areArc<dyn {Uc}UseCaseTrait>.bootstrap.rsis unchanged: theArc<{Uc}UseCaseImpl>it builds coerces to the trait object at the struct literal, so the composition root is the only file naming implementations. No{Entity}Api::new(…)— the fields are public and a struct literal is already the constructor.- Every use case trait file carries
mocks::Mock{Uc}UseCase(mockall::mock!) behind#[cfg(any(test, feature = "test-utils"))]— the gate the repository mocks already use. - The Object Mothers’
testsmodule inbusiness/src/lib.rsmoves from#[cfg(test)]to the same gate, so presentation builds return values with the mothers instead of a second set of fixtures. presentationdev-depends onbusinesswithtest-utilsand onpoemwithtest.- CRUD
routes.rsis generated with a test module that drives the realOpenApiServicethroughpoem::test::TestClient— the paths, the extractors, the JSON body parsing and theApiResponsestatus mapping are all exercised. One mock per use case lives in aMocksstruct; a test sets an expectation only on the use case its route should call, so a route wired to the wrong one panics. One test per status path: create 201/422, get 200/404, list 200/500, update 200/404, delete 204/404. Request bodies come from the type registry’s default literals (FieldCtx::default_literal) serialised with poem-openapi’sToJSON.
Consequences
Section titled “Consequences”test-utilsnow also compiles the Object Mothers intobusinesswhen another crate’s tests enable it; they useexpect, which is acceptable in test support code. A plain build is unaffected.- The mocked use cases do not validate, so the route tests check HTTP wiring and status mapping only. Validation stays covered where it lives (domain and application tests).
- Custom use cases added by
generate use-caseget the port field and the mock, but no endpoint and no route test — their HTTP shape still cannot be inferred (ADR-0004).