-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1526 from GSA/1392-handle-codes-prod-link-test
1392 handle codes prod link test
- Loading branch information
Showing
4 changed files
with
90 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
134 changes: 88 additions & 46 deletions
134
benefit-finder/cypress/e2e/usagov-public-site/links.cy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`, | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters