diff --git a/test/cypress/e2e/moderationDashboard.cy.ts b/test/cypress/e2e/moderationDashboard.cy.ts index 554c9102..98624352 100644 --- a/test/cypress/e2e/moderationDashboard.cy.ts +++ b/test/cypress/e2e/moderationDashboard.cy.ts @@ -2,16 +2,14 @@ import enUS from '../../../i18n/locales/en.json' import fakeSubmissionResponse from '../../fake_data/moderation_dashboard/fakeSubmissionResponse.json' import { aliasQuery } from '../utils' -before(() => { - cy.login() -}) - describe('Moderation dashboard', () => { before(() => { cy.intercept('POST', '*', req => { aliasQuery(req, 'query Submissions', fakeSubmissionResponse) }) + cy.login() + cy.visit('/moderation') cy.wait('@query Submissions') }) @@ -115,6 +113,8 @@ describe('Moderation Edit Submission Form', () => { aliasQuery(req, 'query Submissions', fakeSubmissionResponse) }) + cy.login() + cy.visit('/moderation') cy.wait('@query Submissions') cy.get('[data-testid="mod-submission-list-item-1"]').click() @@ -278,6 +278,8 @@ describe('Moderation Edit Submission Modal', () => { aliasQuery(req, 'query Submissions', fakeSubmissionResponse) }) + cy.login() + cy.visit('/moderation') cy.wait('@query Submissions') cy.get('[data-testid="mod-submission-list-item-1"]').click() diff --git a/test/cypress/utils.ts b/test/cypress/utils.ts index 77f908c7..c0334b01 100644 --- a/test/cypress/utils.ts +++ b/test/cypress/utils.ts @@ -20,9 +20,20 @@ export const auth0Login = () => { cy.url().should('equal', baseUrl) } +// https://docs.cypress.io/api/commands/intercept#Interception-lifecycle +export const requestHandler = (req: IncomingHttpRequest) => { + req.on('before:response', res => { + // force all API responses to not be cached + res.headers['cache-control'] = 'no-store' + }) +} + // https://docs.cypress.io/app/guides/network-requests#Working-with-GraphQL export const aliasQuery = (req: IncomingHttpRequest, operation: string, responseBody: unknown) => { + requestHandler(req) + if (!hasOperation(req, operation)) { + req.alias = 'Continue' req.continue() return }