Skip to content

Commit

Permalink
refactoring approach for login in cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
codyseibert committed Jun 28, 2023
1 parent 6ebadf2 commit 7666ef2
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 236 deletions.
25 changes: 24 additions & 1 deletion cypress-smoketests.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import { defineConfig } from 'cypress';

import {
confirmUser,
getRestApi,
getUserToken,
} from './cypress/cypress-smoketests/support/login';

const { CYPRESS_SMOKETESTS_LOCAL } = process.env;

import {
getRestApi as getRestApiLocal,
getUserToken as getUserTokenLocal,
} from './cypress/cypress-smoketests/support/pages/local-login';

// eslint-disable-next-line import/no-default-export
export default defineConfig({
chromeWebSecurity: false,
defaultCommandTimeout: 60000,
e2e: {
setupNodeEvents(on) {
on('task', {
confirmUser({ email }) {
return confirmUser({ email });
},
getRestApi() {
return CYPRESS_SMOKETESTS_LOCAL ? getRestApiLocal() : getRestApi();
},
getUserToken({ email, password }) {
return CYPRESS_SMOKETESTS_LOCAL
? getUserTokenLocal(email)
: getUserToken(email, password);
},
log(message) {
console.log(message);

return null;
},
});
Expand Down
42 changes: 22 additions & 20 deletions cypress/cypress-smoketests/integration/case-creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');
let token = null;
let testData = { createdPaperDocketNumber: '' };

const { closeScannerSetupDialog, getUserToken, login } =
getEnvironmentSpecificFunctions();
const { closeScannerSetupDialog, login } = getEnvironmentSpecificFunctions();

describe('Petitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down Expand Up @@ -76,12 +76,13 @@ describe('Petitioner', () => {
});

describe('Private practitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down Expand Up @@ -116,12 +117,13 @@ describe('Private practitioner', () => {
});

describe('Petitions clerk', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down
15 changes: 8 additions & 7 deletions cypress/cypress-smoketests/integration/change-address.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import {
updateAddress1,
} from '../support/pages/my-account';

const { getUserToken, login } = getEnvironmentSpecificFunctions();
const { login } = getEnvironmentSpecificFunctions();

const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');

describe('Private practitioner', () => {
let token = null;

before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('logs in', () => {
Expand Down
42 changes: 22 additions & 20 deletions cypress/cypress-smoketests/integration/court-issued-documents.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ const testData = {};

const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');

const { closeScannerSetupDialog, getUserToken, login } =
getEnvironmentSpecificFunctions();
const { closeScannerSetupDialog, login } = getEnvironmentSpecificFunctions();

describe('Petitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down Expand Up @@ -89,12 +89,13 @@ describe('Petitioner', () => {
});

describe('Petitions clerk', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand All @@ -117,12 +118,13 @@ describe('Petitions clerk', () => {
});

describe('Docket Clerk', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down
45 changes: 26 additions & 19 deletions cypress/cypress-smoketests/integration/create-trial-session.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import { waitForElasticsearch } from '../support/helpers';

const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');

console.log('gg', DEFAULT_ACCOUNT_PASS);

faker.seed(faker.number.int());

let docketClerkToken = null;
Expand All @@ -54,37 +56,42 @@ const testData = {
preferredTrialCity: 'Mobile, Alabama',
trialSessionIds: [],
};
const { login } = getEnvironmentSpecificFunctions();

let firstDocketNumber;
let secondDocketNumber;
const caseTestData = { docketNumbers: [] };

describe('Petitions Clerk', () => {
const { getUserToken, login } = getEnvironmentSpecificFunctions();

before(async () => {
let result = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
petitionsClerkToken = result.AuthenticationResult.IdToken;
result = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
docketClerkToken = result.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
petitionsClerkToken = result.AuthenticationResult.IdToken;
});
});

before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
docketClerkToken = result.AuthenticationResult.IdToken;
});
});

describe('Petitioner creates cases', () => {
let petitionerToken;

describe('Petitioner', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
petitionerToken = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down
55 changes: 29 additions & 26 deletions cypress/cypress-smoketests/integration/search.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ let testData = {};
let token;
const DEFAULT_ACCOUNT_PASS = Cypress.env('DEFAULT_ACCOUNT_PASS');

const { closeScannerSetupDialog, getUserToken, login } =
getEnvironmentSpecificFunctions();
const { closeScannerSetupDialog, login } = getEnvironmentSpecificFunctions();

describe('Create and serve a case to search for', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand All @@ -55,12 +55,13 @@ describe('Create and serve a case to search for', () => {
});

describe('Case Advanced Search', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand All @@ -79,12 +80,13 @@ describe('Case Advanced Search', () => {
});

describe('Practitioner Search', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand All @@ -103,12 +105,13 @@ describe('Practitioner Search', () => {
});

describe('Opinion Search', () => {
before(async () => {
const results = await getUserToken(
'[email protected]',
DEFAULT_ACCOUNT_PASS,
);
token = results.AuthenticationResult.IdToken;
before(() => {
cy.task('getUserToken', {
email: '[email protected]',
password: DEFAULT_ACCOUNT_PASS,
}).then(result => {
token = result.AuthenticationResult.IdToken;
});
});

it('should be able to login', () => {
Expand Down
Loading

0 comments on commit 7666ef2

Please sign in to comment.