Created
March 22, 2021 20:47
-
-
Save mgryszko/a1bc12bd9cfa476d667b92c61b1e021a to your computer and use it in GitHub Desktop.
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(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