Skip to content

Commit

Permalink
feat(DTFS2-7781): add effective from date e2e tests (#4189)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarRobSoftwire authored Feb 4, 2025
1 parent c416b1b commit 15c0470
Show file tree
Hide file tree
Showing 20 changed files with 382 additions and 231 deletions.
12 changes: 12 additions & 0 deletions e2e-tests/gef/cypress/e2e/pages/amendments/effective-date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const effectiveDate = {
effectiveDateDay: () => cy.get('[data-cy="effective-date-day"]'),
effectiveDateMonth: () => cy.get('[data-cy="effective-date-month"]'),
effectiveDateYear: () => cy.get('[data-cy="effective-date-year"]'),
errorSummary: () => cy.get('[data-cy="error-summary"]'),
effectiveDateInlineError: () => cy.get('[data-cy="effective-date-inline-error"]'),
pageHeading: () => cy.get('[data-cy="page-heading"]'),
backLink: () => cy.get('[data-cy="back-link"]'),
cancelLink: () => cy.get('[data-cy="cancel-link"]'),
};

module.exports = effectiveDate;
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ context('Amendments - Change both cover end date and facility value - full journ
cy.clickContinueButton();

cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`));
cy.completeDateFormFields({ idPrefix: 'effective-date' });
cy.clickContinueButton();

// TODO DTFS2-7524: add steps for effective from date
cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`));

// TODO DTFS2-7519: add steps for check your answer page
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ context('Amendments - Change cover end date with bank review date - full journey
cy.clickContinueButton();

cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`));
cy.completeDateFormFields({ idPrefix: 'effective-date' });
cy.clickContinueButton();

// TODO DTFS2-7524: add steps for effective from date
cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`));

// TODO DTFS2-7519: add steps for check your answer page
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ context('Amendments - Change cover end date with facility end date - full journe
cy.clickContinueButton();

cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`));
cy.completeDateFormFields({ idPrefix: 'effective-date' });
cy.clickContinueButton();

// TODO DTFS2-7524: add steps for effective from date
cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`));

// TODO DTFS2-7519: add steps for check your answer page
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ context('Amendments - change facility value - full journey', () => {
cy.clickContinueButton();

cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`));
cy.completeDateFormFields({ idPrefix: 'effective-date' });
cy.clickContinueButton();

// TODO DTFS2-7524: add steps for effective from date
cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`));

// TODO DTFS2-7519: add steps for check your answer page
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import relative from '../../../../relativeURL';
import MOCK_USERS from '../../../../../../../e2e-fixtures/portal-users.fixture';
import { MOCK_APPLICATION_AIN_DRAFT } from '../../../../../../../e2e-fixtures/gef/mocks/mock-deals';
import { anIssuedCashFacility } from '../../../../../../../e2e-fixtures/mock-gef-facilities';
import { applicationPreview } from '../../../../../../../gef/cypress/e2e/pages';
import whatDoYouNeedToChange from '../../../../../../../gef/cypress/e2e/pages/amendments/what-do-you-need-to-change';
import facilityValue from '../../../../../../../gef/cypress/e2e/pages/amendments/facility-value';
import eligibility from '../../../../../../../gef/cypress/e2e/pages/amendments/eligibility';
import effectiveDate from '../../../../../../../gef/cypress/e2e/pages/amendments/effective-date';
import { twoDaysAgo, twoMonths, today } from '../../../../../../../e2e-fixtures/dateConstants';

const { BANK1_MAKER1 } = MOCK_USERS;

