Abaks: testing core domainGautier DI FOLCO June 14, 2023 [dev] #haskell #design #project #abaks
Previous log saw the introduction of
One of the reason I favor
Clean Architecture specifically over
Hexagonal Architecture is to have a pure core domain, easily testable (without mocks or specific interpreters).
I also chose to build tested
Event's relying on previous
Commands to avoid testing impossible states.
Note that the lack of legacy is also a strong motivation.
We can start with a simple helper which apply
Commands one after the other, keeping results and accumulating
= snd . foldl' go (mempty, mempty) where go (events, previousResults) handler = let result = applyCommand handler events in (either (const events) (events <>) result, previousResults <> [result]) applyCommands
Then we can start to write some tests:
= do describe "Entities" $ do it "startPeriod should work" $ applyCommands [startPeriod anyPeriodId periodName periodStart periodEnd (Amount 0)] `shouldSatisfy` liftEq ($) [isRight] it "deleteEntry should fail" $ applyCommands [deleteEntry (EntryId 42) "do not exist"] `shouldSatisfy` liftEq ($) [isLeft] spec