Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DTFS2-7781): add effective from date e2e tests #4189

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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
});
Original file line number Diff line number Diff line change
@@ -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
});
Original file line number Diff line number Diff line change
@@ -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
});
Original file line number Diff line number Diff line change
@@ -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
});
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
@@ -55,7 +55,7 @@
.withDealId(dealId)
.withFacilityId(facilityId)
.withAmendmentId(amendmentId)
.withEffectiveFrom(getUnixTime(today))
.withEffectiveDate(getUnixTime(today))

Check failure on line 58 in gef-ui/api-tests/amendments/effective-date.post.api-test.ts

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/effective-date.post.api-test.ts#L58

Unsafe call of an `error` type typed value.
.build(),
);
});
@@ -74,9 +74,9 @@
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'),

Check failure on line 77 in gef-ui/api-tests/amendments/effective-date.post.api-test.ts

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/effective-date.post.api-test.ts#L77

Unsafe assignment of an error typed value.

Check failure on line 77 in gef-ui/api-tests/amendments/effective-date.post.api-test.ts

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/effective-date.post.api-test.ts#L77

Unsafe call of an `error` type typed value.
'effective-date-month': format(today, 'M'),

Check failure on line 78 in gef-ui/api-tests/amendments/effective-date.post.api-test.ts

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/effective-date.post.api-test.ts#L78

Unsafe assignment of an error typed value.

Check failure on line 78 in gef-ui/api-tests/amendments/effective-date.post.api-test.ts

Codacy Production / Codacy Static Code Analysis

gef-ui/api-tests/amendments/effective-date.post.api-test.ts#L78

Unsafe call of an `error` type typed value.
'effective-date-year': format(today, 'yyyy'),
};

// Act
@@ -96,9 +96,9 @@
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
@@ -119,9 +119,9 @@
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),
@@ -134,9 +134,9 @@
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
@@ -151,9 +151,9 @@
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
@@ -164,9 +164,9 @@
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);
@@ -177,9 +177,9 @@
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);
@@ -190,12 +190,12 @@
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
@@ -213,9 +213,9 @@
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
@@ -231,9 +231,9 @@
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
@@ -249,9 +249,9 @@
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
Loading
Loading