Daniel Tischner
08/11/2022, 7:28 AMfromProviderState
mechanism. Its not language specific, but I'll use the JVM examples.
A frequent situation, also shown in the docs, would be that a consumer is asking for a specific situation:
builder.given("product with ID 10 exists")
.uponReceiving("get product with ID 10")
.method("GET")
.path("/product/10")
...
In this example the consumer had to came up with an ID that might exist for a product. (And the provider will then have to adhere to that, making product 10 available).
Would this also be a valid application for fromProviderState
to let the provider decide on the ID of an existing product? (All examples I found in the docs only relate to autogenerated IDs that can not really be picked by the consumer without making life hard for the provider. And they are also mostly focused on using fromProviderState
for the response part, i.e. after willRespondWith()
.)
I.e. should we write this code instead as
builder.given("a product exists")
.uponReceiving("get that product")
.method("GET")
.pathFromProviderState("/product/\${id}", "/product/10")
...
with a provider having a state like
@State("a product exists")
fun createProduct(params: Map<String, String>): Map<String, Any> {
val product = ... // maybe create that product in the DB or something
return mapOf("id" to product.id)
}
Thanks in advance and cheers 👍Daniel Tischner
08/11/2022, 7:33 AMbuilder.given("a product exists")
.uponReceiving("get a product that does not exist")
.method("GET")
.path("/product/\${unknownId}", "/product/999")
...
with a state like
@State("a product exists")
fun createProduct(params: Map<String, String>): Map<String, Any> {
val product = ... // maybe create that product in the DB or something
return mapOf(
"id" to product.id,
"unknownId" to 50
)
}
uglyog
Daniel Tischner
08/11/2022, 8:32 AMDaniel Tischner
08/11/2022, 8:32 AMStefano Lucka
08/11/2022, 8:38 AM