From 862ac800990400e47a466c9078af69978b4c1255 Mon Sep 17 00:00:00 2001 From: Gustavo Minetoma Date: Fri, 24 Jan 2025 20:41:04 +0900 Subject: [PATCH] test --- .github/workflows/cypress.yml | 10 ++++++---- test/cypress/e2e/moderationDashboard.cy.ts | 8 ++++---- test/cypress/e2e/moderationEditFacility.cy.ts | 4 ++-- .../e2e/moderationEditHealthcareProfessional.cy.ts | 4 ++-- test/cypress/utils.ts | 10 ++++++++++ 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 4f36dd98..382ce2bb 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -36,10 +36,12 @@ jobs: - name: Run Cypress tests uses: cypress-io/github-action@v6 - env: - AUTH0_DOMAIN: https://findadoc.jp.auth0.com/ - AUTH0_USERNAME: findadoctest@proton.me - AUTH0_PASSWORD: vCnL5J8agHg6m2f + with: + command: yarn test:e2e + # env: + # AUTH0_DOMAIN: https://findadoc.jp.auth0.com/ + # AUTH0_USERNAME: findadoctest@proton.me + # AUTH0_PASSWORD: vCnL5J8agHg6m2f - name: Upload screenshots uses: actions/upload-artifact@v3 diff --git a/test/cypress/e2e/moderationDashboard.cy.ts b/test/cypress/e2e/moderationDashboard.cy.ts index 554c9102..6be7cd66 100644 --- a/test/cypress/e2e/moderationDashboard.cy.ts +++ b/test/cypress/e2e/moderationDashboard.cy.ts @@ -8,7 +8,7 @@ before(() => { describe('Moderation dashboard', () => { before(() => { - cy.intercept('POST', '*', req => { + cy.intercept('POST', '**/', req => { aliasQuery(req, 'query Submissions', fakeSubmissionResponse) }) @@ -111,7 +111,7 @@ describe('Moderation dashboard', () => { describe('Moderation Edit Submission Form', () => { context('Landscape mode', () => { before(() => { - cy.intercept('POST', '*', req => { + cy.intercept('POST', '**/', req => { aliasQuery(req, 'query Submissions', fakeSubmissionResponse) }) @@ -168,7 +168,7 @@ describe('Moderation Edit Submission Form', () => { cy.get('[data-testid="submission-form-locales"]').should('exist') }) - it('should autofill the form', function() { + it('should autofill the form', () => { const submission = fakeSubmissionResponse.data.submissions[1].facility cy.get('[data-testid="submission-form-nameEn"]').find('input') @@ -274,7 +274,7 @@ describe('Moderation Edit Submission Modal', () => { beforeEach(() => { cy.viewport('macbook-16') - cy.intercept('POST', '*', req => { + cy.intercept('POST', '**/', req => { aliasQuery(req, 'query Submissions', fakeSubmissionResponse) }) diff --git a/test/cypress/e2e/moderationEditFacility.cy.ts b/test/cypress/e2e/moderationEditFacility.cy.ts index d9552029..80b1eb07 100644 --- a/test/cypress/e2e/moderationEditFacility.cy.ts +++ b/test/cypress/e2e/moderationEditFacility.cy.ts @@ -8,8 +8,8 @@ before(() => { describe('Moderation edit facility form', () => { context('Landscape mode', () => { - before(function() { - cy.intercept('POST', '*', req => { + before(() => { + cy.intercept('POST', '**/', req => { aliasQuery(req, 'query Facilities', fakeFacilityResult) }) diff --git a/test/cypress/e2e/moderationEditHealthcareProfessional.cy.ts b/test/cypress/e2e/moderationEditHealthcareProfessional.cy.ts index b904bae7..50158665 100644 --- a/test/cypress/e2e/moderationEditHealthcareProfessional.cy.ts +++ b/test/cypress/e2e/moderationEditHealthcareProfessional.cy.ts @@ -7,10 +7,10 @@ before(() => { describe('Moderation edit professional healthcare form', () => { context('Landscape mode', () => { - before(function() { + before(() => { cy.viewport('macbook-16') - cy.intercept('POST', '*', req => { + cy.intercept('POST', '**/', req => { aliasQuery(req, 'HealthcareProfessionalSearchFilters', fakeHealthcareProfessionalResult) }) diff --git a/test/cypress/utils.ts b/test/cypress/utils.ts index 77f908c7..dc19033a 100644 --- a/test/cypress/utils.ts +++ b/test/cypress/utils.ts @@ -20,8 +20,18 @@ 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.continue() return