Hello Friends,
I am facing an issue with verifying the json response stored in the Json data file with the actual response. I wanted to verify the propertyInvestmentRatios
array alone from the response, for which I was getting an error, so I am trying to verify the entire response stored in CSV against my actual response received. Appreciate your help on this matter.
First of all below is my response which I have stored in a json file with the key as fullReponseBody
"fullResponseBody": {
"entities": {
"propertyInvestmentRatios": [
{
"id": "805432",
"cashFlowAvailable": "-126391.19",
"accessedInterestExpense": "691.31",
"propertyICR": "-182.83",
"groupSurplusRequired": "133304.29",
"surplusAvailable": "-999.00",
"assessmentResult": "Incomplete"
}
]
},
"result": {
"propertyInvestments": [
"805432"
]
}
}
I am trying to compare by fetching the response but I am getting an error as below. The issue I notice is that the block of code is being read an an object.
Test 1 :- To verify the response as is from the CSV which is stored exactly the same.
pm.test("Verify the response for Property Investment Ratio Calculator", function () {
var jsonResponse = pm.response.json();
console.log('ID returned from Response is '+jsonResponse.entities.propertyInvestmentRatios[0]);
pm.expect(pm.response.text()).to.contains((pm.iterationData.get("fullResponseBody")));
});
Below is the error I get in the console.
Verify the response for Property Investment Ratio Calculator | AssertionError: expected '{"entities":{"propertyInvestmentRatios":[{"id":"805432","cashFlowAvailable":"-126391.19","accessedInterestExpense":"691.31","propertyICR":"-182.83","groupSurplusRequired":"133304.29","surplusAvailable":"-999.00","assessmentResult":"Incomplete"}]},"result":{"propertyInvestments":["805432"]}}' to include { entities: { propertyInvestmentRatios: [ [Object] ]}, result: { propertyInvestments: [ '805432' ] } }
I tried the below approach as well.
Test 2
pm.test("Body is correct", function () {
pm.response.to.have.body(pm.iterationData.get("fullResponseBody"));
});
Body is correct | AssertionError: expected response body json to equal { Object (entities, result) } but got { Object (entities, result) }
The issue I notice is that the block of code is being read an an object from Json Data file. Appreciate if you can let me know what am I doing wrong. Thanks in advance.