Skip to content

Commit

Permalink
feat(DTFS2-7720): redirect to check answers page if change query is t…
Browse files Browse the repository at this point in the history
…rue (#4235)
  • Loading branch information
rkontogianni authored Feb 28, 2025
1 parent e8f23c3 commit bdc810b
Show file tree
Hide file tree
Showing 63 changed files with 1,232 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ context('Amendments - Cancel amendment journey', () => {

cy.getAmendmentIdFromUrl().then((amendmentId) => {
amendmentUrl = `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}`;
pageActions(amendmentUrl);
pageActions();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
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 { MOCK_JOURNEYS_WITH_BRD, MOCK_JOURNEYS_WITH_FED } from '../../../../../fixtures/check-your-answers-change-journey';
import { applicationPreview } from '../../../../../../../gef/cypress/e2e/pages';

import whatDoYouNeedToChange from '../../../../../../../gef/cypress/e2e/pages/amendments/what-do-you-need-to-change';
import doYouHaveAFacilityEndDate from '../../../../../../../gef/cypress/e2e/pages/amendments/do-you-have-a-facility-end-date';
import facilityValue from '../../../../../../../gef/cypress/e2e/pages/amendments/facility-value';
import eligibility from '../../../../../../../gef/cypress/e2e/pages/amendments/eligibility';
import checkYourAnswers from '../../../../../../../gef/cypress/e2e/pages/amendments/check-your-answers';
import manualApprovalNeeded from '../../../../../../../gef/cypress/e2e/pages/amendments/manual-approval-needed';

const { BANK1_MAKER1 } = MOCK_USERS;

context('Amendments - Check your answers change journey', () => {
/**
* @type {string}
*/
let dealId;
/**
* @type {string}
*/
let facilityId;
/**
* @type {string}
*/
let amendmentUrl;
/**
* @type {Date}
*/
const mockFacility = anIssuedCashFacility({ facilityEndDateEnabled: true });
const CHANGED_FACILITY_VALUE = '10000';

/**
* This test suite covers the "Check your answers" change journey for amendments.
*/
const setupTest = (testCases, amendmentPageActions, hasFacilityEndDate) => {
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, [mockFacility], 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.getAmendmentIdFromUrl().then((amendmentId) => {
amendmentUrl = `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}`;
amendmentPageActions(hasFacilityEndDate);
});
});
});
});

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

beforeEach(() => {
cy.clearSessionCookies();
cy.login(BANK1_MAKER1);
});

testCases.forEach(({ description, page, nextPage, element, nextElement, checkYourAnswersChangeElement, fragment, nextPageHeading, change }) => {
it(`should navigate back to "Check your answers" page when no changes are made on the ${description} page`, () => {
cy.visit(relative(`${amendmentUrl}/check-your-answers`));
checkYourAnswersChangeElement().click();
cy.url().should('eq', relative(`${amendmentUrl}/${page}/?change=true#${fragment}`));
cy.clickContinueButton();
cy.url().should('eq', relative(`${amendmentUrl}/check-your-answers#${fragment}`));
checkYourAnswers.pageHeading().contains('Check your answers before submitting the amendment request');
});

it(`should navigate back to "Check your answers" page when the Back link is clicked on the ${description} page`, () => {
cy.visit(relative(`${amendmentUrl}/check-your-answers`));
checkYourAnswersChangeElement().click();
cy.url().should('eq', relative(`${amendmentUrl}/${page}/?change=true#${fragment}`));
element.backLink().click();
cy.url().should('eq', relative(`${amendmentUrl}/check-your-answers`));
checkYourAnswers.pageHeading().contains('Check your answers before submitting the amendment request');
});

it(`should navigate through the amendment journey when changes are made on the ${description} page`, () => {
cy.visit(relative(`${amendmentUrl}/check-your-answers`));
checkYourAnswersChangeElement().click();
cy.url().should('eq', relative(`${amendmentUrl}/${page}/?change=true#${fragment}`));
change();
if (nextPage !== 'manual-approval-needed') {
cy.url().should('eq', relative(`${amendmentUrl}/${nextPage}#${fragment}`));
nextElement.pageHeading().contains(nextPageHeading);
} else {
cy.url().should('eq', relative(`${amendmentUrl}/${nextPage}#${fragment}`));
nextElement.pageHeading().contains(nextPageHeading);
manualApprovalNeeded.backLink().click();
eligibility.allTrueRadioButtons().click({ multiple: true });
cy.clickContinueButton();
}
});
});
};

// These are the steps the user follows to amend the facility until they reach the "Check your answers" page.
const amendmentPageActions = (hasFacilityEndDate) => {
whatDoYouNeedToChange.coverEndDateCheckbox().click();
whatDoYouNeedToChange.facilityValueCheckbox().click();
cy.clickContinueButton();

cy.completeDateFormFields({ idPrefix: 'cover-end-date' });
cy.clickContinueButton();

if (hasFacilityEndDate) {
doYouHaveAFacilityEndDate.yesRadioButton().click();
cy.clickContinueButton();
cy.completeDateFormFields({ idPrefix: 'facility-end-date' });
} else {
doYouHaveAFacilityEndDate.noRadioButton().click();
cy.clickContinueButton();
cy.completeDateFormFields({ idPrefix: 'bank-review-date' });
}
cy.clickContinueButton();

cy.keyboardInput(facilityValue.facilityValue(), CHANGED_FACILITY_VALUE);
cy.clickContinueButton();

eligibility.allTrueRadioButtons().click({ multiple: true });
cy.clickContinueButton();

cy.completeDateFormFields({ idPrefix: 'effective-date' });
cy.clickContinueButton();
};

// If the amendmentPageActions function is called with false, the bankReviewDate is enabled in the journey
describe('Bank Review Date Enabled', () => {
setupTest(MOCK_JOURNEYS_WITH_BRD, amendmentPageActions, false);
});
// If the amendmentPageActions function is called with true, the facilityEndDate is enabled in the journey
describe('Facility End Date Endabled', () => {
setupTest(MOCK_JOURNEYS_WITH_FED, amendmentPageActions, true);
});
});
120 changes: 120 additions & 0 deletions e2e-tests/ukef/cypress/fixtures/check-your-answers-change-journey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import coverEndDate from '../../../gef/cypress/e2e/pages/amendments/cover-end-date';
import facilityEndDate from '../../../gef/cypress/e2e/pages/amendments/facility-end-date';
import bankReviewDate from '../../../gef/cypress/e2e/pages/amendments/bank-review-date';
import effectiveDate from '../../../gef/cypress/e2e/pages/amendments/effective-date';
import whatDoYouNeedToChange from '../../../gef/cypress/e2e/pages/amendments/what-do-you-need-to-change';
import doYouHaveAFacilityEndDate from '../../../gef/cypress/e2e/pages/amendments/do-you-have-a-facility-end-date';
import facilityValue from '../../../gef/cypress/e2e/pages/amendments/facility-value';
import eligibility from '../../../gef/cypress/e2e/pages/amendments/eligibility';
import checkYourAnswers from '../../../gef/cypress/e2e/pages/amendments/check-your-answers';
import manualApprovalNeeded from '../../../gef/cypress/e2e/pages/amendments/manual-approval-needed';
import { tomorrow } from '../../../e2e-fixtures/dateConstants';

