Skip to content

Commit

Permalink
feat: refactoring e2e tests to use mock login
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Jan 8, 2021
1 parent 8fd9a31 commit 31b19de
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ describe('When logged in as an admin', () => {
cy.deployProdData();
// The admin spec uses the same setup as the analyst
cy.sqlFixture('fixtures/analyst-all-access-setup');
cy.login(
Cypress.env('TEST_ADMIN_USERNAME'),
Cypress.env('TEST_ADMIN_PASSWORD')
);
cy.mockLogin('admin');
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ describe('When logged in as an analyst', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/analyst-all-access-setup');
cy.login(
Cypress.env('TEST_ANALYST_USERNAME'),
Cypress.env('TEST_ANALYST_PASSWORD')
);
cy.mockLogin('analyst');
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ describe('When logged in as a certifier(reporter)', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/certifier-access-setup');
cy.login(
Cypress.env('TEST_CERTIFIER_USERNAME'),
Cypress.env('TEST_CERTIFIER_PASSWORD')
);
cy.mockLogin('certifier');
cy.useMockedTime(new Date(2020, 5, 10, 9, 0, 0, 0)); //May 10th at 9am
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ describe('When logged in as a reporter', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/reporter-all-access-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});

afterEach(() => {
Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/admin-access-all-pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ describe('When logged in as an admin', () => {
cy.cleanSchema();
// The admin spec uses the same setup as the analyst
cy.sqlFixture('fixtures/analyst-all-access-setup');
cy.login(
Cypress.env('TEST_ADMIN_USERNAME'),
Cypress.env('TEST_ADMIN_PASSWORD')
);
cy.mockLogin('admin');
});

afterEach(() => {
Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/analyst-diffing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ describe('When reviewing a submitted application as an analyst', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/analyst-diffing-setup');
cy.login(
Cypress.env('TEST_ANALYST_USERNAME'),
Cypress.env('TEST_ANALYST_PASSWORD')
);
cy.mockLogin('analyst');
cy.visit(
'/analyst/application-review?applicationId=WyJhcHBsaWNhdGlvbnMiLDFd&applicationRevisionId=WyJhcHBsaWNhdGlvbl9yZXZpc2lvbnMiLDEsMl0%3D&version=2'
);
Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/application-form-validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ describe('When reviewing a submitted application as an analyst', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/form-validation-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});

afterEach(() => {
Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/application-production.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ describe('The production tab', () => {
});
beforeEach(() => {
cy.sqlFixture('fixtures/production-draft-form-result-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
const applicationId = window.btoa('["applications", 1]');
const formResultId = window.btoa('["form_results", 4]');
cy.visit(
Expand Down
25 changes: 5 additions & 20 deletions app/cypress/integration/email.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ describe('Organisation access request emails', () => {
beforeEach(() => {
cy.cleanSchema();
cy.sqlFixture('fixtures/email/org-access-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
cy.request('DELETE', 'localhost:8025/api/v1/messages');
});
afterEach(() => {
Expand Down Expand Up @@ -136,10 +133,7 @@ describe('Draft application started email', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/email/draft-application-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
cy.request('DELETE', 'localhost:8025/api/v1/messages');
cy.wait(500);
});
Expand Down Expand Up @@ -181,10 +175,7 @@ describe('Certification & Confirmation emails', () => {
cy.sqlFixture('fixtures/email-setup');
});
beforeEach(() => {
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});
after(() => {
cy.wait(1000);
Expand Down Expand Up @@ -310,10 +301,7 @@ describe('Certification email opt-out', () => {
cy.sqlFixture('fixtures/email-setup');
});
beforeEach(() => {
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});
after(() => {
cy.wait(1000);
Expand Down Expand Up @@ -362,10 +350,7 @@ describe('Application status change emails', () => {
cy.deployProdData();
cy.sqlFixture('fixtures/email/status-change-setup');
cy.request('DELETE', 'localhost:8025/api/v1/messages');
cy.login(
Cypress.env('TEST_ANALYST_USERNAME'),
Cypress.env('TEST_ANALYST_PASSWORD')
);
cy.mockLogin('analyst');
cy.wait(500);
});
afterEach(() => {
Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/form-errors-prevent-submit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ describe('When logged in as a reporter', () => {
cy.cleanSchema();
cy.deployProdData();
cy.logout();
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
cy.sqlFixture('fixtures/form-errors-prevent-submit-setup');
});

Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/login-redirects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ function testRedirectsForScopedPages(scope, pages) {
cy.url().should('include', '/login-redirect');
cy.url().should('include', `?redirectTo=${encodeURIComponent(url)}`);

cy.login(
Cypress.env[`TEST_${scope.toUpperCase()}_USERNAME`],
Cypress.env[`TEST_${scope.toUpperCase()}_PASSWORD`]
);
cy.mockLogin(scope);

// As the SSO login page won't open in a frame in Cypress, the final redirect must be
// tested indirectly as though we're following the auth callback:
Expand Down
25 changes: 5 additions & 20 deletions app/cypress/integration/override-justification.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ describe('When an applicaiton has errors', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/override-justification-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});

after(() => {
Expand Down Expand Up @@ -54,10 +51,7 @@ describe('When an applicaiton has errors', () => {
});

it('The certifier should see the override notification', () => {
cy.login(
Cypress.env('TEST_CERTIFIER_USERNAME'),
Cypress.env('TEST_CERTIFIER_PASSWORD')
);
cy.mockLogin('certifier');
const applicationId = window.btoa('["applications", 1]');
cy.visit(`/certifier/certify?applicationId=${applicationId}&version=1`);
cy.url().should('include', '/certifier/certify');
Expand All @@ -69,10 +63,7 @@ describe('When an applicaiton has errors', () => {
});

it('The reporter should see their override justification and be able to submit', () => {
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
const applicationId = window.btoa('["applications", 1]');
cy.visit(
`/reporter/application?applicationId=${applicationId}&confirmationPage=true&version=1`
Expand All @@ -86,10 +77,7 @@ describe('When an applicaiton has errors', () => {
});

it('The analyst should see the override notification', () => {
cy.login(
Cypress.env('TEST_ANALYST_USERNAME'),
Cypress.env('TEST_ANALYST_PASSWORD')
);
cy.mockLogin('analyst');
const applicationRevisionId = window.btoa(
'["application_revisions", 1, 1]'
);
Expand All @@ -111,10 +99,7 @@ describe('When an applicaiton does not have errors', () => {
cy.deployProdData();
cy.sqlFixture('fixtures/reporter-all-access-setup');
cy.sqlFixture('fixtures/set-legal-disclaimer-true');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});

afterEach(() => {
Expand Down
15 changes: 3 additions & 12 deletions app/cypress/integration/page-access.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ describe('When logged in as a reporter', () => {
beforeEach(() => {
cy.cleanSchema();
cy.sqlFixture('dev/user');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});

afterEach(() => cy.logout());
Expand All @@ -19,10 +16,7 @@ describe('When logged in as a reporter', () => {

describe('When logged in as an analyst', () => {
before(() => {
cy.login(
Cypress.env('TEST_ANALYST_USERNAME'),
Cypress.env('TEST_ANALYST_PASSWORD')
);
cy.mockLogin('analyst');
});

after(() => cy.logout());
Expand All @@ -36,10 +30,7 @@ describe('When logged in as an analyst', () => {

describe('When logged in as an admin', () => {
before(() => {
cy.login(
Cypress.env('TEST_ADMIN_USERNAME'),
Cypress.env('TEST_ADMIN_PASSWORD')
);
cy.mockLogin('admin');
});

after(() => cy.logout());
Expand Down
20 changes: 4 additions & 16 deletions app/cypress/integration/product-benchmark.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ describe('The products and benchmark page', () => {
cy.logout();
cy.cleanSchema();
cy.sqlFixture('fixtures/products-benchmarks-setup');
cy.login(
Cypress.env('TEST_ADMIN_USERNAME'),
Cypress.env('TEST_ADMIN_PASSWORD')
);
cy.mockLogin('admin');
cy.visit('/admin/products-benchmarks');
cy.get('#page-content');
});
Expand Down Expand Up @@ -34,10 +31,7 @@ describe('The benchmark modal', () => {
cy.logout();
cy.cleanSchema();
cy.sqlFixture('fixtures/products-benchmarks-setup');
cy.login(
Cypress.env('TEST_ADMIN_USERNAME'),
Cypress.env('TEST_ADMIN_PASSWORD')
);
cy.mockLogin('admin');
cy.visit('/admin/products-benchmarks');
cy.get('#page-content');
});
Expand Down Expand Up @@ -103,10 +97,7 @@ describe('The linking modal', () => {
cy.logout();
cy.cleanSchema();
cy.sqlFixture('fixtures/products-benchmarks-setup');
cy.login(
Cypress.env('TEST_ADMIN_USERNAME'),
Cypress.env('TEST_ADMIN_PASSWORD')
);
cy.mockLogin('admin');
cy.visit('/admin/products-benchmarks');
cy.get('#page-content');
});
Expand Down Expand Up @@ -146,10 +137,7 @@ describe('The Create Product modal', () => {
cy.logout();
cy.cleanSchema();
cy.sqlFixture('fixtures/products-benchmarks-setup');
cy.login(
Cypress.env('TEST_ADMIN_USERNAME'),
Cypress.env('TEST_ADMIN_PASSWORD')
);
cy.mockLogin('admin');
cy.visit('/admin/products-benchmarks');
cy.get('#page-content');
});
Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/reporter-access-all-pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ describe('When logged in as a reporter', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/reporter-all-access-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});

afterEach(() => {
Expand Down
5 changes: 1 addition & 4 deletions app/cypress/integration/reporter-certifier-access.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ describe('When logged in as a certifier(reporter)', () => {
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/certifier-access-setup');
cy.login(
Cypress.env('TEST_CERTIFIER_USERNAME'),
Cypress.env('TEST_CERTIFIER_PASSWORD')
);
cy.mockLogin('certifier');
cy.useMockedTime(new Date(2020, 5, 10, 9, 0, 0, 0)); //May 10th at 9am
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ describe('When the reporter is viewing a list of facilities & applications', ()
cy.cleanSchema();
cy.deployProdData();
cy.sqlFixture('fixtures/reporter-all-access-setup');
cy.login(
Cypress.env('TEST_REPORTER_USERNAME'),
Cypress.env('TEST_REPORTER_PASSWORD')
);
cy.mockLogin('reporter');
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/server/postgraphile/authenticationPgSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const authenticationPgSettings = (req) => {
};
}

if (AS_PENDING || allowCypressForRole('pending', req)) {
if (AS_PENDING || allowCypressForRole('user', req)) {
return {
'jwt.claims.sub': '00000000-0000-0000-0000-000000000000',
'jwt.claims.user_groups': 'Pending Analyst',
Expand Down
2 changes: 1 addition & 1 deletion docs/stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ A `cypress.env.json` file is available on the CAS Scrum team SharePoint (TODO: S
- Start the database
- Deploy the development data using `.bin/deploy-data.sh -p -dev`
- Start the application using your favorite command. On CI, it will run it in production mode, with auth enabled. While developing, however, you can run `yarn dev NO_AUTH` in most cases
- The feature flag `yarn dev NO_MATHJAX` is available for running Cypress tests
- The feature flag `yarn dev NO_MATHJAX AS_CYPRESS` is available for running Cypress tests
- These flags block mathjax components that often cause a false failed response from the e2e tests.
- Run `yarn cypress` to open the Cypress UI

Expand Down

0 comments on commit 31b19de

Please sign in to comment.