Hi there :wave: I have a quick design question reg...
# general
d
Hi there 👋 I have a quick design question regarding the
fromProviderState
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:
Copy code
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
Copy code
builder.given("a product exists")
  .uponReceiving("get that product")
  .method("GET")
  .pathFromProviderState("/product/\${id}", "/product/10")
  ...
with a provider having a state like
Copy code
@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 👍
3
Additionally, would that also be applicable for a product that does not exist? Such as
Copy code
builder.given("a product exists")
  .uponReceiving("get a product that does not exist")
  .method("GET")
  .path("/product/\${unknownId}", "/product/999")
  ...
with a state like
Copy code
@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
    )
}
u
Yes, this was exactly what that was for
💡 4
d
awesome, thanks for clarification thumbsupparrot
👌 1
(for visibility: @Stefano Lucka (colleague of mine))
s
Good to know