Hey team I have one question, probably silly, abou...
# general
a
Hey team I have one question, probably silly, about how to do a contain check in the response array in Pact. below is a sample, if I want to check id 995 in sections seems I have to check the whole exact array or use some thing like regular expressions, is there an easier way to check this?(if sections is a object I can just check id 955 and leave other object I don't want to check)
Copy code
{"sections": [
   ...
   {
      "facilities": [
         {
            "id": 433,
            "key": "Swimming Pool (2019 format)",
            "name": "Swimming Pool"
         }
      ],
      "id": 999,
      "key": "Top Facilities",
      "name": "Top facilities"
   },
   {
      "facilities": [],
      "id": 995,
      "key": "Meals",
      "name": "Price for meals"
   },
   {
      "facilities": [],
      "id": 997,
      "key": "Languages Spoken",
      "name": "Languages spoken"
   }
   ...
]
}
a
Have you checked the arrayContaining function? That may help you if I'm not mistaken!
m
😵
🌕 1
Can you please explain what you want to test Alan? I’m not sure I understand the question. Do you want to check that an object in the list of arrays exists, that has the id
995
? Or do you want to check that each object in the list has an
id
?
(or something else)
a
Sure, first thanks Aaron's suggestion. arrayContaining could be helpful in this scenario but I didn't find this function in pact-python which I'm using now😥. The sections is an array and may contain hundreds of different objects. I want to check some of specific objects returned with correct name, key and facilities(exp:sections should contain object with id 995 with name "Price for meals", key "Meals" ...) I found it tough to describe my expect because pact will strictly check each index of object in an array and regular expressions(Term) seems much complex for this case
m
yeah, arrayContaining is unfortunately not supported in Python yet
😔 1
The idea is usually to use provider states, and to limit the responses from the provider for that state, so that you don’t have to do these checks. But that is sometimes easier said than done
i.e. the state might be
given a facility with meals exists
and then when the provider verification happens, this state reduces the responses from the endpoint to the shapes expected