Skip to content

Instantly share code, notes, and snippets.

@mgryszko
Created March 19, 2021 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgryszko/6e068dfc99848b2014d0f29b4807c1d3 to your computer and use it in GitHub Desktop.
Save mgryszko/6e068dfc99848b2014d0f29b4807c1d3 to your computer and use it in GitHub Desktop.
PricingControllerPactTest
@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