const ELIGIBILITY_CRITERIA_COUNT = 7;
const NEW_FACILITY_VALUE = '20000';

const MOCK_ELIGIBILITY_TEST_CASES = Array.from({ length: ELIGIBILITY_CRITERIA_COUNT }, (_, index) => ({
description: 'eligibility',
page: 'eligibility',
nextPage: 'manual-approval-needed',
element: eligibility,
nextElement: manualApprovalNeeded,
checkYourAnswersChangeElement: () => checkYourAnswers.eligibilityCriteriaSummaryListTable().eligibilityCriterionChangeLink(index + 1),
fragment: `${index + 1}`,
nextPageHeading: 'This amendment cannot be automatically approved',
change: () => {
eligibility.allFalseRadioButtons().click({ multiple: true });
cy.clickContinueButton();
},
}));

export const MOCK_JOURNEYS_WITH_FED = [
{
description: 'cover end date',
page: 'cover-end-date',
nextPage: 'do-you-have-a-facility-end-date',
element: coverEndDate,
nextElement: doYouHaveAFacilityEndDate,
checkYourAnswersChangeElement: () => checkYourAnswers.amendmentSummaryListTable().coverEndDateChangeLink(),
fragment: 'coverEndDate-day',
nextPageHeading: 'Do you have a facility end date?',
change: () => {
cy.completeDateFormFields({ idPrefix: 'cover-end-date', date: tomorrow.date });
cy.clickContinueButton();
},
},
{
description: 'facility end date',
page: 'facility-end-date',
nextPage: 'facility-value',
element: facilityEndDate,
nextElement: facilityValue,
checkYourAnswersChangeElement: () => checkYourAnswers.amendmentSummaryListTable().facilityEndDateChangeLink(),
fragment: 'facilityEndDate-day',
nextPageHeading: 'New facility value',
change: () => {
cy.completeDateFormFields({ idPrefix: 'facility-end-date', date: tomorrow.date });
cy.clickContinueButton();
},
},
{
description: 'facility value',
page: 'facility-value',
nextPage: 'eligibility',
element: facilityValue,
nextElement: eligibility,
checkYourAnswersChangeElement: () => checkYourAnswers.amendmentSummaryListTable().facilityValueChangeLink(),
fragment: 'facilityValue',
nextPageHeading: 'Eligibility',
change: () => {
cy.keyboardInput(facilityValue.facilityValue(), NEW_FACILITY_VALUE);
cy.clickContinueButton();
},
},
{
description: 'effective date',
page: 'effective-date',
nextPage: 'check-your-answers',
element: effectiveDate,
nextElement: checkYourAnswers,
checkYourAnswersChangeElement: () => checkYourAnswers.effectiveDateSummaryListTable().effectiveDateChangeLink(),
fragment: 'effectiveDate-day',
nextPageHeading: 'Check your answers before submitting the amendment request',
change: () => {
cy.completeDateFormFields({ idPrefix: 'effective-date', date: tomorrow.date });
cy.clickContinueButton();
},
},
...MOCK_ELIGIBILITY_TEST_CASES,
];

