Untitled
unknown
javascript
a year ago
1.2 kB
11
Indexable
/** * arrayIncludesObjectOnPath - Check if from a list of requests, the value of a given jsonPath is qual to an expected item * @param {requestsList} Array * @param {expectedItem} JSON * @param {jsonPath} String */ export function arrayIncludesObjectOnPath(requestsList, expectedItem, jsonPath) { let valid = false; cy.task("log", `expectedItem: ${JSON.stringify(expectedItem)}`); cy.task("log", `jsonPath: ${jsonPath}`); cy.task("log", `Number of requests: ${requestsList.length}`); let i = 1; // eslint-disable-next-line guard-for-in for (const entry of requestsList) { const jsonRequestBody = entry.request.body; cy.task("log", `#${i} jsonRequestBody: ${JSON.stringify(jsonRequestBody)}`); const objectValueOnPath = JSONPath({ path: jsonPath, json: jsonRequestBody }); valid = isEqual(objectValueOnPath[0], expectedItem); cy.task("log", `#${i} objectValueOnPath: ${JSON.stringify(objectValueOnPath)}`); if (valid === false) { const result = compare(objectValueOnPath[0], expectedItem); cy.task("log", `#${i} Diff: ${JSON.stringify(result)}`); } else { cy.task("log", `#${i} Found a match on request`); return valid; } i++; } return valid; }
Editor is loading...
Leave a Comment