Hi, I already wrote in the pact-jvm channel, but I...
# general
j
Hi, I already wrote in the pact-jvm channel, but I guess it's also a general question, so I'm trying here as well. I am looking for a way to specify that we expect either attribute A to be present, OR attribute B. Is there a way to specify this with pact? I have tried with the combine : "OR", but I suspect this is rather for specifying multiple rules for one attribute... Would appreciate any help!
y
use provider states to assert each state, if you had an or, your provider may only ever provide you one of the values and pass the verification successfully, never returning the or'd value in real life
j
Thanks for the suggestion. The idea would be that I define the message twice (once with attribute B set, and once with attribute A), and provide two different provider states (with the .given method of the builder? This also would work with asynchronous messages?
t
Yes
You write two examples - one with the field, and one without. The reason for this is that a test which allows optional fields would still pass even if the field was never present. You wouldn’t be sure that your provider could ever generate that missing field.
m
See this article for more howtooptional