diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f0cf3f7bf..929151869e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha ## [UNRELEASED - DD.MM.YYYY] ### Changed - #965 Implement proxy functionality of the IRS policy store +- #962 Changed notification model to new one in frontend/backend ### Added - #737 Added concept: Contract table -> parts link action diff --git a/frontend/src/app/mocks/services/alerts-mock/alerts.handler.ts b/frontend/src/app/mocks/services/alerts-mock/alerts.handler.ts index 9ce6942c13..25e3b77e0c 100644 --- a/frontend/src/app/mocks/services/alerts-mock/alerts.handler.ts +++ b/frontend/src/app/mocks/services/alerts-mock/alerts.handler.ts @@ -80,20 +80,10 @@ export const alertsHandlers = [ }), rest.get(`*${ environment.apiUrl }/notifications/:notificationId`, (req, res, ctx) => { - const { alertId } = req.params; - - const indexFromId = parseInt((alertId as string).replace('id-', ''), 10); - - const statusCollection = [ - NotificationStatus.CREATED, - NotificationStatus.SENT, + const { notificationId } = req.params; + const indexFromId = parseInt((notificationId as string).replace('id-', ''), 10); + const currentStatus = [ NotificationStatus.RECEIVED, - NotificationStatus.CLOSED, - NotificationStatus.CANCELED, - NotificationStatus.ACKNOWLEDGED, - NotificationStatus.ACCEPTED, - NotificationStatus.DECLINED, - NotificationStatus.ACKNOWLEDGED, NotificationStatus.ACCEPTED, NotificationStatus.DECLINED, @@ -101,9 +91,9 @@ export const alertsHandlers = [ NotificationStatus.CANCELED, ]; const channel = [ 2, 8, 9, 10, 11, 12 ].includes(indexFromId) ? 'RECEIVER' : 'SENDER'; - const randomNotification = buildMockAlerts([ statusCollection[indexFromId] ], channel)[0]; + const randomNotification = buildMockAlerts(currentStatus, channel)[0]; - return res(ctx.status(200), ctx.json({ ...randomNotification, id: alertId })); + return res(ctx.status(200), ctx.json({ ...randomNotification, id: notificationId })); }), rest.post(`*${ environment.apiUrl }/notifications`, (_, res, ctx) => { return res(ctx.status(400), ctx.json({message: "Error while sending Alert to EDC"} )); diff --git a/frontend/src/app/mocks/services/alerts-mock/alerts.model.ts b/frontend/src/app/mocks/services/alerts-mock/alerts.model.ts index 34d7cadc27..a1b96f9b1c 100644 --- a/frontend/src/app/mocks/services/alerts-mock/alerts.model.ts +++ b/frontend/src/app/mocks/services/alerts-mock/alerts.model.ts @@ -38,21 +38,6 @@ export const buildMockAlerts = ( new Array(101).fill(null).map((_, index) => { const status = statuses[index % statuses.length]; const severity = severities[index % severities.length]; - // every 10th alert should have an error - const errorAlert = (index + 1) % 10 === 0 ? 'The Services returned an Error while processing this Alert' : undefined; - - const close = status === NotificationStatus.CLOSED ? getRandomText(getRandomIntFromInterval(15, 500)) : ''; - const isDeclined = Math.random() >= 0.5; - - const decline = - status === NotificationStatus.DECLINED || (!!close && isDeclined) - ? getRandomText(getRandomIntFromInterval(15, 500)) - : ''; - - const accept = - status === NotificationStatus.ACCEPTED || (!!close && !isDeclined) - ? getRandomText(getRandomIntFromInterval(15, 500)) - : ''; const numberToString = (i: number) => i.toString().padStart(2, '0'); const month = getRandomIntFromInterval(1, 12); @@ -60,40 +45,41 @@ export const buildMockAlerts = ( return { id: `${ AlertIdPrefix }${ index + 1 }`, - description: `Alert No ${ index + 1 } ${ getRandomText(getRandomIntFromInterval(15, 500)) }`, title: 'title', + type: NotificationTypeResponse.ALERT, status, - severity, - channel, + description: `Alert No ${ index + 1 } ${ getRandomText(getRandomIntFromInterval(15, 500)) }`, createdBy: 'BPN10000000OEM0A', createdByName: 'OEM xxxxxxxxxxxxxxx A', + createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`, + updatedDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`, + assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ], + channel, sendTo: 'BPN20000000OEM0B', sendToName: 'OEM xxxxxxxxxxxxxxx B', - reason: { close, decline, accept }, - createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`, + severity, targetDate: `2022-${ numberToString(month) }-${ numberToString(day + 1) }T12:34:12`, - assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ], - errorMessage: errorAlert, - type: NotificationTypeResponse.ALERT, + messages: [], }; }); const MockEmptyAlert: NotificationResponse = { id: `${ AlertIdPrefix }000`, - description: `Alert No 000`, - status: NotificationStatus.CREATED, title: 'Title', - severity: Severity.MINOR, + type: NotificationTypeResponse.ALERT, + status: NotificationStatus.CREATED, + description: `Alert No 000`, createdBy: 'BPN10000000OEM0A', createdByName: 'OEM xxxxxxxxxxxxxxx A', - sendTo: 'BPN20000000OEM0B', - sendToName: 'OEM xxxxxxxxxxxxxxx B', - reason: { close: '', decline: '', accept: '' }, createdDate: `2022-05-01T12:34:12`, - targetDate: `2022-02-01T12:34:12`, + updatedDate: `2022-05-01T12:34:12`, assetIds: [ getRandomAsset().id ], channel: 'SENDER', - type: NotificationTypeResponse.ALERT, + sendTo: 'BPN20000000OEM0B', + sendToName: 'OEM xxxxxxxxxxxxxxx B', + severity: Severity.MINOR, + targetDate: `2022-02-01T12:34:12`, + messages: [], }; export const getAlertById = (id: string) => { diff --git a/frontend/src/app/mocks/services/alerts-mock/alerts.test.model.ts b/frontend/src/app/mocks/services/alerts-mock/alerts.test.model.ts index 55d5962f79..7a5d280294 100644 --- a/frontend/src/app/mocks/services/alerts-mock/alerts.test.model.ts +++ b/frontend/src/app/mocks/services/alerts-mock/alerts.test.model.ts @@ -24,6 +24,7 @@ import { NotificationStatus, NotificationTypeResponse } from '@shared/model/noti import { Severity } from '@shared/model/severity.model'; import { getRandomAsset } from '../parts-mock/partsAsPlanned/partsAsPlanned.model'; import { MOCK_part_1 } from '../parts-mock/partsAsPlanned/partsAsPlanned.test.model'; +import { getRandomIntFromInterval, getRandomText } from '../text-generator.helper'; export const AlertIdPrefix = 'id-'; @@ -39,42 +40,44 @@ export const buildMockAlerts = ( const numberToString = (i: number) => i.toString().padStart(2, '0'); const month = (index % 12) + 1; const day = (index % 28) + 1; - const errorAlert = (index + 1) % 10 === 0 ? 'The Services returned an Error while processing this Alert' : ''; return { id: `${ AlertIdPrefix }${ index + 1 }`, - description: `Alert No ${ index + 1 }`, + title: 'title', + type: NotificationTypeResponse.ALERT, status, - severity, - channel, + description: `Alert No ${ index + 1 } ${ getRandomText(getRandomIntFromInterval(15, 500)) }`, createdBy: 'BPN10000000OEM0A', createdByName: 'OEM xxxxxxxxxxxxxxx A', - sendTo: 'BPN20000000OEM0B', - title: 'Title', - sendToName: 'OEM xxxxxxxxxxxxxxx B', - reason: { close: '', accept: '', decline: '' }, createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`, + updatedDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`, assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ], - errorMessage: errorAlert, - type: NotificationTypeResponse.ALERT, + channel, + sendTo: 'BPN20000000OEM0B', + sendToName: 'OEM xxxxxxxxxxxxxxx B', + severity, + targetDate: `2022-${ numberToString(month) }-${ numberToString(day + 1) }T12:34:12`, + messages: [], }; }); export const MockEmptyAlert: NotificationResponse = { id: `${ AlertIdPrefix }000`, - description: `Alert No 000`, + title: 'Title', + type: NotificationTypeResponse.ALERT, status: NotificationStatus.CREATED, - severity: Severity.MINOR, + description: `Alert No 000`, createdBy: 'BPN10000000OEM0A', createdByName: 'OEM xxxxxxxxxxxxxxx A', - sendTo: 'BPN20000000OEM0B', - sendToName: 'OEM xxxxxxxxxxxxxxx B', - reason: { close: '', accept: '', decline: '' }, createdDate: `2022-05-01T12:34:12`, + updatedDate: `2022-05-01T12:34:12`, assetIds: [ getRandomAsset().id ], channel: 'SENDER', - title: 'Title', - type: NotificationTypeResponse.ALERT, + sendTo: 'BPN20000000OEM0B', + sendToName: 'OEM xxxxxxxxxxxxxxx B', + severity: Severity.MINOR, + targetDate: `2022-02-01T12:34:12`, + messages: [], }; export const getAlertById = (id: string) => { diff --git a/frontend/src/app/mocks/services/investigations-mock/investigations.test.model.ts b/frontend/src/app/mocks/services/investigations-mock/investigations.test.model.ts index 7f61b98f42..4735dc9794 100644 --- a/frontend/src/app/mocks/services/investigations-mock/investigations.test.model.ts +++ b/frontend/src/app/mocks/services/investigations-mock/investigations.test.model.ts @@ -44,20 +44,21 @@ export const buildMockInvestigations = ( return { id: `${ InvestigationIdPrefix }${ index + 1 }`, - description: `Investigation No ${ index + 1 }`, + title: 'Title', + type: NotificationTypeResponse.INVESTIGATION, status, - severity, - channel, + description: `Investigation No ${ index + 1 }`, createdBy: 'BPN10000000OEM0A', createdByName: 'OEM xxxxxxxxxxxxxxx A', - sendTo: 'BPN20000000OEM0B', - sendToName: 'OEM xxxxxxxxxxxxxxx B', - reason: { close: '', accept: '', decline: '' }, createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`, + updatedDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`, assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ], - errorMessage: errorInvestigation, - title: 'Title', - type: NotificationTypeResponse.INVESTIGATION, + channel, + sendTo: 'BPN20000000OEM0B', + sendToName: 'OEM xxxxxxxxxxxxxxx B', + severity, + targetDate: `2022-${ numberToString(month) }-${ numberToString(day + 1) }T12:34:12`, + messages: [], }; }); diff --git a/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.spec.ts b/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.spec.ts index 86b9387184..4991c79aaa 100644 --- a/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.spec.ts +++ b/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.spec.ts @@ -78,20 +78,22 @@ describe('NotificationEditComponent', () => { it('should render component with form', async () => { const notification: Notification = { - assetIds: [], - createdBy: '', + id: 'id-1', + title: '', type: NotificationType.INVESTIGATION, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + updatedDate: undefined, + assetIds: [], + channel: 'SENDER', sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'id-1', + targetDate: null, + messages: [], }; const notificationsFacadeMock = jasmine.createSpyObj('notificationsFacade', [ 'getNotification' ]); @@ -107,20 +109,22 @@ describe('NotificationEditComponent', () => { it('should remove affected parts to affectedPartIds and clear temporaryAffectedParts', async () => { const notification: Notification = { - assetIds: [], - createdBy: '', + id: 'id-1', + title: '', type: NotificationType.INVESTIGATION, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + updatedDate: undefined, + assetIds: [], + channel: 'SENDER', sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'id-1', + targetDate: null, + messages: [], }; const notificationsFacadeMock = jasmine.createSpyObj('notificationsFacade', [ 'getNotification' ]); @@ -153,20 +157,22 @@ describe('NotificationEditComponent', () => { it('should add affected parts to affectedPartIds and clear temporaryAffectedParts', async () => { const notification: Notification = { - assetIds: [], - createdBy: '', + id: 'id-1', + title: '', type: NotificationType.INVESTIGATION, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + updatedDate: undefined, + assetIds: [], + channel: 'SENDER', sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'id-1', + targetDate: null, + messages: [], }; const notificationsFacadeMock = jasmine.createSpyObj('notificationsFacade', [ 'getNotification' ]); @@ -200,20 +206,22 @@ describe('NotificationEditComponent', () => { it('should set supplier parts for investigation', async () => { const notification: Notification = { - assetIds: [], - createdBy: '', + id: 'id-1', + title: '', type: NotificationType.INVESTIGATION, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + updatedDate: undefined, + assetIds: [], + channel: 'SENDER', sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'abc', + targetDate: null, + messages: [], }; const notificationsFacadeMock = jasmine.createSpyObj('notificationsFacade', [ 'getNotification' ]); notificationsFacadeMock.getNotification.and.returnValue(of({ notification })); @@ -240,20 +248,22 @@ describe('NotificationEditComponent', () => { it('should set own parts as built for available part subscription with alerts', async () => { const notification: Notification = { - assetIds: [], - createdBy: '', + id: 'id-1', + title: '', type: NotificationType.ALERT, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + updatedDate: undefined, + assetIds: [], + channel: 'SENDER', sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'abc', + targetDate: null, + messages: [], }; const notificationsFacadeMock = jasmine.createSpyObj('notificationsFacade', [ 'getNotification' ]); @@ -280,20 +290,22 @@ describe('NotificationEditComponent', () => { it('should correctly update form', async () => { const notification: Notification = { - assetIds: [], - createdBy: '', + id: 'id-1', + title: '', type: NotificationType.ALERT, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + updatedDate: undefined, + assetIds: [], + channel: 'SENDER', sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'abc', + targetDate: null, + messages: [], }; const notificationsFacadeMock = jasmine.createSpyObj('notificationsFacade', [ 'getNotification' ]); diff --git a/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.ts b/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.ts index b7517551a5..681d668c78 100644 --- a/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.ts +++ b/frontend/src/app/modules/page/notifications/detail/edit/notification-edit.component.ts @@ -139,20 +139,22 @@ export class NotificationEditComponent implements OnDestroy { this.isSaveButtonDisabled = true; const newNotification: Notification = { - assetIds: this.sharedPartService?.affectedParts?.map(value => value.id) || [], - createdBy: '', + id: 'new', + title: '', type: this.route.snapshot.queryParams['initialType'] ?? null, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: true, - reason: undefined, + updatedDate: undefined, + assetIds: this.sharedPartService?.affectedParts?.map(value => value.id) || [], + channel: 'SENDER', sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'new', + messages: [], + isFromSender: true, }; this.selectNotificationAndLoadPartsBasedOnNotification(newNotification); } diff --git a/frontend/src/app/modules/page/notifications/presentation/notifications.component.spec.ts b/frontend/src/app/modules/page/notifications/presentation/notifications.component.spec.ts index b9e1dd7301..3964e2636f 100644 --- a/frontend/src/app/modules/page/notifications/presentation/notifications.component.spec.ts +++ b/frontend/src/app/modules/page/notifications/presentation/notifications.component.spec.ts @@ -47,24 +47,6 @@ describe('NotificationsComponent', () => { expect(spy).toHaveBeenCalledWith([ '/inbox/id-84' ], { queryParams: tabInformation }); }); - it('should call change pagination of received notifications', async () => { - await renderNotifications(); - fireEvent.click(await waitFor(() => screen.getByLabelText('pagination.nextPageLabel', { selector: 'button' }))); - - expect(await waitFor(() => screen.getByText('Alert No 20'))).toBeInTheDocument(); - expect(await waitFor(() => screen.getByText('Alert No 84'))).toBeInTheDocument(); - }); - - it('should call change pagination of queued & requested notifications', async () => { - await renderNotifications(); - - fireEvent.click(await waitFor(() => screen.getByText('commonAlert.tabs.queuedAndRequested'))); - - fireEvent.click(await waitFor(() => screen.getByLabelText('pagination.nextPageLabel', { selector: 'button' }))); - - expect(await waitFor(() => screen.getByText('Alert No 20'))).toBeInTheDocument(); - expect(await waitFor(() => screen.getByText('Alert No 84'))).toBeInTheDocument(); - }); it('should sort received notifications after column status', async () => { const { fixture } = await renderNotifications(); diff --git a/frontend/src/app/modules/shared/assembler/notification.assembler.spec.ts b/frontend/src/app/modules/shared/assembler/notification.assembler.spec.ts index 4d99e52f70..842c8e85f9 100644 --- a/frontend/src/app/modules/shared/assembler/notification.assembler.spec.ts +++ b/frontend/src/app/modules/shared/assembler/notification.assembler.spec.ts @@ -40,21 +40,21 @@ describe('InvestigationsAssembler', () => { it('should handle empty values', () => { const expected: Notification = { id: null, - assetIds: null, + title: '', + type: undefined, + status: null, description: '', createdBy: '', createdByName: '', + createdDate: new CalendarDateModel(null), + updatedDate: new CalendarDateModel(null), + assetIds: null, sendTo: '', sendToName: '', - reason: { accept: '', close: '', decline: '' }, - isFromSender: false, - status: null, severity: null, - createdDate: new CalendarDateModel(null), targetDate: new CalendarDateModel(null), - bpn: '', - type: undefined, - title: '', + messages: [], + isFromSender: false, }; expect(NotificationAssembler.assembleNotification({} as NotificationResponse)).toEqual(expected); @@ -70,40 +70,40 @@ describe('InvestigationsAssembler', () => { content: [ { id: 'test-1', + title: 'Title', + type: NotificationTypeResponse.INVESTIGATION, + status: NotificationStatus.SENT, description: 'test descr', + createdBy: 'BPNL000000TESTRE', + createdByName: '', createdDate: '2022-07-26T15:09:39.419Z', - targetDate: '2022-06-26T15:09:39.419Z', - bpn: 'BPNL000000TESTRE', - status: NotificationStatus.SENT, - severity: Severity.MINOR, + updatedDate: '2022-07-26T15:09:39.419Z', + assetIds: [], channel: 'SENDER', - createdBy: '', - createdByName: '', sendTo: '', sendToName: '', - reason: { close: '', accept: '', decline: '' }, - assetIds: [], - errorMessage: '', - title: 'Title', - type: NotificationTypeResponse.INVESTIGATION, + severity: Severity.MINOR, + targetDate: '2022-07-26T15:09:39.419Z', + messages: [], + }, { id: 'test-2', - description: 'test descr', - createdDate: '2022-07-26T15:09:39.419Z', - targetDate: '2022-06-26T15:09:39.419Z', - bpn: 'BPNL000000TESTRE', + title: 'Title', + type: NotificationTypeResponse.INVESTIGATION, status: 'unknown' as unknown as NotificationStatus, - severity: Severity.MAJOR, - createdBy: '', + description: 'test descr', + createdBy: 'BPNL000000TESTRE', createdByName: '', + createdDate: '2022-07-26T15:09:39.419Z', + updatedDate: '2022-07-26T15:09:39.419Z', + assetIds: [], + channel: 'SENDER', sendTo: '', sendToName: '', - reason: { close: '', accept: '', decline: '' }, - channel: 'SENDER', - assetIds: [], - title: 'Title', - type: NotificationTypeResponse.INVESTIGATION, + severity: Severity.MAJOR, + targetDate: '2022-07-26T15:09:39.419Z', + messages: [], }, ], }, @@ -117,39 +117,40 @@ describe('InvestigationsAssembler', () => { content: [ { id: 'test-1', - description: 'test descr', + title: 'Title', + type: NotificationType.INVESTIGATION, status: NotificationStatus.SENT, - severity: Severity.MINOR, - createdDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), - targetDate: new CalendarDateModel('2022-06-26T15:09:39.419Z'), - bpn: 'BPNL000000TESTRE', - createdBy: '', + description: 'test descr', + createdBy: 'BPNL000000TESTRE', createdByName: '', + createdDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), + updatedDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), + assetIds: [], sendTo: '', sendToName: '', - reason: { close: '', accept: '', decline: '' }, + severity: Severity.MINOR, + targetDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), + messages: [], isFromSender: true, - assetIds: [], - type: NotificationType.INVESTIGATION, - title: 'Title', + }, { id: 'test-2', - description: 'test descr', + title: 'Title', + type: NotificationType.INVESTIGATION, status: null, - severity: Severity.MAJOR, - createdDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), - targetDate: new CalendarDateModel('2022-06-26T15:09:39.419Z'), - bpn: 'BPNL000000TESTRE', - createdBy: '', + description: 'test descr', + createdBy: 'BPNL000000TESTRE', createdByName: '', + createdDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), + updatedDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), + assetIds: [], sendTo: '', sendToName: '', - reason: { close: '', accept: '', decline: '' }, + severity: Severity.MAJOR, + targetDate: new CalendarDateModel('2022-07-26T15:09:39.419Z'), + messages: [], isFromSender: true, - assetIds: [], - type: NotificationType.INVESTIGATION, - title: 'Title', }, ], }; diff --git a/frontend/src/app/modules/shared/assembler/notification.assembler.ts b/frontend/src/app/modules/shared/assembler/notification.assembler.ts index dadc7d59f5..321343cc7b 100644 --- a/frontend/src/app/modules/shared/assembler/notification.assembler.ts +++ b/frontend/src/app/modules/shared/assembler/notification.assembler.ts @@ -39,56 +39,58 @@ export class NotificationAssembler { public static assembleNotification(response: NotificationResponse): Notification { const { id = null, - assetIds = null, - channel = null, title: _title = '', - reason = { accept: '', close: '', decline: '' }, - description = '', - bpn = '', + type: _type = null, status: _status, - severity: _severity, - createdDate: _createdDate = '', + description = '', createdBy: _createdBy = '', createdByName: _createdByName = '', + createdDate: _createdDate = '', + updatedDate: _updatedDate = '', + assetIds = null, + channel = null, sendTo: _sendTo = '', sendToName: _sendToName = '', + severity: _severity, targetDate: _targetDate = '', - errorMessage: _errorMessage = '', - type: _type = null, + messages: _messages = [], } = response; - const isFromSender = channel === 'SENDER'; + const title = _title; + const type = NotificationType[_type]; const status = NotificationStatus[_status] ?? null; - const severity = Object.values(Severity).find(element => element == _severity) ?? null; - const createdDate = new CalendarDateModel(_createdDate); - const targetDate = new CalendarDateModel(_targetDate); const createdBy = _createdBy; const createdByName = _createdByName; + const createdDate = new CalendarDateModel(_createdDate); + const updatedDate = new CalendarDateModel(_updatedDate); const sendTo = _sendTo; - const title = _title; const sendToName = _sendToName; - const errorMessage = _errorMessage || undefined; - const type = NotificationType[_type]; + const severity = Object.values(Severity).find(element => element == _severity) ?? null; + const targetDate = new CalendarDateModel(_targetDate); + const messages = _messages; + + const isFromSender = channel === 'SENDER'; let assembled = { id, + title, description, createdBy, createdByName, sendTo, sendToName, - reason, assetIds, isFromSender, status, severity, createdDate, + updatedDate, targetDate, - bpn, type, - title, + messages, + }; - return errorMessage ? { ...assembled, errorMessage: errorMessage } : assembled; + return assembled; } } diff --git a/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts b/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts index 9bcf57678a..4f8eb99913 100644 --- a/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts +++ b/frontend/src/app/modules/shared/assembler/notificationMenuActions.assembler.spec.ts @@ -26,7 +26,7 @@ import { NotificationsState } from '@page/notifications/core/notifications.state import { NotificationActionHelperService } from '@shared/assembler/notification-action-helper.service'; import { NotificationMenuActionsAssembler } from '@shared/assembler/notificationMenuActions.assembler'; import { NotificationCommonModalComponent } from '@shared/components/notification-common-modal/notification-common-modal.component'; -import { Notification, NotificationStatus } from '@shared/model/notification.model'; +import { Notification, NotificationStatus, NotificationType } from '@shared/model/notification.model'; import { Severity } from '@shared/model/severity.model'; import { KeycloakService } from 'keycloak-angular'; @@ -64,18 +64,19 @@ describe('NotificationMenuActionsAssembler', () => { const notificationTemplate: Notification = { id: 'id-1', + title: 'Title', + type: NotificationType.INVESTIGATION, + status: NotificationStatus.ACKNOWLEDGED, description: 'Investigation No 1', createdBy: '', - title: 'Title', createdByName: '', + createdDate: new CalendarDateModel('2022-05-01T10:34:12.000Z'), + assetIds: [ 'MOCK_part_1' ], sendTo: '', sendToName: '', - reason: { close: '', accept: '', decline: '' }, - isFromSender: true, - assetIds: [ 'MOCK_part_1' ], - status: NotificationStatus.ACKNOWLEDGED, severity: Severity.MINOR, - createdDate: new CalendarDateModel('2022-05-01T10:34:12.000Z'), + messages: [], + isFromSender: true, }; // Act diff --git a/frontend/src/app/modules/shared/components/notification-overview/notification-overview.component.html b/frontend/src/app/modules/shared/components/notification-overview/notification-overview.component.html index a03085aeb7..c598471174 100644 --- a/frontend/src/app/modules/shared/components/notification-overview/notification-overview.component.html +++ b/frontend/src/app/modules/shared/components/notification-overview/notification-overview.component.html @@ -99,13 +99,15 @@ + + {{notification?.errorMessage | i18n}} {{"errorMessage.notificationError" | i18n}} +--> {{ date }} diff --git a/frontend/src/app/modules/shared/components/notification-reason/notification-reason.component.ts b/frontend/src/app/modules/shared/components/notification-reason/notification-reason.component.ts index 30f68d634d..3dbc1142da 100644 --- a/frontend/src/app/modules/shared/components/notification-reason/notification-reason.component.ts +++ b/frontend/src/app/modules/shared/components/notification-reason/notification-reason.component.ts @@ -44,7 +44,6 @@ export class NotificationReasonComponent { @Input() set notification({ description, - reason, status, isFromSender, createdDate, @@ -54,7 +53,6 @@ export class NotificationReasonComponent { sendToName, }: Notification) { const { ACCEPTED, SENT, CLOSED, CREATED, DECLINED } = NotificationStatus; - const { accept, close, decline } = reason; const senderDirection: TextMessageDirection = isFromSender ? 'right' : 'left'; const receiverDirection: TextMessageDirection = !isFromSender ? 'right' : 'left'; @@ -69,19 +67,19 @@ export class NotificationReasonComponent { }; const acceptedMessage = { - reason: accept, direction: receiverDirection, user: sendToName, bpn: sendTo, status: + reason: 'reason accept', direction: receiverDirection, user: sendToName, bpn: sendTo, status: ACCEPTED, } ; const declinedMessage = { - reason: decline, + reason: 'reason decline', direction: receiverDirection, user: sendToName, bpn: sendTo, status: DECLINED, }; const closedMessage = { - reason: close, + reason: 'reason closed', direction: senderDirection, user: createdByName, bpn: createdBy, diff --git a/frontend/src/app/modules/shared/components/request-notification-new/notification-new-request.component.spec.ts b/frontend/src/app/modules/shared/components/request-notification-new/notification-new-request.component.spec.ts index 171b69b4a7..38392a15ce 100644 --- a/frontend/src/app/modules/shared/components/request-notification-new/notification-new-request.component.spec.ts +++ b/frontend/src/app/modules/shared/components/request-notification-new/notification-new-request.component.spec.ts @@ -17,22 +17,18 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -import {LayoutModule} from '@layout/layout.module'; -import {NotificationDetailFacade} from '@page/notifications/core/notification-detail.facade'; -import {NotificationDetailState} from '@page/notifications/core/notification-detail.state'; +import { LayoutModule } from '@layout/layout.module'; +import { NotificationDetailFacade } from '@page/notifications/core/notification-detail.facade'; +import { NotificationDetailState } from '@page/notifications/core/notification-detail.state'; import { NotificationAssembler } from '@shared/assembler/notification.assembler'; -import { - RequestNotificationNewComponent -} from '@shared/components/request-notification-new/notification-new-request.component'; -import {Notification, NotificationType} from '@shared/model/notification.model'; -import {View} from '@shared/model/view.model'; -import { - FormatPartlistSemanticDataModelToCamelCasePipe -} from '@shared/pipes/format-partlist-semantic-data-model-to-camelcase.pipe'; -import {SharedModule} from '@shared/shared.module'; -import {screen, waitFor} from '@testing-library/angular'; -import {renderComponent} from '@tests/test-render.utils'; -import {of} from 'rxjs'; +import { RequestNotificationNewComponent } from '@shared/components/request-notification-new/notification-new-request.component'; +import { Notification, NotificationType } from '@shared/model/notification.model'; +import { View } from '@shared/model/view.model'; +import { FormatPartlistSemanticDataModelToCamelCasePipe } from '@shared/pipes/format-partlist-semantic-data-model-to-camelcase.pipe'; +import { SharedModule } from '@shared/shared.module'; +import { screen, waitFor } from '@testing-library/angular'; +import { renderComponent } from '@tests/test-render.utils'; +import { of } from 'rxjs'; import { MockEmptyAlert } from '../../../../mocks/services/alerts-mock/alerts.test.model'; @@ -73,20 +69,20 @@ describe('requestNotificationNewComponent', () => { const notification: View = { data: { - assetIds: [], - createdBy: '', + id: 'abc', + title: '', type: NotificationType.ALERT, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + assetIds: [], sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'abc', + messages: [], + isFromSender: false, } }; diff --git a/frontend/src/app/modules/shared/components/table/table.component.html b/frontend/src/app/modules/shared/components/table/table.component.html index 841eea23b6..57536641f3 100644 --- a/frontend/src/app/modules/shared/components/table/table.component.html +++ b/frontend/src/app/modules/shared/components/table/table.component.html @@ -184,7 +184,6 @@ [tableType]="tableType" ngDefaultControl [formControl]="filterFormGroup.controls[filter.filterKey]"> - diff --git a/frontend/src/app/modules/shared/model/notification.model.ts b/frontend/src/app/modules/shared/model/notification.model.ts index 6c1e571f4a..a0ed220835 100644 --- a/frontend/src/app/modules/shared/model/notification.model.ts +++ b/frontend/src/app/modules/shared/model/notification.model.ts @@ -86,42 +86,60 @@ export enum NotificationTypeResponse { export interface NotificationResponse { id: string; - description: string; - status: NotificationStatus; - severity: Severity; title: string; - createdDate: string; + type: NotificationTypeResponse; + status: NotificationStatus; + description: string; createdBy: string; createdByName?: string; - sendTo: string; - sendToName?: string; - reason: NotificationReason; + createdDate: string; + updatedDate?: string; assetIds: string[]; channel: 'SENDER' | 'RECEIVER'; + sendTo: string; + sendToName?: string; + severity: Severity; targetDate?: string; - bpn?: string; - errorMessage?: string; - type: NotificationTypeResponse + messages: NotificationMessage[] | []; + +} + +export interface NotificationMessage { + id: string; + sentBy: string; + sentByName: string; + sendTo: string; + sendToName: string; + contractAgreementId: string; + notificationReferenceId: string; + edcNotificationId: string; + messageDate: string; + messageId: string; + message: string; + status: NotificationStatus; + errorMessage: string; } export interface Notification { id: string; - description: string; - status: NotificationStatus | null; - severity: Severity | null; title: string; - createdDate: CalendarDateModel; + type: NotificationType; + status: NotificationStatus; + description: string; createdBy: string; - createdByName: string; - sendTo: string; - sendToName: string; - reason: NotificationReason; + createdByName?: string; + createdDate: CalendarDateModel; + updatedDate?: CalendarDateModel; assetIds: string[]; - isFromSender: boolean; + channel?: 'SENDER' | 'RECEIVER'; + sendTo: string; + sendToName?: string; + severity: Severity; targetDate?: CalendarDateModel; - bpn?: string; - errorMessage?: string; - type?: NotificationType; + messages: NotificationMessage[]; + + //added fields + isFromSender?: boolean; } export enum NotificationColumn { diff --git a/frontend/src/app/modules/shared/modules/notification/modal/actions/notification-action-modal.component.spec.ts b/frontend/src/app/modules/shared/modules/notification/modal/actions/notification-action-modal.component.spec.ts index db8d707fd0..6335dd657f 100644 --- a/frontend/src/app/modules/shared/modules/notification/modal/actions/notification-action-modal.component.spec.ts +++ b/frontend/src/app/modules/shared/modules/notification/modal/actions/notification-action-modal.component.spec.ts @@ -122,20 +122,20 @@ describe('NotificationActionModalComponent', () => { const { fixture } = await renderNotificationActionModalComponent(); const { componentInstance } = fixture; const notification: Notification = { - assetIds: [], - createdBy: '', + id: 'abc', + title: '', type: NotificationType.ALERT, + status: undefined, + description: '', + createdBy: '', createdByName: '', createdDate: undefined, - description: '', - isFromSender: false, - reason: undefined, + assetIds: [], sendTo: '', sendToName: '', severity: undefined, - status: undefined, - title: '', - id: 'abc', + messages: [], + isFromSender: false, }; componentInstance.show(notification, NotificationStatus.CLOSED); diff --git a/frontend/src/app/modules/shared/modules/notification/presentation/notification.component.spec.ts b/frontend/src/app/modules/shared/modules/notification/presentation/notification.component.spec.ts index aa0b010b26..d32c080ac7 100644 --- a/frontend/src/app/modules/shared/modules/notification/presentation/notification.component.spec.ts +++ b/frontend/src/app/modules/shared/modules/notification/presentation/notification.component.spec.ts @@ -39,6 +39,7 @@ import { delay } from 'rxjs/operators'; import { buildMockInvestigations } from '../../../../../mocks/services/investigations-mock/investigations.test.model'; import { NotificationModule } from '../notification.module'; + describe('NotificationsInboxComponent', () => { let clickHandler; @@ -47,6 +48,7 @@ describe('NotificationsInboxComponent', () => { const mapNotificationResponse = (data: NotificationResponse): Notification => { const isFromSender = data.channel === NotificationChannel.SENDER; const createdDate = new CalendarDateModel(data.createdDate); + const updatedDate = new CalendarDateModel((data.updatedDate)); const targetDate = new CalendarDateModel(data.targetDate); const createdBy = data.createdBy; const createdByName = data.createdByName; @@ -59,6 +61,7 @@ describe('NotificationsInboxComponent', () => { return { ...data, createdDate, + updatedDate, targetDate, isFromSender, createdBy,