export const MOCK_JOURNEYS_WITH_BRD = [
{
description: 'what do you need to change',
page: 'what-do-you-need-to-change',
nextPage: 'cover-end-date',
element: whatDoYouNeedToChange,
nextElement: coverEndDate,
checkYourAnswersChangeElement: () => checkYourAnswers.amendmentSummaryListTable().amendmentOptionsChangeLink(),
fragment: 'amendmentOptions',
nextPageHeading: 'New cover end date',
change: () => {
whatDoYouNeedToChange.facilityValueCheckbox().click();
cy.clickContinueButton();
},
},
{
description: 'bank review date',
page: 'bank-review-date',
nextPage: 'eligibility',
element: bankReviewDate,
nextElement: eligibility,
checkYourAnswersChangeElement: () => checkYourAnswers.amendmentSummaryListTable().bankReviewDateChangeLink(),
fragment: 'bankReviewDate-day',
nextPageHeading: 'Eligibility',
change: () => {
cy.completeDateFormFields({ idPrefix: 'bank-review-date', date: tomorrow.date });
cy.clickContinueButton();
},
},
];
6 changes: 3 additions & 3 deletions gef-ui/api-tests/amendments/bank-review-date.get.api-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const mockGetFacility = jest.fn();
const mockGetApplication = jest.fn();
const mockGetAmendment = jest.fn();

const dealId = '123';
const facilityId = '111';
const amendmentId = '111';
const dealId = '6597dffeb5ef5ff4267e5044';
const facilityId = '6597dffeb5ef5ff4267e5045';
const amendmentId = '6597dffeb5ef5ff4267e5046';

const mockDeal = { ...MOCK_BASIC_DEAL, submissionType: DEAL_SUBMISSION_TYPE.AIN, status: DEAL_STATUS.UKEF_ACKNOWLEDGED };

