Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Bring intercept responses to one format #1782

Merged
merged 6 commits into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 49 additions & 20 deletions cypress/support/interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': () => {
Expand All @@ -27,39 +40,55 @@ 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');
}
};

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
Expand Down