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
Yousaf Nabi (pactflow.io)
04/24/2023, 2:12 PM
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
Julie Røsok
04/24/2023, 2:37 PM
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
Timothy Jones
04/24/2023, 5:00 PM
Yes
Timothy Jones
04/24/2023, 5:01 PM
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.