Apologies if this is an old question, but I can't seem to find a pact (v2/v3) matcher that would check if an object-valued non-array response field (in e.g. REST/JSON) was one of a list of possible expectation shapes.
This kind of thing arises quite frequently in e.g. GraphQL schema union types (where a field could be e.g. a Person or a Team), and the possible values are quite different.
t
Timothy Jones
03/09/2023, 8:47 PM
You would cover these in separate tests
Timothy Jones
03/09/2023, 8:48 PM
A pact test is not about describing the possible responses, it’s about ensuring that your response types are covered.
Timothy Jones
03/09/2023, 8:48 PM
For example, if you could say “it might be a person or a team”, you could pass your tests without ever checking that the provider and consumer agree about what a Team should look like
Timothy Jones
03/09/2023, 8:49 PM
Think of the matchers as saying “this test covers all cases that pass this matcher”, not “this is the response schema”
a
Alan Boshier
03/09/2023, 8:56 PM
Thanks @Timothy Jones I see your point; it's a particular setup where provider responses are generated from GraphQL schema-driven mocks, but I can see I'm going to have to use provider state in some fashion to direct the mocking behaviour.