Skip to content

Commit

Permalink
feat(EMS-1027): no PDF - account - sign in - verify email after expiry (
Browse files Browse the repository at this point in the history
  • Loading branch information
Zainzzkk authored Jun 4, 2024
1 parent 28d9cd5 commit 2910cb2
Show file tree
Hide file tree
Showing 29 changed files with 577 additions and 180 deletions.
40 changes: 40 additions & 0 deletions e2e-tests/commands/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,21 @@ const queryStrings = {
mutation updateAccount($where: AccountWhereUniqueInput!, $data: AccountUpdateInput!) {
updateAccount(where: $where, data: $data) {
id
verificationExpiry
verificationHash
reactivationHash
passwordResetHash
status {
id
}
}
}
`,
updateAccountStatus: () => gql`
mutation updateAccountStatus($where: AccountStatusWhereUniqueInput!, $data: AccountStatusUpdateInput!) {
updateAccountStatus(where: $where, data: $data) {
id
isInactive
}
}
`,
Expand Down Expand Up @@ -357,6 +369,33 @@ const updateAccount = async (id, updateObj) => {
}
};

/**
* updateAccountStatus
* Update an account status
* @param {String} AccountStatus ID
* @returns {AccountStatus} AccountStatus
*/
const updateAccountStatus = async (id, updateObj) => {
try {
const responseBody = await apollo
.query({
query: queryStrings.updateAccountStatus(),
variables: {
where: { id },
data: updateObj,
},
context: APOLLO_CONTEXT,
})
.then((response) => response.data.updateAccountStatus);

return responseBody;
} catch (err) {
console.error(err);

throw new Error('Updating account status', { err });
}
};

/**
* deleteAnAccount
* Delete an account by email address
Expand Down Expand Up @@ -638,6 +677,7 @@ const api = {
createApplications,
getAccountByEmail,
updateAccount,
updateAccountStatus,
deleteAnAccount,
addAndGetOTP,
getAccountPasswordResetToken,
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/constants/account.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const ACCOUNT = {
MAX_AUTH_RETRIES: 6,
IS_INACTIVE: 'isInactive',
};
7 changes: 4 additions & 3 deletions e2e-tests/content-strings/pages/insurance/account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ const ACCOUNT = {
},
VERIFY_EMAIL_EXPIRED_LINK: {
PAGE_TITLE: 'Your link has expired',
BODY: "You'll need to enter your details and create an account again.",
CREATE_ACCOUNT: {
TEXT: 'Create account',
NOT_VERIFIED: 'Your account has not been verified.',
CAN_SEND_NEW_LINK: 'If you would still like to verify your account we can send you a new link.',
REQUEST_NEW_LINK: {
TEXT: 'Request a new link',
HREF: INSURANCE_ROUTES.ACCOUNT.CREATE.YOUR_DETAILS,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { INSURANCE_ROUTES as ROUTES } from '../../../../../../../constants/routes/insurance';
import api from '../../../../../../../commands/api';
import { ACCOUNT } from '../../../../../../../constants';

const { IS_INACTIVE } = ACCOUNT;

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

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`,
() => {
let url;
let account;

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

cy.navigateToUrl(START);

cy.submitEligibilityAndStartAccountCreation();
cy.completeAndSubmitCreateAccountForm();

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

cy.assertUrl(url);
});

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

describe(`When a verification token has expired and the ${IS_INACTIVE} flag is set and the user navigates to ${VERIFY_EMAIL} with the expired token`, () => {
let updatedAccount;

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 today = new Date();
const lastMonth = new Date(today.setMonth(today.getMonth() - 1));

const updateObj = {
verificationExpiry: lastMonth,
};

updatedAccount = await api.updateAccount(account.id, updateObj);

/**
* Update the account status' isInactive flag via the API,
* so that we can mimic an inactive account.
*/
const updateStatusObj = {
isInactive: true,
};

await api.updateAccountStatus(updatedAccount.status.id, updateStatusObj);
});

it(`should redirect to ${CONFIRM_EMAIL_RESENT} when submitting the form`, () => {
const { verificationHash } = updatedAccount;

const verificationUrl = `${VERIFY_EMAIL}?token=${verificationHash}&id=${account.id}`;

cy.navigateToUrl(`${baseUrl}${verificationUrl}`);

cy.clickSubmitButton();

const expectedUrl = `${baseUrl}${CONFIRM_EMAIL_RESENT}?id=${account.id}`;
cy.assertUrl(expectedUrl);
});
});
},
);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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';

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,
},
},
} = ROUTES;

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

context(
'Insurance - Account - Create - Confirm email page - expired token - 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;

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

cy.navigateToUrl(START);

cy.submitEligibilityAndStartAccountCreation();
cy.completeAndSubmitCreateAccountForm();

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

cy.assertUrl(url);
});

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

describe(`When a verification token has expired and the user navigates to ${VERIFY_EMAIL} with the expired token`, () => {
let updatedAccount;

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 today = new Date();
const lastMonth = new Date(today.setMonth(today.getMonth() - 1));

const updateObj = {
verificationExpiry: lastMonth,
};

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

it(`should redirect to ${VERIFY_EMAIL_EXPIRED_LINK} and render core page elements and content`, () => {
const { verificationHash } = updatedAccount;

const verificationUrl = `${VERIFY_EMAIL}?token=${verificationHash}&id=${account.id}`;

cy.navigateToUrl(`${baseUrl}${verificationUrl}`);

const expectedUrl = `${baseUrl}${VERIFY_EMAIL_EXPIRED_LINK}?id=${account.id}`;

cy.assertUrl(expectedUrl);

cy.corePageChecks({
pageTitle: CONTENT_STRINGS.PAGE_TITLE,
currentHref: verificationUrl,
backLink: `${CONFIRM_EMAIL}?id=${account.id}`,
hasAForm: false,
assertAuthenticatedHeader: false,
submitButtonCopy: CONTENT_STRINGS.REQUEST_NEW_LINK.TEXT,
});

// assert body content
cy.checkText(verifyEmailLinkExpiredPage.notVerified(), CONTENT_STRINGS.NOT_VERIFIED);
cy.checkText(verifyEmailLinkExpiredPage.canSendNewLink(), CONTENT_STRINGS.CAN_SEND_NEW_LINK);
});

it(`should redirect to ${CONFIRM_EMAIL_RESENT} when submitting the form`, () => {
const { verificationHash } = updatedAccount;

const verificationUrl = `${VERIFY_EMAIL}?token=${verificationHash}&id=${account.id}`;

cy.navigateToUrl(`${baseUrl}${verificationUrl}`);

cy.clickSubmitButton();

const expectedUrl = `${baseUrl}${CONFIRM_EMAIL_RESENT}?id=${account.id}`;
cy.assertUrl(expectedUrl);
});
});
},
);
Loading

0 comments on commit 2910cb2

Please sign in to comment.