context('Amendments - Date amendment effective from - page tests', () => {
/**
* @type {string}
*/
let dealId;

/**
* @type {string}
*/
let facilityId;
/**
* @type {string}
*/
let amendmentId;

before(() => {
cy.insertOneGefDeal(MOCK_APPLICATION_AIN_DRAFT, BANK1_MAKER1).then((insertedDeal) => {
dealId = insertedDeal._id;

cy.updateGefDeal(dealId, MOCK_APPLICATION_AIN_DRAFT, BANK1_MAKER1);

cy.createGefFacilities(dealId, [anIssuedCashFacility({ facilityEndDateEnabled: true })], BANK1_MAKER1).then((createdFacility) => {
facilityId = createdFacility.details._id;

cy.makerLoginSubmitGefDealForReview(insertedDeal);
cy.checkerLoginSubmitGefDealToUkef(insertedDeal);

cy.clearSessionCookies();
cy.login(BANK1_MAKER1);
cy.saveSession();
cy.visit(relative(`/gef/application-details/${dealId}`));

applicationPreview.makeAChangeButton(facilityId).click();

cy.url().then((url) => {
const urlSplit = url.split('/');

amendmentId = urlSplit[9];
});

whatDoYouNeedToChange.facilityValueCheckbox().click();
cy.clickContinueButton();
cy.keyboardInput(facilityValue.facilityValue(), '10000');
cy.clickContinueButton();
eligibility.allTrueRadioButtons().click({ multiple: true });
cy.clickContinueButton();
});
});
});

after(() => {
cy.clearCookies();
cy.clearSessionCookies();
});

beforeEach(() => {
cy.clearSessionCookies();
cy.login(BANK1_MAKER1);
cy.visit(relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`));
});

it('should render key features of the page', () => {
effectiveDate.pageHeading().contains('Date amendment effective from');
effectiveDate.backLink();
effectiveDate.cancelLink();
});

it('should render an error if no date is provided', () => {
cy.clickContinueButton();

effectiveDate.errorSummary().should('be.visible');
effectiveDate.errorSummary().contains('Enter the date amendment effective from');

effectiveDate.effectiveDateInlineError().should('be.visible');
effectiveDate.effectiveDateInlineError().contains('Enter the date amendment effective from');
});

const effectiveDateErrorTestCases = [
{
description: 'the date amendment effective from consists of invalid characters',
dateFieldInput: { day: 'aa', month: '11', year: '2025' },
expectedErrorMessage: 'Date amendment effective from must be a real date',
},
{
description: 'the date amendment effective from is missing a field',
dateFieldInput: { day: '2', month: ' ', year: '2025' },
expectedErrorMessage: 'Date amendment effective from must include a month',
},
{
description: 'the date amendment effective from is greater than 30 days in the future',
dateFieldInput: twoMonths,
expectedErrorMessage: `You entered an amendment date more than 30 days from now. Amendments must be effective within the next 30 days - come back later or use the Schedule 8 form`,
},
{
description: 'the date amendment effective from is before the cover start date',
dateFieldInput: twoDaysAgo,
expectedErrorMessage: `Date amendment effective from cannot be before the cover start date ${today.d_MMMM_yyyy}`,
},
];

effectiveDateErrorTestCases.forEach(({ description, dateFieldInput, expectedErrorMessage }) => {
it(`should render an error on the bank review date page if ${description}`, () => {
cy.completeDateFormFields({ idPrefix: 'effective-date', ...dateFieldInput });
cy.clickContinueButton();

effectiveDate.errorSummary().should('be.visible');
effectiveDate.errorSummary().contains(expectedErrorMessage);
effectiveDate.effectiveDateInlineError().should('be.visible');
effectiveDate.effectiveDateInlineError().contains(expectedErrorMessage);
});
});

it('should navigate to cancel page when cancel is clicked', () => {
eligibility.cancelLink().click();

cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe(`POST ${url}`, () => {
.withDealId(dealId)
.withFacilityId(facilityId)
.withAmendmentId(amendmentId)
.withEffectiveFrom(getUnixTime(today))
.withEffectiveDate(getUnixTime(today))
.build(),
);
});
Expand All @@ -74,9 +74,9 @@ describe(`POST ${url}`, () => {
it('should redirect to /not-found', async () => {
// Arrange
const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand All @@ -96,9 +96,9 @@ describe(`POST ${url}`, () => {
it('should redirect to /not-found', async () => {
// Arrange
const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand All @@ -119,9 +119,9 @@ describe(`POST ${url}`, () => {
makeRequestWithHeaders: (headers: Headers) =>
post(
{
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
},
headers,
).to(url),
Expand All @@ -134,9 +134,9 @@ describe(`POST ${url}`, () => {
mockGetFacility.mockResolvedValue({ details: undefined });

const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand All @@ -151,9 +151,9 @@ describe(`POST ${url}`, () => {
mockGetApplication.mockResolvedValue(undefined);

const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand All @@ -164,9 +164,9 @@ describe(`POST ${url}`, () => {
expect(response.headers.location).toEqual('/not-found');
});

it('should render date amendment effective from page with errors if effective from is invalid', async () => {
it('should render date amendment effective date page with errors if effective date is invalid', async () => {
// Arrange
const body = { 'effective-from-day': '1000', 'effective-from-month': '100', 'effective-from-year': '100' };
const body = { 'effective-date-day': '1000', 'effective-date-month': '100', 'effective-date-year': '100' };

// Act
const response = await postWithSessionCookie(body, sessionCookie);
Expand All @@ -177,9 +177,9 @@ describe(`POST ${url}`, () => {
expect(response.text).toContain('Date amendment effective from must be a real date');
});

it('should render date amendment effective from page with errors if effective from is not provided', async () => {
it('should render date amendment effective date page with errors if effective date is not provided', async () => {
// Arrange
const body = { 'effective-from-day': '', 'effective-from-month': '', 'effective-from-year': '' };
const body = { 'effective-date-day': '', 'effective-date-month': '', 'effective-date-year': '' };

// Act
const response = await postWithSessionCookie(body, sessionCookie);
Expand All @@ -190,12 +190,12 @@ describe(`POST ${url}`, () => {
expect(response.text).toContain('Enter the date amendment effective from');
});

it('should redirect to the next page if the effective from is valid', async () => {
it('should redirect to the next page if the effective date is valid', async () => {
// Arrange
const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand All @@ -213,9 +213,9 @@ describe(`POST ${url}`, () => {
mockGetApplication.mockRejectedValue(new Error('test error'));

const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand All @@ -231,9 +231,9 @@ describe(`POST ${url}`, () => {
mockGetFacility.mockRejectedValue(new Error('test error'));

const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand All @@ -249,9 +249,9 @@ describe(`POST ${url}`, () => {
mockUpdateAmendment.mockRejectedValue(new Error('test error'));

const body = {
'effective-from-day': format(today, 'd'),
'effective-from-month': format(today, 'M'),
'effective-from-year': format(today, 'yyyy'),
'effective-date-day': format(today, 'd'),
'effective-date-month': format(today, 'M'),
'effective-date-year': format(today, 'yyyy'),
};

// Act
Expand Down
Loading

0 comments on commit 15c0470

Please sign in to comment.