Hello everyone, how are you? I’ve a problem using ...
# pact-python
c
Hello everyone, how are you? I’ve a problem using Like match in my mock response. I’ve a mock body response in my consumer with an array with 3 elements inside, like this
Like({array: [1, 2, 3]})
, but when I’m running this contract in my provider verification the provider return an array with 6 elements and the validation fail. Is there any way to ignore the array length and just verify if the response in my provider contains an array with length greater than 0 in the body?
m
Yes. What shape is that actual response from your API you're trying to model? You probably want to use the
eachLike
variant which you use in place of arrays, and supply an example item and min length
c
Thats good to know, thank you Matt. This is exactly my response:
Copy code
Like({
    "shelves": [
        {
            "id": "31239bf8-e8d8-4893-a3de-",
            "type": "BILLBOARD",
            "parentIds": [],
            "displayName": "Destaques",
            "order": 1,
            "active": True,
            "imageUrl": None,
            "state": None,
            "cities": None,
            "startsAt": "2020-10-01T03:00:00.000Z",
            "endsAt": None,
            "isRoot": True,
            "items": {
                "result": [
                    {
                        "id": "b7566f41-db87-4b03-bef2",
                        "type": "BANNER",
                        "displayName": "TESTEQA10",
                        "image": ".jpg",
                    },
                    {
                        "id": "14ed8ec5-bca2-426d-bbcc",
                        "type": "BANNER",
                        "displayName": "TESTE DE DATAs",
                        "image": ".jpg",
                    },
                ],
                "hasMoreItems": False,
            },
        }
    ],
    "hasNextPage": True,
    "nextCursor": "MQ==",
    "images": [],
})
The problem i’m getting is with the
result
list
m
Hmm the top level like I thought should cascade
Try replacing the result value with the each like matcher (it accepts a single example value and a min length)
c
Thank you, I will try
👍 1