Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint: Architecture

โญโญโญ advancedโณ 28 min read๐Ÿ“ Lesson 142 of 169

Assemble an injected service: repository + injected clock, deterministic ids.

Checkpoint โ€” an injected checkout

Implement CheckoutService(repo, clock):

  • checkout(cart) builds {'id': f'o-{clock.now():.0f}', 'items': list(cart), 'total': sum(cart)}, saves it via the repository, and returns it
  • an empty cart raises ValueError('empty cart') โ€” nothing saved
  • the clock is INJECTED (clock.now() returns a float) โ€” the graded test uses a fixed fake clock and asserts the id and totals exactly

Constructor injection + injected time = deterministic tests. That is the lesson.