Skip to content

Commit

Permalink
Merge pull request #1526 from GSA/1392-handle-codes-prod-link-test
Browse files Browse the repository at this point in the history
1392 handle codes prod link test
  • Loading branch information
scottqueen-bixal authored Jul 2, 2024
2 parents 5c17cfd + e7061a4 commit b5da2d1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-cypress-prod-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
browser: chrome
env: NODE_ENV=test
config-file: cypress.prod.config.js
config-file: cypress.prod.links.config.js
working-directory: benefit-finder

- name: create github issue
Expand Down
12 changes: 0 additions & 12 deletions benefit-finder/cypress.prod.config.js

This file was deleted.

134 changes: 88 additions & 46 deletions benefit-finder/cypress/e2e/usagov-public-site/links.cy.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,106 @@
import * as utils from '../../support/utils'
import * as BENEFITS_ELIBILITY_DATA from '../../fixtures/benefits-eligibility.json'

describe('Verify correct status code when user navigates links', () => {
// to be removed when uncaught exceptions are addressed
Cypress.on('uncaught:exception', (_err, runnable) => {
return false
})
it('Verify success status code response for links in Death of a loved one English page', () => {
const selectedData =
BENEFITS_ELIBILITY_DATA['death-of-a-loved-one'].en.param
const scenario = utils.encodeURIFromObject(selectedData)
cy.visit(`benefit-finder/death?${scenario}`)
cy.get('main a[href]').each(link => {
cy.request(link.prop('href'))
const localePaths = {
en: [
{ key: 'death-of-a-loved-one', path: 'death' },
{ key: 'retirement', path: 'retirement' },
{ key: 'disability', path: 'disability' },
],
es: [
{ key: 'death-of-a-loved-one', path: 'muerte' },
{ key: 'retirement', path: 'jubilacion' },
{ key: 'disability', path: 'discapacidad' },
],
}

const handlerequest = ({ testLink, link }) => {
const url = testLink || link.prop('href')
return cy
.request({
url,
failOnStatusCode: false,
})
.then(response => {
if (response.status === 200) {
expect(response.status).to.eq(200)
} else if (response.status === 403) {
cy.get('body').children().its('length').should('be.gt', 0)
} else if (response.status === 503) {
throw new Error(`site down - gave a 503 ${url}`)
} else if (response.status === 404) {
throw new Error(`page not found - gave a 404 ${url}`)
} else {
cy.get('body').children().its('length').should('be.gt', 0)
}
})
}

const validateErrorCodes = test => {
// we verify site is alive and fail on 404 || 503
cy.get('#benefit-finder a[href]').each(link => {
handlerequest({ link })
})
}

it('Verify success status code response for links in Death of a Loved One Spanish page', () => {
const selectedData =
BENEFITS_ELIBILITY_DATA['death-of-a-loved-one'].es.param
const scenario = utils.encodeURIFromObject(selectedData)
cy.visit(`es/buscador-beneficios/muerte?${scenario}`)
cy.get('main a[href]').each(link => {
cy.request(link.prop('href'))
})
const validateLinks = ({ selectedData, path }) => {
const scenario = utils.encodeURIFromObject(selectedData)
cy.visit(`${path}?${scenario}`)
validateErrorCodes()
}

// to be removed when uncaught exceptions are addressed
Cypress.on('uncaught:exception', (error, runnable) => {
return false
})

describe('Verify correct status code handling', () => {
// negate validation on our functional code
Cypress.on('fail', (error, runnable) => {
if (JSON.stringify(error).includes('httpstat')) {
expect(error).to.not.be.undefined
} else {
throw error
}
})

it('Verify success status code response for links in Retirement English page', () => {
const selectedData = BENEFITS_ELIBILITY_DATA.retirement.en.param
const scenario = utils.encodeURIFromObject(selectedData)
cy.visit(`benefit-finder/retirement?${scenario}`)
cy.get('main a[href]').each(link => {
cy.request(link.prop('href'))
})
it(`handles 404 with an error`, () => {
handlerequest({ testLink: 'https://httpstat.us/404' })
})

it('Verify success status code response for links in Retirement Spanish page', () => {
const selectedData = BENEFITS_ELIBILITY_DATA.retirement.es.param
const scenario = utils.encodeURIFromObject(selectedData)
cy.visit(`es/buscador-beneficios/jubilacion?${scenario}`)
cy.get('main a[href]').each(link => {
cy.request(link.prop('href'))
})
it(`handles 503 with an error`, () => {
handlerequest({ testLink: 'https://httpstat.us/503' })
})

it(`handles 200 successfully`, () => {
handlerequest({ testLink: 'https://httpstat.us/200' })
})

it(`handles any 403 successfully`, () => {
handlerequest({ testLink: 'https://httpstat.us/403' })
})

it(`handles any other request successfully`, () => {
handlerequest({ testLink: 'https://httpstat.us/201' })
})
})

it('Verify success status code response for links in Disability English page', () => {
const selectedData = BENEFITS_ELIBILITY_DATA.disability.en.param
const scenario = utils.encodeURIFromObject(selectedData)
cy.visit(`benefit-finder/disability?${scenario}`)
cy.get('main a[href]').each(link => {
cy.request(link.prop('href'))
describe('Verify correct status code when user navigates links in each locales', () => {
localePaths.en.forEach(location => {
it(`Verify success status code response for links in ${location.key} en page`, () => {
validateLinks({
selectedData: BENEFITS_ELIBILITY_DATA[`${location.key}`].en.param,
path: `benefit-finder/${location.path}`,
})
})
})

it('Verify success status code response for links in Disability English page', () => {
const selectedData = BENEFITS_ELIBILITY_DATA.disability.es.param
const scenario = utils.encodeURIFromObject(selectedData)
cy.visit(`es/buscador-beneficios/discapacidad?${scenario}`)
cy.get('main a[href]').each(link => {
cy.request(link.prop('href'))
localePaths.es.forEach(location => {
it(`Verify success status code response for links in ${location.key} es page`, () => {
validateLinks({
selectedData: BENEFITS_ELIBILITY_DATA[`${location.key}`].en.param,
path: `es/buscador-beneficios/${location.path}`,
})
})
})
})
2 changes: 1 addition & 1 deletion benefit-finder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"cy:run:component": "NODE_ENV=test npx cypress run --component --browser chrome",
"cy:run:e2e": "NODE_ENV=test npx cypress run --browser chrome",
"cy:run": "NODE_ENV=test npm run cy:run:component && npm run cy:run:e2e",
"cy:run:prod:e2e": "NODE_ENV=test npx cypress run --config-file cypress.prod.config.js --browser chrome",
"cy:run:prod:e2e": "NODE_ENV=test npx cypress run --config-file cypress.prod.links.config.js --browser chrome",
"cy:run:prod:links:e2e": "NODE_ENV=test npx cypress run --config-file cypress.prod.links.config.js --browser chrome",
"cy:run:pipeline": "NODE_ENV=test concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"http-server ./storybook-static --port 6006 --silent\" -Y",
"cy:run:edge:e2e": "NODE_ENV=test npx cypress run --browser edge",
Expand Down

0 comments on commit b5da2d1

Please sign in to comment.