Created
March 19, 2021 16:11
-
-
Save mgryszko/6e068dfc99848b2014d0f29b4807c1d3 to your computer and use it in GitHub Desktop.
PricingControllerPactTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExtendWith(SpringExtension::class) | |
@Provider("pricing") | |
@PactBroker(host = "localhost", port = "9292") | |
@WebMvcTest | |
class PricingControllerPactTest { | |
@MockkBean | |
lateinit var useCase: PriceCartUseCase | |
@TestTemplate | |
@ExtendWith(PactVerificationSpringProvider::class) | |
fun pactVerifications(context: PactVerificationContext) { | |
context.verifyInteraction() | |
} | |
@BeforeEach | |
fun before(context: PactVerificationContext) { | |
context.target = MockMvcTestTarget().apply { | |
controllers = listOf(PricingController(useCase)) | |
} | |
} | |
@State("cart with existing SKUs") | |
fun `cart with existing SKUs`() { | |
val cart = Cart(listOf(CartItem("croissants", 4), CartItem("baguettes", 5))) | |
every { useCase.execute(cart) } returns | |
PricedCart( | |
items = listOf( | |
PricedCartItem( | |
sku = "croissants", | |
quantity = 3, | |
unitPrice = 1.10.toBigDecimal(), | |
totalPrice = 2.65.toBigDecimal(), | |
), | |
PricedCartItem( | |
sku = "baguettes", | |
quantity = 5, | |
unitPrice = 0.75.toBigDecimal(), | |
totalPrice = 3.0.toBigDecimal(), | |
), | |
), | |
total = 5.65.toBigDecimal(), | |
) | |
} | |
@State("some cart SKUs don't exist") | |
fun `some cart SKUs don't exist`() { | |
every { useCase.execute(any()) } returns null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment