Skip to content

Instantly share code, notes, and snippets.

@mgryszko
Created March 20, 2021 21:49
Show Gist options
  • Save mgryszko/6c7c708d001688f1c0eb59c60206890e to your computer and use it in GitHub Desktop.
Save mgryszko/6c7c708d001688f1c0eb59c60206890e to your computer and use it in GitHub Desktop.
class PriceCartUseCaseTest {
val inventory = mockk<Inventory>()
val pricingEngine = mockk<PricingEngine>()
val useCase = PriceCartUseCase(inventory, pricingEngine)
val cartToPrice = Cart(listOf(CartItem("::sku1::", 2), CartItem("::sku2::", 1)))
val availableCart = Cart(listOf(CartItem("::sku1::", 1), CartItem("::sku2::", 0)))
val unavailableCart = Cart(listOf(CartItem("::sku1::", 0), CartItem("::sku2::", 0)))
val pricedCard = PricedCart(emptyList(), 0.toBigDecimal())
@Test
fun `some cart items available`() {
every { inventory.check(cartToPrice) } returns availableCart
every { pricingEngine.price(availableCart) } returns pricedCard
expect(useCase.execute(cartToPrice)).toBe(pricedCard)
}
@Test
fun `none of cart items available`() {
every { inventory.check(cartToPrice) } returns unavailableCart
expect(useCase.execute(cartToPrice)).toBe(null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment