Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/main/controllers/TribunalRespondToOrderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getLogger } from '../logger';
import { getFlagValue } from '../modules/featureFlag/launchDarkly';

import { setUserCase, updateSendNotificationState } from './helpers/CaseHelpers';
import { getDocumentsAdditionalInformation } from './helpers/DocumentHelpers';
import { getResponseErrors } from './helpers/ErrorHelpers';
import { getPageContent } from './helpers/FormHelpers';
import { getLanguageParam, returnSafeRedirectUrl } from './helpers/RouterHelpers';
Expand Down Expand Up @@ -121,6 +122,16 @@ export default class TribunalRespondToOrderController {
logger.info(error.message);
}

try {
await getDocumentsAdditionalInformation(
selectedRequestOrOrder.value.sendNotificationUploadDocument,
req.session.user?.accessToken
);
} catch (err) {
logger.error('Error getting document additional information: ' + err.message);
res.redirect('/not-found');
}

res.render(TranslationKeys.TRIBUNAL_RESPOND_TO_ORDER, {
...content,
cancelLink: `/citizen-hub/${userCase.id}${getLanguageParam(req.url)}`,
Expand Down
3 changes: 0 additions & 3 deletions src/main/controllers/citizen-hub/CitizenHubController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
import { getLanguageParam } from '../helpers/RouterHelpers';
import {
activateTribunalOrdersAndRequestsLink,
filterECCNotifications,
filterOutSpecialNotifications,
getClaimantTribunalResponseBannerContent,
setNotificationBannerData,
Expand Down Expand Up @@ -156,7 +155,6 @@ export default class CitizenHubController {

const notifications = setNotificationBannerData(userCase?.sendNotificationCollection, req.url);
const generalNotifications = filterOutSpecialNotifications(notifications);
const eccNotifications = await filterECCNotifications(notifications);

let respondentBannerContent = undefined;

Expand Down Expand Up @@ -213,7 +211,6 @@ export default class CitizenHubController {
),
showHearingBanner: shouldShowHearingBanner(userCase?.sendNotificationCollection),
notifications: generalNotifications,
eccNotifications,
languageParam: getLanguageParam(req.url),
welshEnabled,
showMultipleData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ export const getRedirectUrlForNotification = (
* Sets "showAlert" and "needsResponse" for a notification for the notification banner on citizen hub.
*/
export const setNotificationBannerData = (
items: SendNotificationTypeItem[],
notifications: SendNotificationTypeItem[],
url: string
): SendNotificationTypeItem[] => {
const notifications = filterSendNotifications(items);
if (notifications?.length) {
notifications.forEach(item => {
const actionableNotification = isActionableNotification(item);
Expand Down Expand Up @@ -215,32 +214,14 @@ export const activateTribunalOrdersAndRequestsLink = async (
}
};

export const filterSendNotifications = (items: SendNotificationTypeItem[]): SendNotificationTypeItem[] => {
return items?.filter(it => !it.value.sendNotificationSubjectString?.includes(NotificationSubjects.ECC));
};

export const filterECCNotifications = async (
items: SendNotificationTypeItem[]
): Promise<SendNotificationTypeItem[]> => {
const eccFlag = await getFlagValue(FEATURE_FLAGS.ECC, null);
if (eccFlag) {
return items?.filter(it => it.value.sendNotificationSubjectString?.includes(NotificationSubjects.ECC));
}
return [];
};

/**
* Filter out ECC notifications or Hearing only notifications
* Filter out Hearing only notifications
* @param notifications
*/
export const filterOutSpecialNotifications = (
notifications: SendNotificationTypeItem[]
): SendNotificationTypeItem[] => {
return notifications?.filter(
it =>
!it.value.sendNotificationSubjectString?.includes(NotificationSubjects.ECC) &&
it.value.sendNotificationSubjectString !== NotificationSubjects.HEARING
);
return notifications?.filter(it => it.value.sendNotificationSubjectString !== NotificationSubjects.HEARING);
};

/**
Expand Down Expand Up @@ -445,6 +426,7 @@ export const getClaimantTribunalResponseBannerContent = (
.map(response => ({
redirectUrl: `/notification-details/${notification.id}${languageParam}`,
copyToOtherParty: response.value.copyToOtherParty,
sendNotificationSubject: notification.value.sendNotificationSubject,
})) ?? []
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/locales/cy/translation/citizen-hub.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
"rule92No": {
"p1": "Rydych wedi anfon ymateb i'r tribiwnlys ac wedi rhoi eich rhesymau dros beidio â'i gopïo i'r atebydd.",
"p2": "Bydd y tribiwnlys yn ystyried eich rhesymau ac yn rhoi gwybod i chi beth fydd yn digwydd nesaf."
},
"rule92NoEcc": {
"p1": "Rydych chi wedi anfon ateb i'r tribiwnlys."
}
},
"link": "Gweld eich ymateb"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/locales/en/translation/citizen-hub.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
"rule92No": {
"p1": "You have sent a response to the tribunal and given your reasons not to copy it to the respondent.",
"p2": "The tribunal will consider your reasons and let you know what happens next."
},
"rule92NoEcc": {
"p1": "You have sent a reply to the tribunal."
}
},
"link": "View your response"
Expand Down
41 changes: 14 additions & 27 deletions src/main/views/citizen-hub-notification-banner.njk
Original file line number Diff line number Diff line change
Expand Up @@ -219,35 +219,22 @@
}}
{% endfor %}

{% for notification in eccNotifications %}
{% if notification.showAlert %}
{% set htmlForEcc %}
<h3 class="govuk-notification-banner__heading">
{{ notificationBanner.ecc.title + notification.value.sendNotificationTitle }}
</h3>
<p class="govuk-body">
<a class="govuk-link" href="{{ notification.redirectUrl }}">{{ notificationBanner.orderOrRequest.link }}</a>
</p>
{% endset %}
{{ govukNotificationBanner({
html: htmlForEcc,
titleText: important
}) }}
{% endif %}
{% endfor %}

{% for item in claimantTribunalResponseBannerContent %}
{% set claimantTribunalResponseHtml %}
{% if item.copyToOtherParty === "Yes" %}
<h3 class="govuk-notification-banner__heading">
{{notificationBanner.claimantResponseToTribunal.title.rule92Yes}}
</h3>
{% else %}
<h3 class="govuk-notification-banner__heading">
{{notificationBanner.claimantResponseToTribunal.title.rule92No.p1}}<br><br>
{{notificationBanner.claimantResponseToTribunal.title.rule92No.p2}}
</h3>
{% endif %}
{% if item.copyToOtherParty === 'Yes' %}
<h3 class="govuk-notification-banner__heading">
{{ notificationBanner.claimantResponseToTribunal.title.rule92Yes }}
</h3>
{% elif 'Employer Contract Claim' in item.sendNotificationSubject %}
<h3 class="govuk-notification-banner__heading">
{{ notificationBanner.claimantResponseToTribunal.title.rule92NoEcc.p1 }}
</h3>
{% else %}
<h3 class="govuk-notification-banner__heading">
{{ notificationBanner.claimantResponseToTribunal.title.rule92No.p1 }}<br><br>
{{ notificationBanner.claimantResponseToTribunal.title.rule92No.p2 }}
</h3>
{% endif %}
<h3 class="govuk-notification-banner__heading">
<a class="govuk-link" href="{{ item.redirectUrl }}">{{ notificationBanner.claimantResponseToTribunal.link }}</a>
</h3>
Expand Down
63 changes: 63 additions & 0 deletions src/test/unit/controller/TribunalRespondToOrderController.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';

import TribunalRespondToOrderController from '../../../main/controllers/TribunalRespondToOrderController';
import * as DocumentHelpers from '../../../main/controllers/helpers/DocumentHelpers';
import * as routerHelpers from '../../../main/controllers/helpers/RouterHelpers';
import { CaseWithId, YesOrNo } from '../../../main/definitions/case';
import {
Expand Down Expand Up @@ -181,4 +182,66 @@ describe('Tribunal Respond to Order Controller', () => {

expect(response.redirect).toHaveBeenCalledWith('/not-found?lng=en');
});

it('should redirect to /not-found when getDocumentsAdditionalInformation throws an error', async () => {
const getDocumentsAdditionalInformationSpy = jest
.spyOn(DocumentHelpers, 'getDocumentsAdditionalInformation')
.mockRejectedValue(new Error('Document service error'));

const translationJsons = { ...respondJsonRaw, ...common };
const controller = new TribunalRespondToOrderController();

const mockSelectedRequestOrOrder = {
id: '999',
value: {
number: '1',
sendNotificationTitle: 'title',
sendNotificationSubjectString: 'Order or request',
sendNotificationSelectHearing: {
selectedLabel: 'Hearing',
},
date: '2019-05-03',
sentBy: 'Tribunal',
sendNotificationCaseManagement: 'Order',
sendNotificationResponseTribunal: 'required',
sendNotificationSelectParties: 'Both',
sendNotificationAdditionalInfo: 'additional info',
sendNotificationWhoCaseOrder: 'Legal officer',
sendNotificationFullName: 'Judge Dredd',
sendNotificationNotify: 'Both',
notificationState: 'notViewedYet',
sendNotificationUploadDocument: [
{
id: '1',
value: {
typeOfDocument: 'ACAS Certificate',
uploadedDocument: {
document_binary_url: 'http://dm-store:8080/documents/test.pdf/binary',
document_filename: 'test.pdf',
document_url: 'http://dm-store:8080/documents/test.pdf',
},
},
},
],
},
};

const userCase: Partial<CaseWithId> = {
...mockUserCaseComplete,
selectedRequestOrOrder: mockSelectedRequestOrOrder,
sendNotificationCollection: [mockSelectedRequestOrOrder],
};

const response = mockResponse();
const request = mockRequestWithTranslation({ t, userCase }, translationJsons);
request.params.orderId = '999';
request.session.userCase.sendNotificationCollection = [mockSelectedRequestOrOrder];

await controller.get(request, response);

expect(response.redirect).toHaveBeenCalledWith('/not-found');
expect(response.render).toHaveBeenCalledWith(TranslationKeys.TRIBUNAL_RESPOND_TO_ORDER, expect.anything());

getDocumentsAdditionalInformationSpy.mockRestore();
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
activateTribunalOrdersAndRequestsLink,
filterECCNotifications,
filterOutSpecialNotifications,
filterSendNotifications,
getClaimantTribunalResponseBannerContent,
getNotificationResponses,
getTribunalOrderOrRequestDetails,
Expand Down Expand Up @@ -31,7 +29,6 @@ import respondentOrderOrRequestRaw from '../../../../main/resources/locales/en/t
import notificationSubjectsRaw from '../../../../main/resources/locales/en/translation/notification-subjects.json';
import mockUserCaseWithCitizenHubLinks from '../../../../main/resources/mocks/mockUserCaseWithCitizenHubLinks';
import {
mockECCNotification,
mockNotificationItem,
mockNotificationItemOther,
mockNotificationRespondOnlyReq,
Expand All @@ -54,7 +51,6 @@ describe('Tribunal order or request Details helper', () => {
};
const req = mockRequestWithTranslation({}, translationJsons);
const notificationItem = mockNotificationItem;
const notificationItemOther = mockNotificationItemOther;
const notificationItemWithResponses = mockNotificationWithResponses;
const mockLdClient = jest.spyOn(LaunchDarkly, 'getFlagValue');
mockLdClient.mockResolvedValue(true);
Expand Down Expand Up @@ -270,6 +266,7 @@ describe('Tribunal order or request Details helper', () => {
{
copyToOtherParty: YesOrNo.YES,
redirectUrl: '/notification-details/6423be5b-0b82-462a-af1d-5f1df39686ab?lng=en',
sendNotificationSubject: [NotificationSubjects.ORDER_OR_REQUEST],
},
]);
});
Expand All @@ -291,52 +288,6 @@ describe('Tribunal order or request Details helper', () => {
});
});

describe('should filter notifications', () => {
it('should filter only orders, requests or Other (General correspondence)', () => {
// create a test subject as the only one which should be filtered OUT is ECC
const TEST_NOTIFICATION_SUBJECT = 'TEST SUBJECT';
const notificationWithoutOrderOrRequest = {
value: {
sendNotificationCaseManagement: undefined,
sendNotificationSubjectString: TEST_NOTIFICATION_SUBJECT,
} as SendNotificationType,
} as SendNotificationTypeItem;

const filteredNotifications = filterSendNotifications([
notificationWithoutOrderOrRequest,
notificationItem,
notificationItemOther,
mockECCNotification,
]);
expect(filteredNotifications).toHaveLength(3);
expect(filteredNotifications[0].value.sendNotificationSubjectString).toStrictEqual(TEST_NOTIFICATION_SUBJECT);
expect(filteredNotifications[1].value.sendNotificationSubjectString).toStrictEqual(
NotificationSubjects.ORDER_OR_REQUEST
);
expect(filteredNotifications[2].value.sendNotificationSubjectString).toStrictEqual(
NotificationSubjects.GENERAL_CORRESPONDENCE
);
});

it('should filter only ECC notifications', async () => {
const eccNotifications = await filterECCNotifications([
notificationItem,
notificationItemOther,
mockECCNotification,
]);

expect(eccNotifications).toHaveLength(1);
expect(eccNotifications[0].value.sendNotificationSubjectString).toStrictEqual(NotificationSubjects.ECC);
});

it('should return empty array when no ECC notifications', async () => {
mockLdClient.mockResolvedValue(false);
const eccNotifications = await filterECCNotifications([notificationItem, notificationItemOther]);

expect(eccNotifications).toHaveLength(0);
});
});

describe('setNotificationBannerData - populate', () => {
it('should populate notification with correct status when not required to respond', () => {
const populatedNotification = setNotificationBannerData([mockNotificationRespondOnlyReq], 'url')[0];
Expand Down Expand Up @@ -757,7 +708,7 @@ describe('Tribunal order or request Details helper', () => {
});
});

describe('filterOutEcc', () => {
describe('filterOutHearingOnlyNotifications', () => {
test('should show filtered notification', async () => {
const notifications: SendNotificationTypeItem[] = [
{
Expand All @@ -773,15 +724,15 @@ describe('Tribunal order or request Details helper', () => {
value: {
date: '2 December 2023',
sendNotificationSubjectString: 'Employer Contract Claim',
sendNotificationTitle: '2 Do not show',
sendNotificationTitle: '2 Show',
},
},
{
id: '3',
value: {
date: '3 December 2023',
sendNotificationSubjectString: 'Employer Contract Claim, Response (ET3)',
sendNotificationTitle: '3 Do not show',
sendNotificationTitle: '3 Show',
},
},
{
Expand All @@ -802,9 +753,11 @@ describe('Tribunal order or request Details helper', () => {
},
];
const result = filterOutSpecialNotifications(notifications);
expect(result).toHaveLength(2);
expect(result).toHaveLength(4);
expect(result[0].value.sendNotificationTitle).toEqual('1 Show');
expect(result[1].value.sendNotificationTitle).toEqual('5 Show');
expect(result[1].value.sendNotificationTitle).toEqual('2 Show');
expect(result[2].value.sendNotificationTitle).toEqual('3 Show');
expect(result[3].value.sendNotificationTitle).toEqual('5 Show');
});
});
});
Loading