Expand Down
60 changes: 49 additions & 11 deletions gef-ui/api-tests/amendments/bank-review-date.post.api-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ jest.mock('../../server/middleware/csrf', () => ({
}));

const mockGetFacility = jest.fn();
const mockGetAmendment = jest.fn();
const mockGetApplication = jest.fn();
const mockUpdateAmendment = jest.fn();

const dealId = '123';
const facilityId = '111';
const amendmentId = '111';
const dealId = '6597dffeb5ef5ff4267e5044';
const facilityId = '6597dffeb5ef5ff4267e5045';
const amendmentId = '6597dffeb5ef5ff4267e5046';

const mockDeal = { ...MOCK_BASIC_DEAL, submissionType: DEAL_SUBMISSION_TYPE.AIN, status: DEAL_STATUS.UKEF_ACKNOWLEDGED };

Expand All @@ -46,18 +47,20 @@ describe(`POST ${url}`, () => {
({ sessionCookie } = await storage.saveUserSession([ROLES.MAKER]));
jest.spyOn(api, 'getFacility').mockImplementation(mockGetFacility);
jest.spyOn(api, 'getApplication').mockImplementation(mockGetApplication);
jest.spyOn(api, 'getAmendment').mockImplementation(mockGetAmendment);
jest.spyOn(api, 'updateAmendment').mockImplementation(mockUpdateAmendment);

const amendment = new PortalFacilityAmendmentWithUkefIdMockBuilder()
.withDealId(dealId)
.withFacilityId(facilityId)
.withAmendmentId(amendmentId)
.withBankReviewDate(todayPlusTwoYears)
.build();

mockGetFacility.mockResolvedValue(MOCK_ISSUED_FACILITY);
mockGetApplication.mockResolvedValue(mockDeal);
mockUpdateAmendment.mockResolvedValue(
new PortalFacilityAmendmentWithUkefIdMockBuilder()
.withDealId(dealId)
.withFacilityId(facilityId)
.withAmendmentId(amendmentId)
.withBankReviewDate(todayPlusTwoYears)
.build(),
);
mockGetAmendment.mockResolvedValue(amendment);
mockUpdateAmendment.mockResolvedValue(amendment);
});

afterAll(async () => {
Expand Down Expand Up @@ -146,6 +149,23 @@ describe(`POST ${url}`, () => {
expect(response.headers.location).toEqual('/not-found');
});

it('should redirect to /not-found when amendment not found', async () => {
// Arrange
mockGetAmendment.mockResolvedValue(undefined);

const body = {
'bank-review-date-day': format(todayPlusTwoYears, 'd'),
'bank-review-date-month': format(todayPlusTwoYears, 'M'),
'bank-review-date-year': format(todayPlusTwoYears, 'yyyy'),
};

// Act
const response = await postWithSessionCookie(body, sessionCookie);
// Assert
expect(response.status).toEqual(HttpStatusCode.Found);
expect(response.headers.location).toEqual('/not-found');
});

it('should redirect to /not-found when deal not found', async () => {
// Arrange
mockGetApplication.mockResolvedValue(undefined);
Expand Down Expand Up @@ -244,6 +264,24 @@ describe(`POST ${url}`, () => {
expect(response.text).toContain('Problem with the service');
});

it('should render `problem with service` if getAmendment throws an error', async () => {
// Arrange
mockGetAmendment.mockRejectedValue(new Error('test error'));

const body = {
'bank-review-date-day': format(todayPlusTwoYears, 'd'),
'bank-review-date-month': format(todayPlusTwoYears, 'M'),
'bank-review-date-year': format(todayPlusTwoYears, 'yyyy'),
};

// Act
const response = await postWithSessionCookie(body, sessionCookie);

// Assert
expect(response.status).toEqual(HttpStatusCode.Ok);
expect(response.text).toContain('Problem with the service');
});

it('should render `problem with service` if updateAmendment throws an error', async () => {
// Arrange
mockUpdateAmendment.mockRejectedValue(new Error('test error'));
Expand Down
Loading

0 comments on commit bdc810b

Please sign in to comment.