Skip to content

Commit

Permalink
feat(EMS-1027): no pdf - account sign in, creation - unverified email…
Browse files Browse the repository at this point in the history
… enhancements (#2540)

* feat(EMS-1027): no pdf - account sign in - resend verification email if unverified

* feat(EMS-1027): account creation - resend verification email if exisiting unverified account

* feat(EMS-1027): no pdf - account creation - e2e tests

* feat(EMS-1027): fix linting issues

* feat(EMS-1027): fix linting issues

* feat(EMS-1027): fix/update unit tests

* feat(EMS-1027): no pdf - account sign in - mark account is inActive=false after generating otp

* feat(EMS-1027): no pdf - account creation - render 'account exists' validation errors

* feat(EMS-1027): fix typo

* feat(EMS-1027): address todo comment

* feat(EMS-1027): remove commented code

* feat(EMS-1027): fix linting issues

* feat(EMS-1027): documentation improvements

* feat(EMS-1027): fix/update create an account cypress command
  • Loading branch information
ttbarnes authored Jun 6, 2024
1 parent ea2ceb1 commit e85b2f8
Show file tree
Hide file tree
Showing 107 changed files with 1,642 additions and 804 deletions.
4 changes: 2 additions & 2 deletions e2e-tests/commands/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const queryStrings = {
mutation createAnAccount($urlOrigin: String!, $firstName: String!, $lastName: String!, $email: String!, $password: String!) {
createAnAccount(urlOrigin: $urlOrigin, firstName: $firstName, lastName: $lastName, email: $email, password: $password) {
success
alreadyExists
isVerified
id
firstName
lastName
email
verificationHash
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ const {
},
} = INSURANCE_ROUTES;

export default (params) => {
const completeAndSubmitCreateAccountForm = (params) => {
if (params?.navigateToAccountCreationPage) {
cy.navigateToUrl(YOUR_DETAILS);
}

cy.keyboardInput(field(FIRST_NAME).input(), account[FIRST_NAME]);
cy.keyboardInput(field(LAST_NAME).input(), account[LAST_NAME]);
cy.keyboardInput(field(EMAIL).input(), account[EMAIL]);
cy.keyboardInput(passwordField.input(), account[PASSWORD]);

const passwordValue = (params && params[PASSWORD]) || account[PASSWORD];

cy.keyboardInput(passwordField.input(), passwordValue);

cy.clickSubmitButton();
};

export default completeAndSubmitCreateAccountForm;
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { INSURANCE_ROUTES } from '../../../constants/routes/insurance';
import account from '../../../fixtures/account';

const {
ACCOUNT: {
EMAIL,
PASSWORD,
},
ACCOUNT: { EMAIL, PASSWORD },
} = INSURANCE_FIELD_IDS;

const {
Expand All @@ -27,19 +24,16 @@ const baseUrl = Cypress.config('baseUrl');
* - password
* - assertSuccessUrl
*/
const completeAndSubmitSignInAccountForm = ({
emailAddress = account[EMAIL],
password = account[PASSWORD],
assertRedirectUrl = true,
}) => {
const completeAndSubmitSignInAccountForm = ({ emailAddress = account[EMAIL], password = account[PASSWORD], assertRedirectUrl = true }) => {
cy.keyboardInput(field(EMAIL).input(), emailAddress);
cy.keyboardInput(passwordField.input(), password);

cy.clickSubmitButton();

if (assertRedirectUrl) {
// assert we are on the 'enter code' page'
// assert we are on the 'enter code' page
const expectedUrl = `${baseUrl}${ENTER_CODE}`;

cy.assertUrl(expectedUrl);
}
};
Expand Down
7 changes: 5 additions & 2 deletions e2e-tests/content-strings/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,17 @@ export const ERROR_MESSAGES = {
[FIELD_IDS.INSURANCE.ACCOUNT.LAST_NAME]: {
IS_EMPTY: 'Enter your last name',
},
ACCOUNT_ALREADY_EXISTS: 'There is already an account with this email address. Please sign in or reset your password',
[FIELD_IDS.INSURANCE.ACCOUNT.EMAIL]: {
IS_EMPTY: 'Enter an email address in the correct format, like name@example.com',
INCORRECT_FORMAT: 'Enter an email address in the correct format, like name@example.com',
ABOVE_MAXIMUM: `Your email address cannot be more than ${MAXIMUM_CHARACTERS.EMAIL} characters`,
ACCOUNT_ALREADY_EXISTS: 'There is already an account with this email address. Please sign in or reset your password',
ACCOUNT_ALREADY_EXISTS_INCORRECT: "Email address - either the email address or password you've entered is incorrect",
},
[FIELD_IDS.INSURANCE.ACCOUNT.PASSWORD]: {
INCORRECT_FORMAT: 'Enter a password in the correct format - for example, 14 characters long with an uppercase letter, lower case letter, number and special character',
INCORRECT_FORMAT:
'Enter a password in the correct format - for example, 14 characters long with an uppercase letter, lower case letter, number and special character',
ACCOUNT_ALREADY_EXISTS_INCORRECT: "Password - either the email address or password you've entered is incorrect",
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions e2e-tests/helpers/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ export const createTimestampFromNumbers = (day, month, year) => new Date(`${mont
* @returns {String} Formatted date
*/
export const formatDate = (timestamp, dateFormat = DATE_FORMAT.DEFAULT) => format(new Date(timestamp), dateFormat);

/**
* createDateOneMonthInThePast
* Create a date that is one month in the past.
* @returns {String} Date one month in the past
*/
export const createDateOneMonthInThePast = () => {
const today = new Date();

const lastMonth = new Date(today.setMonth(today.getMonth() - 1));

return lastMonth;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { INSURANCE_ROUTES as ROUTES } from '../../../../../../../constants/routes/insurance';
import api from '../../../../../../../commands/api';
import { ACCOUNT } from '../../../../../../../constants';
import api from '../../../../../../../commands/api';
import { createDateOneMonthInThePast } from '../../../../../../../helpers/date';

const { IS_INACTIVE } = ACCOUNT;

Expand All @@ -14,7 +15,7 @@ const {
const baseUrl = Cypress.config('baseUrl');

context(
`Insurance - Account - Create - Confirm email page - expired token and ${IS_INACTIVE} flag set - As an Exporter I want to verify my email address for account creation, So that I can activate my email address and use it to create a digital service account with UKEF`,
`Insurance - Account - Create - Confirm email page - expired verification and ${IS_INACTIVE} flag set - As an Exporter I want to verify my email address for account creation, So that I can activate my email address and use it to create a digital service account with UKEF`,
() => {
let url;
let account;
Expand Down Expand Up @@ -55,11 +56,8 @@ context(
* Update the account's verification expiry date via the API,
* so that we can mimic missing the verification period.
*/
const today = new Date();
const lastMonth = new Date(today.setMonth(today.getMonth() - 1));

const updateObj = {
verificationExpiry: lastMonth,
verificationExpiry: createDateOneMonthInThePast(),
};

updatedAccount = await api.updateAccount(account.id, updateObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { PAGES } from '../../../../../../../content-strings';
import { verifyEmailLinkExpiredPage } from '../../../../../../../pages/insurance/account/create';
import { INSURANCE_ROUTES as ROUTES } from '../../../../../../../constants/routes/insurance';
import api from '../../../../../../../commands/api';
import { createDateOneMonthInThePast } from '../../../../../../../helpers/date';

const CONTENT_STRINGS = PAGES.INSURANCE.ACCOUNT.CREATE.VERIFY_EMAIL_EXPIRED_LINK;

const {
START,
ACCOUNT: {
CREATE: {
CONFIRM_EMAIL, VERIFY_EMAIL, VERIFY_EMAIL_EXPIRED_LINK, CONFIRM_EMAIL_RESENT,
CONFIRM_EMAIL,
VERIFY_EMAIL,
VERIFY_EMAIL_EXPIRED_LINK,
CONFIRM_EMAIL_RESENT,
},
},
} = ROUTES;
Expand Down Expand Up @@ -58,11 +62,8 @@ context(
* Update the account's verification expiry date via the API,
* so that we can mimic missing the verification period.
*/
const today = new Date();
const lastMonth = new Date(today.setMonth(today.getMonth() - 1));

const updateObj = {
verificationExpiry: lastMonth,
verificationExpiry: createDateOneMonthInThePast(),
};

updatedAccount = await api.updateAccount(account.id, updateObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { INSURANCE_ROUTES as ROUTES } from '../../../../../../../constants/route

const {
START,
ACCOUNT: { CREATE: { CONFIRM_EMAIL, CONFIRM_EMAIL_RESENT } },
ACCOUNT: {
CREATE: { CONFIRM_EMAIL, CONFIRM_EMAIL_RESENT },
},
} = ROUTES;

const baseUrl = Cypress.config('baseUrl');
Expand All @@ -30,7 +32,7 @@ context('Insurance - Account - Create - Resend confirm email page - Go back to c
beforeEach(() => {
/**
* Get the account ID directly from the API,
* so that we can assert that the URL and `request a new link` has the correct ID.
* so that we can assert that the URLs have the correct ID.
*/
const accountEmail = Cypress.env('GOV_NOTIFY_EMAIL_RECIPIENT_1');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { field as fieldSelector } from '../../../../../../../pages/shared';
import { ERROR_MESSAGES } from '../../../../../../../content-strings';
import { INSURANCE_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance';
import { ACCOUNT as ACCOUNT_ROUTES } from '../../../../../../../constants/routes/insurance/account';
import mockAccount from '../../../../../../../fixtures/account';

const {
CREATE: { YOUR_DETAILS },
} = ACCOUNT_ROUTES;

const {
ACCOUNT: { EMAIL, PASSWORD },
} = INSURANCE_FIELD_IDS;

const {
INSURANCE: {
ACCOUNT: {
CREATE: { YOUR_DETAILS: YOUR_DETAILS_ERROR_MESSAGES },
},
},
} = ERROR_MESSAGES;

const invalidPassword = `${mockAccount[PASSWORD]}-invalid`;

const baseUrl = Cypress.config('baseUrl');

context(
'Insurance - Account - Create - Your details page - Account already exists - unverified - invalid password - As an Exporter, I want the system to verify that the email address that I register against my UKEF digital service account is unique, So that I can be sure that the system does not have multiple digital service accounts with the same email address',
() => {
let url;

before(() => {
cy.deleteAccount();

url = `${baseUrl}${YOUR_DETAILS}`;

cy.navigateToUrl(url);

// create an account
cy.completeAndSubmitCreateAccountForm();
});

beforeEach(() => {
cy.saveSession();
});

describe('when trying to create an account with an email that already has an account and the provided password is incorrect', () => {
beforeEach(() => {
cy.navigateToUrl(url);

cy.completeAndSubmitCreateAccountForm({
[PASSWORD]: invalidPassword,
});
});

it(`should render an ${EMAIL} validation error`, () => {
cy.submitAndAssertFieldErrors({
field: fieldSelector(EMAIL),
value: mockAccount[EMAIL],
expectedErrorsCount: 2,
expectedErrorMessage: YOUR_DETAILS_ERROR_MESSAGES[EMAIL].ACCOUNT_ALREADY_EXISTS_INCORRECT,
});
});

it(`should render an ${PASSWORD} validation error`, () => {
cy.submitAndAssertFieldErrors({
field: fieldSelector(PASSWORD),
value: invalidPassword,
errorIndex: 1,
expectedErrorsCount: 2,
expectedErrorMessage: YOUR_DETAILS_ERROR_MESSAGES[PASSWORD].ACCOUNT_ALREADY_EXISTS_INCORRECT,
});
});
});
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ACCOUNT as ACCOUNT_ROUTES } from '../../../../../../../constants/routes/insurance/account';
import api from '../../../../../../../commands/api';
import { createDateOneMonthInThePast } from '../../../../../../../helpers/date';

const {
CREATE: { YOUR_DETAILS, CONFIRM_EMAIL },
} = ACCOUNT_ROUTES;

const baseUrl = Cypress.config('baseUrl');

context(
'Insurance - Account - Create - Your details page - Account already exists - unverified - valid password - As an Exporter, I want the system to verify that the email address that I register against my UKEF digital service account is unique, So that I can be sure that the system does not have multiple digital service accounts with the same email address',
() => {
const yourDetailsUrl = `${baseUrl}${YOUR_DETAILS}`;
const confirmEmailUrl = `${baseUrl}${CONFIRM_EMAIL}`;
let account;

before(() => {
cy.deleteAccount();

cy.navigateToUrl(yourDetailsUrl);

// create an account
cy.completeAndSubmitCreateAccountForm();
});

describe('when trying to create an account with an email that already has an account and the provided password is correct', () => {
beforeEach(async () => {
/**
* Get the account so that we can use the ID
* to update the verification period.
*/
const accountEmail = Cypress.env('GOV_NOTIFY_EMAIL_RECIPIENT_1');

const accountsResponse = await api.getAccountByEmail(accountEmail);

const [firstAccount] = accountsResponse;
account = firstAccount;

/**
* Update the account's verification expiry date via the API,
* so that we can mimic missing the verification period.
*/
const updateObj = {
verificationExpiry: createDateOneMonthInThePast(),
};

await api.updateAccount(account.id, updateObj);
});

it(`should redirect to ${CONFIRM_EMAIL}`, () => {
cy.navigateToUrl(yourDetailsUrl);

cy.completeAndSubmitCreateAccountForm();

cy.assertUrl(confirmEmailUrl);
});
});
},
);
Loading

0 comments on commit e85b2f8

Please sign in to comment.