Hi, probably this is a common question, I have the...
# general
m
Hi, probably this is a common question, I have the following test
Copy code
const reports = await getReportByID("xxxxxxxxxxx");
          return expect(reports).to.deep.equal(getReportBodyExpectation)
and it's failing, I got
Copy code
1.1) has a matching body
           $ -> Type mismatch: Expected List [{"account":{.........
but received Map {"account":{"acco
the easy fix is removing the [ ] from my json files, but is there a nice way or something that I should take a look
b
It's valid to use any JSON type as the root of a document, but objects give the greatest flexibility. If your endpoint represents a singular resource (not a list) then removing the list wrapper should be fine. But if it genuinely represents a list of resources, you should consider wrapping it in another object, and giving the list a field name.
1
m
Yep, the issue is that your consumer test is expecting an array, but your provider is returning an object
☝️ 1
You need to update your test to expect the correct shape the provider actually returns (an object) or modify the API provider to actually return an object of the shape you expect (presumably by working with that team to arrange the modification)
the easy fix is removing the [ ] from my json files, but is there a nice way or something that I should take a look
in case it’s not clear, you never should be modifying the JSON files directly. They represent what your API client is doing (in this case, expecting an array). By removing it from the pact file, you are modifying what the contract captures and potentially deviating from reality - this is likely to result in breakages
👍 1