davT
09/08/2022, 1:41 PMYousaf Nabi (pactflow.io)
davT
09/08/2022, 1:47 PMdavT
09/08/2022, 1:48 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
davT
09/08/2022, 1:51 PMdavT
09/08/2022, 1:52 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
davT
09/08/2022, 2:01 PMYousaf Nabi (pactflow.io)
[
{
"type": "parent",
"children": [] #no children
},
{
"type": "parent"
"children" :[] #no children
},
.....
]
and your test would pass, and you would be safe to deploy.
however your provider, when it has children could actually return a different structure than you expected for the list with children, and you wouldn’t know until it was too late?
[
{
"type": "parent",
"children": [] #no children
},
{
"type": "parent"
"children" :[{"firstName": "Buzz"}..... ] # children
},
.....
]
davT
09/08/2022, 2:14 PMdavT
09/08/2022, 2:21 PMdavT
09/08/2022, 2:41 PMYousaf Nabi (pactflow.io)
I mean if developers cannot validate a response with this kind of structure Pact is very limited in its use , don’t you think ?I don’t no, you can use provider states for this purpose.
I really expected for a paid for service this stuff would be covered off.You’re asking for a fundamental change in a project, which has associated documentation to explain the rationale, so why would you assume that this would be covered?
Yousaf Nabi (pactflow.io)
What I was asking is can a matcher be implemented to verify an empty list or an object(s) like the one in the response but only that shape ? It appears not . I prefer to say either not optional , either no objects or the ones of a shape I define. Either one state or another, there’s only two states. Like Enum isn’t optional its one of a list of string s, does that make sense ?
Yousaf Nabi (pactflow.io)
davT
09/08/2022, 3:38 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Matt (pactflow.io / pact-js / pact-go)
[
{
"type": "parentwithnochildrcen",
"children": [] #no children
},
{
"type": "parentwithchildren",
"children" :eachLike({"firstName": "Buzz"}) # children
}
]
This would not match an arbitrary length array, but again, if you can control the data you now have tested both cases in a single test.
If you can’t use provider states as Yousaf says, the arrayContaining
matcher in JS might do what you need. It would allow you to specify multiple different object shapes, and would ensure the provider returns an array that at least has both of them. This is not yet available in Python though, which if I recall, is what you needdavT
09/09/2022, 9:17 AMMatt (pactflow.io / pact-js / pact-go)