I'm using Cypress as my automation framework for both API and UI tests. I've written multiple API tests that are running and passing but they're only validating that the response.status returns a 200. I want to compare the response json from a GET against a stored "expected" response to confirm that the JSON response data is correct.
I've tried different variations of to.deep.equal and deepEquals in my .then(response => {} code block. But I don't want to validate that just one field is returning the correct value, I want to validate whether a bunch of different fields are returning the correct values. My GET request returns over 100 lines of nested JSON fields/values and I only want to validate 20 or so fields/values nested inside each other.
cy.request({
method: 'GET',
log: true,
url: 'https://dev.api.random.com/calculators/run-calculate/524/ABC',
headers: {
'content-type': 'application/json',
'x-api-key': calcXApiKey
},
body: {}
}).then(response => {
const respGet = response.body
const tPrice = response.body.data.calculations.t_costs[0].comparison.t_price
cy.log(respGet, tPrice)
assert.deepEqual({
tPrice
}, {
t_price: '359701'
})
// assert.equal(response.status, 200) -- This works great
})
Error= expected { tPrice: undefined } to deeply equal { t_price: 359701 }
deepEqual