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-7621): add amendments url helper #4141

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { validationErrorHandler } from '../../../server/utils/helpers';
import pageRenderer from '../../pageRenderer';
abhi-markan marked this conversation as resolved.
Show resolved Hide resolved
import { WhatNeedsToChangeViewModel } from '../../../server/types/view-models/amendments/what-needs-to-change-view-model.ts';

const page = 'partials/amendments/what-needs-to-change.njk';
const render = pageRenderer(page);

describe(page, () => {
const previousPage = 'previousPage';
const cancelUrl = 'cancelUrl';
const exporterName = 'exporterName';
const amendmentFormEmail = 'amendmentFormEmail';

const params: WhatNeedsToChangeViewModel = {
previousPage,
cancelUrl,
amendmentFormEmail,
exporterName,
};

it('should render the page heading', () => {
const wrapper = render(params);

wrapper.expectText('[data-cy="page-heading"]').toRead('What do you need to change?');
});

it('should render the exporter name in the heading caption', () => {
const wrapper = render(params);

wrapper.expectText('[data-cy="heading-caption"]').toRead(exporterName);
});

it(`should render the 'Back' link`, () => {
const wrapper = render(params);

wrapper.expectLink('[data-cy="back-link"]').toLinkTo(previousPage, 'Back');
});

it('should render the amendment selection checkboxes unchecked', () => {
const wrapper = render(params);

wrapper.expectInput('[data-cy="cover-end-date-checkbox"]').toNotBeChecked();
wrapper.expectInput('[data-cy="facility-value-checkbox"]').toNotBeChecked();
});

it(`should render the continue button`, () => {
const wrapper = render(params);

wrapper.expectPrimaryButton('[data-cy="continue-button"]').toLinkTo(undefined, 'Continue');
});

it(`should render the cancel link`, () => {
const wrapper = render(params);

wrapper.expectLink('[data-cy="cancel-link"]').toLinkTo(cancelUrl, 'Cancel');
});

it('should render the warning text', () => {
const wrapper = render(params);

wrapper.expectText('[data-cy="warning"]').toContain('Check your records for the most up-to-date values');
});

it('should not render the error summary if there is no error', () => {
const wrapper = render(params);

wrapper.expectElement('[data-cy="error-summary"]').notToExist();
});

it('should not render the in-line error if there is no error', () => {
const wrapper = render(params);

wrapper.expectElement('[data-cy="amendment-options-inline-error"]').notToExist();
});

it('should render the error summary if there is an error', () => {
const errMsg = 'an error';
const paramsWithError = {
...params,
errors: validationErrorHandler({ errRef: 'amendmentOptions', errMsg }),
};

const wrapper = render(paramsWithError);

wrapper.expectText('[data-cy="error-summary"]').toContain(errMsg);
});

it('should render the inline error if there is an error', () => {
const errMsg = 'an error';
const paramsWithError = {
...params,
errors: validationErrorHandler({ errRef: 'amendmentOptions', errMsg }),
};

const wrapper = render(paramsWithError);

wrapper.expectText('[data-cy="amendment-options-inline-error"]').toContain(errMsg);
});
});
1 change: 1 addition & 0 deletions gef-ui/server/constants/amendments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const PORTAL_AMENDMENT_PAGES = {
ELIGIBILITY: 'eligibility',
EFFECTIVE_DATE: 'effective-date',
CHECK_YOUR_ANSWERS: 'check-your-answers',
CANCEL: 'cancel',
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MOCK_BASIC_DEAL } from '../../../utils/mocks/mock-applications';
import { MOCK_UNISSUED_FACILITY, MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities';
import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { getPreviousPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getPreviousPage } from '../helpers/navigation.helper';

jest.mock('../../../services/api', () => ({
getApplication: getApplicationMock,
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('getBankReviewDate', () => {
// Assert
const expectedRenderData: BankReviewDateViewModel = {
exporterName: MOCK_BASIC_DEAL.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.BANK_REVIEW_DATE, amendment),
bankReviewDate: undefined,
};
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('getBankReviewDate', () => {
// Assert
const expectedRenderData: BankReviewDateViewModel = {
exporterName: MOCK_BASIC_DEAL.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.BANK_REVIEW_DATE, amendment),
bankReviewDate: {
day: format(bankReviewDate, 'd'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { BankReviewDateViewModel } from '../../../types/view-models/amendments/bank-review-date-view-model';
import { asLoggedInUserSession } from '../../../utils/express-session';
import { userCanAmendFacility } from '../../../utils/facility-amendments.helper';
import { getPreviousPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getPreviousPage } from '../helpers/navigation.helper';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { convertDateToDayMonthYearInput } from '../helpers/dates.helper.ts';

Expand Down Expand Up @@ -60,7 +60,7 @@

const viewModel: BankReviewDateViewModel = {
exporterName: deal.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),

Check failure on line 63 in gef-ui/server/controllers/amendments/bank-review-date/get-bank-review-date.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/bank-review-date/get-bank-review-date.ts#L63

Unsafe assignment of an error typed value.
BethThomas141 marked this conversation as resolved.
Show resolved Hide resolved
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.BANK_REVIEW_DATE, amendment),
bankReviewDate,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MOCK_BASIC_DEAL } from '../../../utils/mocks/mock-applications';
import { MOCK_UNISSUED_FACILITY, MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities';
import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { getPreviousPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getPreviousPage } from '../helpers/navigation.helper';

jest.mock('../../../services/api', () => ({
getApplication: getApplicationMock,
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('getCoverEndDate', () => {
// Assert
const expectedRenderData: CoverEndDateViewModel = {
exporterName: MOCK_BASIC_DEAL.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.COVER_END_DATE, amendment),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { CoverEndDateViewModel } from '../../../types/view-models/amendments/cover-end-date-view-model';
import { asLoggedInUserSession } from '../../../utils/express-session';
import { userCanAmendFacility } from '../../../utils/facility-amendments.helper';
import { getPreviousPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getPreviousPage } from '../helpers/navigation.helper';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';

export type GetCoverEndDateRequest = CustomExpressRequest<{
Expand Down Expand Up @@ -43,14 +43,12 @@

if (!amendment.changeCoverEndDate) {
console.error('Amendment %s not changing cover end date', amendmentId);
return res.redirect(
`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/${PORTAL_AMENDMENT_PAGES.WHAT_DO_YOU_NEED_TO_CHANGE}`,
);
return res.redirect(getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.WHAT_DO_YOU_NEED_TO_CHANGE }));

Check failure on line 46 in gef-ui/server/controllers/amendments/cover-end-date/get-cover-end-date.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cover-end-date/get-cover-end-date.ts#L46

Unsafe assignment of an error typed value.
}

const viewModel: CoverEndDateViewModel = {
exporterName: deal.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),

Check failure on line 51 in gef-ui/server/controllers/amendments/cover-end-date/get-cover-end-date.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/cover-end-date/get-cover-end-date.ts#L51

Unsafe assignment of an error typed value.
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.COVER_END_DATE, amendment),
rkontogianni marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as api from '../../../services/api';
import { asLoggedInUserSession } from '../../../utils/express-session';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { getAmendmentsUrl } from '../helpers/navigation.helper.ts';

export type PostCreateFacilityAmendmentRequest = CustomExpressRequest<{
params: { dealId: string; facilityId: string };
Expand All @@ -20,9 +21,7 @@

const { amendmentId } = await api.upsertAmendment({ facilityId, dealId, amendment: {}, userToken });

return res.redirect(
`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/${PORTAL_AMENDMENT_PAGES.WHAT_DO_YOU_NEED_TO_CHANGE}`,
);
return res.redirect(getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.WHAT_DO_YOU_NEED_TO_CHANGE }));

Check failure on line 24 in gef-ui/server/controllers/amendments/create-draft/post-create-draft.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/create-draft/post-create-draft.ts#L24

Unsafe assignment of an error typed value.
} catch (error) {
console.error('Error upserting draft facility amendment %o', error);
return res.render('partials/problem-with-service.njk');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DoYouHaveAFacilityEndDateViewModel } from '../../../types/view-models/a
import { MOCK_UNISSUED_FACILITY, MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities';
import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { getPreviousPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getPreviousPage } from '../helpers/navigation.helper';

jest.mock('../../../services/api', () => ({
getApplication: getApplicationMock,
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('getDoYouHaveAFacilityEndDate', () => {
// Assert
const expectedRenderData: DoYouHaveAFacilityEndDateViewModel = {
exporterName: MOCK_BASIC_DEAL.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.DO_YOU_HAVE_A_FACILITY_END_DATE, amendment),
};

Expand Down Expand Up @@ -142,7 +142,7 @@ describe('getDoYouHaveAFacilityEndDate', () => {
// Assert
const expectedRenderData: DoYouHaveAFacilityEndDateViewModel = {
exporterName: MOCK_BASIC_DEAL.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.DO_YOU_HAVE_A_FACILITY_END_DATE, amendment),
isUsingFacilityEndDate: String(isUsingFacilityEndDate),
};
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('getDoYouHaveAFacilityEndDate', () => {
// Assert
const expectedRenderData: DoYouHaveAFacilityEndDateViewModel = {
exporterName: MOCK_BASIC_DEAL.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.DO_YOU_HAVE_A_FACILITY_END_DATE, amendment),
isUsingFacilityEndDate: String(isUsingFacilityEndDate),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { DoYouHaveAFacilityEndDateViewModel } from '../../../types/view-models/amendments/do-you-have-a-facility-end-date-view-model';
import { asLoggedInUserSession } from '../../../utils/express-session';
import { userCanAmendFacility } from '../../../utils/facility-amendments.helper';
import { getPreviousPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getPreviousPage } from '../helpers/navigation.helper';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';

export type GetDoYouHaveAFacilityEndDateRequest = CustomExpressRequest<{
Expand Down Expand Up @@ -43,16 +43,14 @@

if (!amendment.changeCoverEndDate) {
console.error('Amendment %s is not changing the cover end date', amendmentId);
return res.redirect(
`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/${PORTAL_AMENDMENT_PAGES.WHAT_DO_YOU_NEED_TO_CHANGE}`,
);
return res.redirect(getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.WHAT_DO_YOU_NEED_TO_CHANGE }));

Check failure on line 46 in gef-ui/server/controllers/amendments/do-you-have-a-facility-end-date/get-do-you-have-a-facility-end-date.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/do-you-have-a-facility-end-date/get-do-you-have-a-facility-end-date.ts#L46

Unsafe assignment of an error typed value.
}

const isUsingFacilityEndDate = amendment.isUsingFacilityEndDate === undefined ? undefined : amendment.isUsingFacilityEndDate.toString();

const viewModel: DoYouHaveAFacilityEndDateViewModel = {
exporterName: deal.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),

Check failure on line 53 in gef-ui/server/controllers/amendments/do-you-have-a-facility-end-date/get-do-you-have-a-facility-end-date.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/do-you-have-a-facility-end-date/get-do-you-have-a-facility-end-date.ts#L53

Unsafe assignment of an error typed value.
previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.DO_YOU_HAVE_A_FACILITY_END_DATE, amendment),
rkontogianni marked this conversation as resolved.
Show resolved Hide resolved
isUsingFacilityEndDate,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DoYouHaveAFacilityEndDateViewModel } from '../../../types/view-models/a
import { MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities';
import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { getNextPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getNextPage } from '../helpers/navigation.helper';
import { postDoYouHaveAFacilityEndDate, PostDoYouHaveAFacilityEndDateRequest } from './post-do-you-have-a-facility-end-date';
import { validationErrorHandler } from '../../../utils/helpers';
import { validateIsUsingFacilityEndDate } from './validation';
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('postDoYouHaveAFacilityEndDate', () => {
// Assert
const expectedRenderData: DoYouHaveAFacilityEndDateViewModel = {
exporterName: mockDeal.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),
previousPage,
errors: validationErrorHandler((validateIsUsingFacilityEndDate(isUsingFacilityEndDate) as { errors: ValidationError[] }).errors),
isUsingFacilityEndDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as api from '../../../services/api';
import { DoYouHaveAFacilityEndDateViewModel } from '../../../types/view-models/amendments/do-you-have-a-facility-end-date-view-model';
import { asLoggedInUserSession } from '../../../utils/express-session';
import { getNextPage } from '../helpers/navigation.helper';
import { getAmendmentsUrl, getNextPage } from '../helpers/navigation.helper';
import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments';
import { validateIsUsingFacilityEndDate } from './validation';
import { validationErrorHandler } from '../../../utils/helpers';
Expand Down Expand Up @@ -37,7 +37,7 @@
if ('errors' in errorsOrValue) {
const viewModel: DoYouHaveAFacilityEndDateViewModel = {
exporterName: deal.exporter.companyName,
cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`,
cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }),

Check failure on line 40 in gef-ui/server/controllers/amendments/do-you-have-a-facility-end-date/post-do-you-have-a-facility-end-date.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

gef-ui/server/controllers/amendments/do-you-have-a-facility-end-date/post-do-you-have-a-facility-end-date.ts#L40

Unsafe assignment of an error typed value.
previousPage,
rkontogianni marked this conversation as resolved.
Show resolved Hide resolved
errors: validationErrorHandler(errorsOrValue.errors),
isUsingFacilityEndDate,
Expand Down
Loading
Loading