Replies: 1 comment 4 replies
-
Of course it is okay, though best place for general Pact questions is the Slack community where all sorts of different set ups are discussed. In PactSwift you can allow empty arrays as valid responses by using let body: [
"products": Matcher.EachLike(
[
"name": Matcher.SomethingLike("foo"),
"description": Matcher.SomethingLike("bar"),
"availableCoupons": Matcher.EachLike(Matcher.IntLike(1234), min: 0) // <-- demand the `availableCoupons` to be present in response but allows an empty array and should pass the provider validation
],
min: 1, // <-- expect at least one product in response when validating provider
max: 999, // <-- allow max 999 products in response
count: 5 // <-- mock server returns 5 mocked products for consumer to test with
)
] I hope I understood your question. |
Beta Was this translation helpful? Give feedback.
-
This is a general PACT question... hope it's OK to ask here:
The product I'm developing has two potential back-end servers (providers). The first is a full-featured one, and the second will implement a subset of the features.
To give a fictionalized example, one of our APIs returns an array of "products". Let's say a product contains a name (string), description (string), and availableCoupons, which is an array of ints, referring to coupons from another API.
However, the lightweight provider doesn't deal with coupons, and will always return an empty array here.
When the consumer creates the contract, I gave it mock data with "products" which have examples both specifying and not specifying 'availableCoupons'. However, our provider (server) folks from the lightweight server say that they cannot fulfill this contract, since they don't have a means to return coupons.
What is the proper PACT-ful way to incorporate this? I can use separate tests, one with coupons specified, and the second without, and only have the lightweight server have the one without as part of their contract... but that seems wrong, since they're not violating the contract, they're just not fully implementing it.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions