`arrayContaining(X1, ..., Xi, ..., Xn)` as I under...
# general
a
arrayContaining(X1, ..., Xi, ..., Xn)
as I understand it means "match if and only if the returned array contains at least one instance of each `Xi`" , and allows other non-matching elements to appear in the returned array. Is there a variant of this which says, every element of the returned array must match either
X1
... or
Xi
... or
Xn
?
m
No, because that is the "optional attributes" problem in disguise
a
Interesting - so as an example I ask for e.g. a list of contacts for a Person; I'm expecting either phone or email contacts so I want to assert that the returned list doesn't contain anything I can't handle (e.g. a fax contact). If the provider is enhanced to start returning fax contacts too, it doesn't feel like my contract will protect me against that breaking change.
m
It’s more the inverse that Pact is designed to protect in this case. The case you’re referring to is probably best left to the standard array matching, and the scenarios can be separated by provider states to ensure only each type of contact is tested
Pact does assume Postel’s law here “be liberal with what you accept”
i.e. if extra data comes back, you should ignore it. but this is probably an edge case of that principle
You can of course also test that specific scenario without Pact quite easily
a
Thanks Matt - I'm not sure the provider state approach would fly here since the consumer would by definition only be directing the provider to return types it knows about.
But I understand your argument, I think in the case of GraphQL queries the Postel approach would be to request something like:
Copy code
contacts {
   __typename: always lets us know what this is
   ... on PhoneContact { ... }
   ... on EmailContact { ... }
and if the provider always returns one of each type it supports arrayContaining will not fail.