From 639ea393abb13147f34df3a36d48824a4bff5969 Mon Sep 17 00:00:00 2001 From: Georgy Karataev Date: Mon, 13 Mar 2023 15:13:51 +0100 Subject: [PATCH] test: Bring intercept responses to one format (#1782) This rewrites some interceptors to always have the third argument compliant with the interceptors' response object interface (e.g., always include statusCode, body). Co-authored-by: Aleksandr Voznesenskii <62722417+Fewwy@users.noreply.github.com> --- cypress/support/interceptors.js | 69 +++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/cypress/support/interceptors.js b/cypress/support/interceptors.js index 902c6aa86..df484615d 100644 --- a/cypress/support/interceptors.js +++ b/cypress/support/interceptors.js @@ -6,16 +6,29 @@ import groupDetailFixtures from '../fixtures/groups/620f9ae75A8F6b83d78F3B55Af1c export const groupsInterceptors = { 'successful with some items': () => - cy.intercept('GET', '/api/inventory/v1/groups*', fixtures).as('getGroups'), + cy + .intercept('GET', '/api/inventory/v1/groups*', { + statusCode: 200, + body: fixtures + }) + .as('getGroups'), 'successful with some items second page': () => - cy.intercept('GET', '/api/inventory/v1/groups?*page=2&perPage=50*', groupsSecondPage).as('getGroupsSecond'), + cy + .intercept('GET', '/api/inventory/v1/groups?*page=2&perPage=50*', { + statusCode: 200, + body: groupsSecondPage + }) + .as('getGroupsSecond'), 'successful empty': () => cy .intercept('GET', '/api/inventory/v1/groups*', { - count: 0, - page: 1, - per_page: DEFAULT_ROW_COUNT, - total: 0 + statusCode: 200, + body: { + count: 0, + page: 1, + per_page: DEFAULT_ROW_COUNT, + total: 0 + } }) .as('getGroups'), 'failed with server error': () => { @@ -27,11 +40,10 @@ export const groupsInterceptors = { ); }, 'long responding': () => { - cy.intercept('GET', '/api/inventory/v1/groups*', (req) => { - req.reply({ - body: fixtures, - delay: 42000000 // milliseconds - }); + cy.intercept('GET', '/api/inventory/v1/groups*', { + statusCode: 200, + body: fixtures, + delay: 42000000 // milliseconds }).as('getGroups'); } }; @@ -39,27 +51,44 @@ export const groupsInterceptors = { export const groupDetailInterceptors = { successful: () => cy - .intercept('GET', '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', groupDetailFixtures) + .intercept( + 'GET', + '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', + { + statusCode: 200, + body: groupDetailFixtures + } + ) .as('getGroupDetail'), empty: () => cy - .intercept('GET', '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', { statusCode: 404 }) + .intercept( + 'GET', + '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', + { statusCode: 404 } + ) .as('getGroupDetail'), 'failed with server error': () => { Cypress.on('uncaught:exception', () => { return false; }); - cy.intercept('GET', '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', { statusCode: 500 }).as( - 'getGroupDetail' - ); + cy.intercept( + 'GET', + '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', + { statusCode: 500 } + ).as('getGroupDetail'); }, 'long responding': () => { - cy.intercept('GET', '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', (req) => { - req.reply({ + cy.intercept( + 'GET', + '/api/inventory/v1/groups/620f9ae75A8F6b83d78F3B55Af1c4b2C', + { + statusCode: 200, body: groupDetailFixtures, delay: 42000000 // milliseconds - }); - }).as('getGroupDetail'); + } + ) + .as('getGroupDetail'); }, 'patch successful': () => { cy