Skip to content

Commit

Permalink
chore: allow for both 200 and 201 response from backend in cypress te…
Browse files Browse the repository at this point in the history
…sts (#2802)

Needed to keep the cypress tests passing.

There is a recurring issue from the backend:
Sometimes a create request returns 200, other times 201.
To avoid having to update these tests continually, accept both values as valid
since it doesn't have any impact on the app
  • Loading branch information
jenniferarnesen authored Oct 24, 2023
1 parent 9c6c0c6 commit e62700d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
15 changes: 8 additions & 7 deletions cypress/integration/edit/edit_dashboard/show_description.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { When, Then } from 'cypress-cucumber-preprocessor/steps'
import { clickViewActionButton } from '../../../elements/viewDashboard.js'
import { getApiBaseUrl } from '../../../support/utils.js'

const SHOW_DESC_RESP_CODE_SUCCESS = 201
const SHOW_DESC_RESP_CODE_FAIL = 409
const RESP_CODE_200 = 200
const RESP_CODE_201 = 201
const RESP_CODE_FAIL = 409

before(() => {
//ensure that the description is not currently shown
Expand All @@ -15,7 +16,7 @@ before(() => {
},
body: 'false',
}).then((response) =>
expect(response.status).to.equal(SHOW_DESC_RESP_CODE_SUCCESS)
expect(response.status).to.be.oneOf([RESP_CODE_201, RESP_CODE_200])
)
})

Expand All @@ -29,7 +30,7 @@ When('I click to show description', () => {

cy.wait('@toggleDescription')
.its('response.statusCode')
.should('eq', SHOW_DESC_RESP_CODE_SUCCESS)
.should('be.oneOf', [RESP_CODE_200, RESP_CODE_201])
})

When('I click to hide the description', () => {
Expand All @@ -38,20 +39,20 @@ When('I click to hide the description', () => {

cy.wait('@toggleDescription')
.its('response.statusCode')
.should('eq', SHOW_DESC_RESP_CODE_SUCCESS)
.should('be.oneOf', [RESP_CODE_200, RESP_CODE_201])
})

// Error scenario
When('clicking to show description fails', () => {
cy.intercept('PUT', 'userDataStore/dashboard/showDescription', {
statusCode: SHOW_DESC_RESP_CODE_FAIL,
statusCode: RESP_CODE_FAIL,
}).as('showDescriptionFails')

clickViewActionButton('More')
cy.contains('Show description').click()
cy.wait('@showDescriptionFails')
.its('response.statusCode')
.should('eq', SHOW_DESC_RESP_CODE_FAIL)
.should('eq', RESP_CODE_FAIL)
})

Then(
Expand Down
15 changes: 12 additions & 3 deletions cypress/integration/view/view_dashboard/resize_dashboards_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
} from '../../../elements/viewDashboard.js'
import { EXTENDED_TIMEOUT } from '../../../support/utils.js'

const RESP_CODE_200 = 200
const RESP_CODE_201 = 201

// Scenario: I change the height of the control bar
When('I drag to increase the height of the control bar', () => {
cy.intercept('PUT', '/userDataStore/dashboard/controlBarRows').as('putRows')
Expand All @@ -14,7 +17,9 @@ When('I drag to increase the height of the control bar', () => {
.trigger('mousemove', { clientY: 300 })
.trigger('mouseup')

cy.wait('@putRows').its('response.statusCode').should('eq', 201)
cy.wait('@putRows')
.its('response.statusCode')
.should('be.oneOf', [RESP_CODE_200, RESP_CODE_201])
})

Then('the control bar height should be updated', () => {
Expand All @@ -29,7 +34,9 @@ Then('the control bar height should be updated', () => {
.trigger('mousedown')
.trigger('mousemove', { clientY: 71 })
.trigger('mouseup')
cy.wait('@putRows').its('response.statusCode').should('eq', 201)
cy.wait('@putRows')
.its('response.statusCode')
.should('be.oneOf', [RESP_CODE_200, RESP_CODE_201])
})

When('I drag to decrease the height of the control bar', () => {
Expand All @@ -40,5 +47,7 @@ When('I drag to decrease the height of the control bar', () => {
.trigger('mousemove', { clientY: 300 })
.trigger('mouseup')

cy.wait('@putRows').its('response.statusCode').should('eq', 201)
cy.wait('@putRows')
.its('response.statusCode')
.should('be.oneOf', [RESP_CODE_200, RESP_CODE_201])
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { getApiBaseUrl, EXTENDED_TIMEOUT } from '../../../support/utils.js'
const MIN_DASHBOARDS_BAR_HEIGHT = 71
const MAX_DASHBOARDS_BAR_HEIGHT = 431

const RESP_CODE_200 = 200
const RESP_CODE_201 = 201

beforeEach(() => {
cy.request({
method: 'PUT',
Expand All @@ -17,7 +20,9 @@ beforeEach(() => {
'content-type': 'application/json',
},
body: '1',
}).then((response) => expect(response.status).to.equal(201))
}).then((response) =>
expect(response.status).to.be.oneOf([RESP_CODE_201, RESP_CODE_200])
)
})

When('I toggle show more dashboards', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { When, Then } from 'cypress-cucumber-preprocessor/steps'
import { getApiBaseUrl } from '../../../support/utils.js'

const RESP_CODE_200 = 200
const RESP_CODE_201 = 201
const RESP_CODE_FAIL = 409

// Error scenario

before(() => {
Expand All @@ -12,20 +16,22 @@ before(() => {
'content-type': 'application/json',
},
body: 'false',
}).then((response) => expect(response.status).to.equal(201))
}).then((response) =>
expect(response.status).to.be.oneOf([RESP_CODE_201, RESP_CODE_200])
)
})

When('clicking to show description fails', () => {
cy.intercept('PUT', 'userDataStore/dashboard/showDescription', {
statusCode: 409,
statusCode: RESP_CODE_FAIL,
}).as('showDescriptionFails')

cy.get('button').contains('More').click()
cy.contains('Show description').click()

cy.wait('@showDescriptionFails')
.its('response.statusCode')
.should('eq', 409)
.should('eq', RESP_CODE_FAIL)
})

Then(
Expand Down

0 comments on commit e62700d

Please sign in to comment.