Skip to content

Instantly share code, notes, and snippets.

@mgryszko
Created March 22, 2021 20:47
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/a1bc12bd9cfa476d667b92c61b1e021a to your computer and use it in GitHub Desktop.
Save mgryszko/a1bc12bd9cfa476d667b92c61b1e021a to your computer and use it in GitHub Desktop.
@ExtendWith(PactConsumerTestExt::class)
@PactTestFor(providerName = "inventory")
class InventoryRepositoryPactTest {
@Pact(consumer = "pricing")
fun `some items available pact`(builder: PactDslWithProvider): RequestResponsePact =
builder
.given("some items are available")
.uponReceiving("inventory check")
.method("POST")
.path("/inventory/check")
.body("""{
"items": [{
"sku": "::sku1::",
"quantity": 2
}, {
"sku": "::sku2::",
"quantity": 1
}]
}""".trimIndent())
.willRespondWith()
.status(200)
.body("""{
"items": [{
"sku": "::sku1::",
"quantity": 1
}, {
"sku": "::sku2::",
"quantity": 0
}]
}""".trimIndent(), "application/json")
.toPact()
@Test
@PactTestFor(pactMethod = "some items available pact")
fun `some items available`(mockServer: MockServer) {
val repository = InventoryRepository(mockServer.getUrl())
val cart = Cart(listOf(CartItem("::sku1::", 2), CartItem("::sku2::", 1)))
expect(repository.check(cart)).toBe(
Cart(listOf(CartItem("::sku1::", 1), CartItem("::sku2::", 0)))
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment