diff --git a/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts b/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts index 63b62612a..ad923d325 100644 --- a/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts +++ b/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts @@ -1,20 +1,19 @@ import { - DigitalDomicileType, PhysicalCommunicationType, RecipientType, } from '@pagopa-pn/pn-commons'; import { NewNotification, - NewNotificationDTO, + NewNotificationDigitalAddressType, NewNotificationDocument, NewNotificationRecipient, NotificationFeePolicy, PaymentModel, } from '../models/NewNotification'; import { UserGroup } from '../models/user'; -import { newNotificationMapper } from '../utility/notification.utility'; import { userResponse } from './Auth.mock'; +import { BffNewNotificationRequest, NotificationDigitalAddressTypeEnum, NotificationDocument, NotificationRecipientV23 } from '../generated-client/notifications'; export const newNotificationGroups: Array = [ { @@ -43,7 +42,7 @@ const newNotificationRecipients: Array = [ firstName: 'Mario', lastName: 'Rossi', recipientType: RecipientType.PF, - type: DigitalDomicileType.PEC, + type: NewNotificationDigitalAddressType.PEC, digitalDomicile: 'mario.rossi@pec.it', address: 'via del corso', addressDetails: '', @@ -61,7 +60,7 @@ const newNotificationRecipients: Array = [ firstName: 'Sara Gallo srl', lastName: '', recipientType: RecipientType.PG, - type: DigitalDomicileType.PEC, + type: NewNotificationDigitalAddressType.PEC, digitalDomicile: '', address: 'via delle cicale', addressDetails: '', @@ -74,6 +73,22 @@ const newNotificationRecipients: Array = [ }, ]; +const newNotificationRecipientsForBff: Array = [ + { + taxId: 'MRARSS90P08H501Q', + denomination: 'Mario Rossi', + recipientType: RecipientType.PF, + digitalDomicile: {type: NotificationDigitalAddressTypeEnum.Pec,address: 'mario.rossi@pec.it'}, + physicalAddress: {address:'via del corso 49', zip: '00122', municipality: 'Roma', province: 'Roma', foreignState: 'Italia'}, + }, + { + taxId: '12345678901', + denomination: 'Sara Gallo srl', + recipientType: RecipientType.PG, + physicalAddress: {address:'via delle cicale 21', zip: '00035', municipality: 'Anzio', province: 'Roma', foreignState: 'Italia'} + }, +] + const newNotificationDocuments: Array = [ { id: 'mocked-id-0', @@ -115,6 +130,31 @@ const newNotificationDocuments: Array = [ }, ]; +const newNotificationDocumentsForBff: Array = [ + { + title: 'mocked-name-0', + contentType: 'application/pdf', + digests: { + sha256: 'mocked-sha256-0', + }, + ref: { + key: 'mocked-key-0', + versionToken: 'mocked-versionToken-0', + }, + }, + { + title: 'mocked-name-1', + contentType: 'application/pdf', + digests: { + sha256: 'mocked-sha256-1', + }, + ref: { + key: 'mocked-key-1', + versionToken: 'mocked-versionToken-1', + }, + }, +]; + const newNotificationPagoPa: NewNotificationDocument = { id: 'mocked-pagopa-id', idx: 0, @@ -190,8 +230,21 @@ export const newNotificationEmpty: NewNotification = { paymentMode: '' as PaymentModel, group: '', taxonomyCode: '', + senderTaxId:'', notificationFeePolicy: '' as NotificationFeePolicy, senderDenomination: userResponse.organization.name, }; -export const newNotificationDTO: NewNotificationDTO = newNotificationMapper(newNotification); +export const newNotificationForBff: BffNewNotificationRequest = { + abstract: '', + paProtocolNumber: '12345678910', + subject: 'Multone esagerato', + recipients: newNotificationRecipientsForBff, + documents: newNotificationDocumentsForBff, + physicalCommunicationType: PhysicalCommunicationType.REGISTERED_LETTER_890, + group: newNotificationGroups[2].id, + taxonomyCode: '010801N', + notificationFeePolicy: NotificationFeePolicy.FLAT_RATE, + senderDenomination: userResponse.organization.name, + senderTaxId: userResponse.organization.fiscal_code, +}; diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index ce575ef36..94b2f140b 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -26,12 +26,12 @@ import { LangCode } from '@pagopa/mui-italia'; import { NewNotification, NewNotificationLangOther, + PreliminaryInformationsPayload, } from '../../models/NewNotification'; import { GroupStatus } from '../../models/user'; import { useAppDispatch, useAppSelector } from '../../redux/hooks'; import { NEW_NOTIFICATION_ACTIONS, getUserGroups } from '../../redux/newNotification/actions'; import { setPreliminaryInformations } from '../../redux/newNotification/reducers'; -import { PreliminaryInformationsPayload } from '../../redux/newNotification/types'; import { RootState } from '../../redux/store'; import { getConfiguration } from '../../services/configuration.service'; import { requiredStringFieldValidation } from '../../utility/validation.utility'; diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsContent.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsContent.tsx index f6974a0da..559910dbf 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsContent.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsContent.tsx @@ -5,8 +5,7 @@ import { useTranslation } from 'react-i18next'; import { TextField, Typography, useFormControl } from '@mui/material'; import { LangCode, LangLabels } from '@pagopa/mui-italia'; -import { NewNotificationLangOther } from '../../models/NewNotification'; -import { PreliminaryInformationsPayload } from '../../redux/newNotification/types'; +import { NewNotificationLangOther, PreliminaryInformationsPayload } from '../../models/NewNotification'; import { FormBox, FormBoxSubtitle, FormBoxTitle } from './NewNotificationFormElelements'; type SubjectFocusHelperTextProps = { diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsLang.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsLang.tsx index d5ff80ad5..00e0072b5 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsLang.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformationsLang.tsx @@ -14,8 +14,7 @@ import { import { CustomDropdown } from '@pagopa-pn/pn-commons'; import { LangCode, LangLabels } from '@pagopa/mui-italia'; -import { BILINGUALISM_LANGUAGES, NewNotificationLangOther } from '../../models/NewNotification'; -import { PreliminaryInformationsPayload } from '../../redux/newNotification/types'; +import { BILINGUALISM_LANGUAGES, NewNotificationLangOther, PreliminaryInformationsPayload } from '../../models/NewNotification'; import { FormBox, FormBoxSubtitle, FormBoxTitle } from './NewNotificationFormElelements'; type Props = { diff --git a/packages/pn-pa-webapp/src/components/NewNotification/Recipient.tsx b/packages/pn-pa-webapp/src/components/NewNotification/Recipient.tsx index 92c4a663e..9fb78cf75 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/Recipient.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/Recipient.tsx @@ -14,10 +14,10 @@ import { Stack, Typography, } from '@mui/material'; -import { DigitalDomicileType, RecipientType, dataRegex } from '@pagopa-pn/pn-commons'; +import { RecipientType, dataRegex } from '@pagopa-pn/pn-commons'; import { ButtonNaked } from '@pagopa/mui-italia'; -import { NewNotificationRecipient, PaymentModel } from '../../models/NewNotification'; +import { NewNotificationDigitalAddressType, NewNotificationRecipient, PaymentModel } from '../../models/NewNotification'; import { useAppDispatch } from '../../redux/hooks'; import { saveRecipients } from '../../redux/newNotification/reducers'; import { @@ -36,7 +36,7 @@ const singleRecipient = { taxId: '', firstName: '', lastName: '', - type: DigitalDomicileType.PEC, + type: NewNotificationDigitalAddressType.PEC, digitalDomicile: '', address: '', houseNumber: '', diff --git a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx index 59ca016c9..98c3b487f 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx @@ -85,7 +85,7 @@ const populateForm = async ( ); }; -describe('PreliminaryInformations component with payment enabled', async () => { +describe('PreliminaryInformations Component', async () => { let result: RenderResult; const confirmHandlerMk = vi.fn(); let mock: MockAdapter; @@ -94,10 +94,6 @@ describe('PreliminaryInformations component with payment enabled', async () => { mock = new MockAdapter(apiClient); }); - beforeEach(() => { - mockIsPaymentEnabledGetter.mockReturnValue(true); - }); - afterEach(() => { mock.reset(); vi.clearAllMocks(); @@ -179,7 +175,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { preloadedState: { userState: { user: { - organization: { name: 'Comune di Palermo', hasGroup: true }, + organization: { name: 'Comune di Palermo', fiscal_code: '00000', hasGroup: true }, }, }, }, @@ -191,6 +187,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { expect(button).toBeDisabled(); await populateForm(form); expect(button).toBeEnabled(); + fireEvent.click(button); await waitFor(() => { const state = testStore.getState(); @@ -211,6 +208,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { additionalAbstract: '', additionalLang: '', additionalSubject: '', + senderTaxId: '' }); }); expect(confirmHandlerMk).toHaveBeenCalledTimes(1); @@ -283,163 +281,6 @@ describe('PreliminaryInformations component with payment enabled', async () => { expect(button).toBeDisabled(); }); - it('form initially filled', async () => { - mock.onGet('/bff/v1/pa/groups?status=ACTIVE').reply(200, newNotificationGroups); - await act(async () => { - result = render( - , - { - preloadedState: { - userState: { - user: { - organization: { name: 'Comune di Palermo', hasGroup: true }, - }, - }, - }, - } - ); - }); - const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement; - testFormElements( - form, - 'paProtocolNumber', - 'protocol-number*', - newNotification.paProtocolNumber - ); - testFormElements(form, 'subject', 'subject*', newNotification.subject); - testFormElements(form, 'abstract', 'abstract', newNotification.abstract); - testFormElements(form, 'group', 'group', newNotification.group); - testFormElements(form, 'taxonomyCode', 'taxonomy-id*', newNotification.taxonomyCode); - testFormElements(form, 'senderDenomination', 'sender-name*', userResponse.organization.name); - const physicalCommunicationType = form.querySelector( - `input[name="physicalCommunicationType"][value="${newNotification.physicalCommunicationType}"]` - ); - expect(physicalCommunicationType).toBeChecked(); - }); - - it('errors on api call', async () => { - mock.onGet('/bff/v1/pa/groups?status=ACTIVE').reply(errorMock.status, errorMock.data); - await act(async () => { - result = render( - <> - - - - , - { - preloadedState: { - userState: { - user: { - organization: { name: 'Comune di Palermo', hasGroup: true }, - }, - }, - }, - } - ); - }); - const statusApiErrorComponent = result.queryByTestId( - `api-error-${NEW_NOTIFICATION_ACTIONS.GET_USER_GROUPS}` - ); - expect(statusApiErrorComponent).toBeInTheDocument(); - }); -}); - -describe('PreliminaryInformations Component with payment disabled', async () => { - let result: RenderResult; - const confirmHandlerMk = vi.fn(); - let mock: MockAdapter; - - beforeAll(() => { - mock = new MockAdapter(apiClient); - }); - - beforeEach(() => { - mockIsPaymentEnabledGetter.mockReturnValue(false); - }); - - afterEach(() => { - mock.reset(); - vi.clearAllMocks(); - }); - - afterAll(() => { - mock.restore(); - }); - - it('renders component', async () => { - mock.onGet('/bff/v1/pa/groups?status=ACTIVE').reply(200, newNotificationGroups); - await act(async () => { - result = render( - , - { - preloadedState: { - userState: { - user: { - organization: { name: 'Comune di Palermo', hasGroup: true }, - }, - }, - }, - } - ); - }); - expect(result.container).toHaveTextContent(/title/i); - const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement; - const button = within(form).getByTestId('step-submit'); - expect(button).toBeDisabled(); - }); - - it('changes form values and clicks on confirm', async () => { - mock.onGet('/bff/v1/pa/groups?status=ACTIVE').reply(200, newNotificationGroups); - await act(async () => { - result = render( - , - { - preloadedState: { - userState: { - user: { - organization: { name: 'Comune di Palermo', hasGroup: true }, - }, - }, - }, - } - ); - }); - const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement; - const button = within(form).getByTestId('step-submit'); - expect(button).toBeDisabled(); - await populateForm(form); - expect(button).toBeEnabled(); - fireEvent.click(button); - await waitFor(() => { - const state = testStore.getState(); - expect(state.newNotificationState.notification).toEqual({ - paProtocolNumber: newNotification.paProtocolNumber, - abstract: '', - subject: newNotification.subject, - taxonomyCode: newNotification.taxonomyCode, - group: newNotificationGroups[1].id, - notificationFeePolicy: NotificationFeePolicy.FLAT_RATE, - payment: {}, - documents: [], - recipients: [], - physicalCommunicationType: PhysicalCommunicationType.AR_REGISTERED_LETTER, - paymentMode: '', - senderDenomination: newNotification.senderDenomination, - lang: 'it', - additionalAbstract: '', - additionalLang: '', - additionalSubject: '', - }); - }); - expect(confirmHandlerMk).toHaveBeenCalledTimes(1); - }); - it('set senderDenomination longer than 80 characters', async () => { mock.onGet('/bff/v1/pa/groups?status=ACTIVE').reply(200, newNotificationGroups); await act(async () => { @@ -531,4 +372,64 @@ describe('PreliminaryInformations Component with payment disabled', async () => ); testFormElements(form, 'additionalLang', 'select-other-language*', 'de'); }); + + it('form initially filled', async () => { + mock.onGet('/bff/v1/pa/groups?status=ACTIVE').reply(200, newNotificationGroups); + await act(async () => { + result = render( + , + { + preloadedState: { + userState: { + user: { + organization: { name: 'Comune di Palermo', hasGroup: true }, + }, + }, + }, + } + ); + }); + const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement; + testFormElements( + form, + 'paProtocolNumber', + 'protocol-number*', + newNotification.paProtocolNumber + ); + testFormElements(form, 'subject', 'subject*', newNotification.subject); + testFormElements(form, 'abstract', 'abstract', newNotification.abstract); + testFormElements(form, 'group', 'group', newNotification.group); + testFormElements(form, 'taxonomyCode', 'taxonomy-id*', newNotification.taxonomyCode); + testFormElements(form, 'senderDenomination', 'sender-name*', userResponse.organization.name); + const physicalCommunicationType = form.querySelector( + `input[name="physicalCommunicationType"][value="${newNotification.physicalCommunicationType}"]` + ); + expect(physicalCommunicationType).toBeChecked(); + }); + + it('errors on api call', async () => { + mock.onGet('/bff/v1/pa/groups?status=ACTIVE').reply(errorMock.status, errorMock.data); + await act(async () => { + result = render( + <> + + + + , + { + preloadedState: { + userState: { + user: { + organization: { name: 'Comune di Palermo', hasGroup: true }, + }, + }, + }, + } + ); + }); + const statusApiErrorComponent = result.queryByTestId( + `api-error-${NEW_NOTIFICATION_ACTIONS.GET_USER_GROUPS}` + ); + expect(statusApiErrorComponent).toBeInTheDocument(); + }); }); diff --git a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsContent.test.tsx b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsContent.test.tsx index 9bcca1d0a..c07fe9d38 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsContent.test.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsContent.test.tsx @@ -9,8 +9,7 @@ import { testFormElements, } from '@pagopa-pn/pn-commons/src/test-utils'; -import { NewNotificationLangOther, PaymentModel } from '../../../models/NewNotification'; -import { PreliminaryInformationsPayload } from '../../../redux/newNotification/types'; +import { NewNotificationLangOther, PaymentModel, PreliminaryInformationsPayload } from '../../../models/NewNotification'; import PreliminaryInformationsContent from '../PreliminaryInformationsContent'; // mock imports diff --git a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsLang.test.tsx b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsLang.test.tsx index a1043a48d..eddd60e9e 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsLang.test.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformationsLang.test.tsx @@ -14,8 +14,7 @@ import { import { LangLabels } from '@pagopa/mui-italia'; import userEvent from '@testing-library/user-event'; -import { PaymentModel } from '../../../models/NewNotification'; -import { PreliminaryInformationsPayload } from '../../../redux/newNotification/types'; +import { PaymentModel, PreliminaryInformationsPayload } from '../../../models/NewNotification'; import PreliminaryInformationsLang from '../PreliminaryInformationsLang'; // mock imports diff --git a/packages/pn-pa-webapp/src/models/NewNotification.ts b/packages/pn-pa-webapp/src/models/NewNotification.ts index d18dfca95..8ce0d1ddd 100644 --- a/packages/pn-pa-webapp/src/models/NewNotification.ts +++ b/packages/pn-pa-webapp/src/models/NewNotification.ts @@ -1,10 +1,8 @@ import { - DigitalDomicileType, - NotificationDetailDocument, - NotificationDetailRecipient, PhysicalCommunicationType, RecipientType, } from '@pagopa-pn/pn-commons'; +import { NotificationAttachmentBodyRef } from '../generated-client/notifications'; export enum PaymentModel { PAGO_PA_NOTICE = 'PAGO_PA_NOTICE', @@ -17,25 +15,9 @@ export enum NotificationFeePolicy { DELIVERY_MODE = 'DELIVERY_MODE', } -interface BaseNewNotification { - notificationFeePolicy: NotificationFeePolicy; - idempotenceToken?: string; - paProtocolNumber: string; - subject: string; - abstract?: string; - cancelledIun?: string; - physicalCommunicationType: PhysicalCommunicationType; - senderDenomination: string; - senderTaxId?: string; - group?: string; - taxonomyCode: string; -} - -// New Notification DTO -export interface NewNotificationDTO extends BaseNewNotification { - recipients: Array; - documents: Array; - additionalLanguages?: Array; +// NotificationDigital Domicile Type +export enum NewNotificationDigitalAddressType { + PEC = 'PEC', } // New Notification @@ -46,7 +28,7 @@ export interface NewNotificationRecipient { taxId: string; firstName: string; lastName: string; - type: DigitalDomicileType; + type: NewNotificationDigitalAddressType; digitalDomicile: string; address: string; houseNumber: string; @@ -76,7 +58,18 @@ export interface NewNotificationDocument { }; } -export interface NewNotification extends BaseNewNotification, NewNotificationBilingualism { +export interface NewNotification extends NewNotificationBilingualism { + notificationFeePolicy: NotificationFeePolicy; + idempotenceToken?: string; + paProtocolNumber: string; + subject: string; + abstract?: string; + cancelledIun?: string; + physicalCommunicationType: PhysicalCommunicationType; + senderDenomination: string; + senderTaxId: string; + group?: string; + taxonomyCode: string; paymentMode?: PaymentModel; recipients: Array; documents: Array; @@ -95,10 +88,35 @@ export interface PaymentObject { f24?: NewNotificationDocument; } -export interface NewNotificationResponse { - notificationRequestId: string; +export interface PreliminaryInformationsPayload extends NewNotificationBilingualism { paProtocolNumber: string; - idempotenceToken: string; + subject: string; + abstract?: string; + physicalCommunicationType: PhysicalCommunicationType; + group?: string; + paymentMode: PaymentModel; + taxonomyCode: string; + senderDenomination?: string; +} + +export interface UploadDocumentParams { + id: string; + key: string; + contentType: string; + file: Uint8Array | undefined; + sha256: string; +} + +export interface UploadPaymentResponse { + [key: string]: { + pagoPaForm: UploadDocumentsResponse; + f24flatRate?: UploadDocumentsResponse; + f24standard?: UploadDocumentsResponse; + }; +} + +export interface UploadDocumentsResponse { + [id: string]: NotificationAttachmentBodyRef; } export const BILINGUALISM_LANGUAGES = ['de', 'sl', 'fr']; diff --git a/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts b/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts index 96d513b9c..5f026d24c 100644 --- a/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts +++ b/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts @@ -5,7 +5,7 @@ import { PhysicalCommunicationType } from '@pagopa-pn/pn-commons'; import { mockAuthentication } from '../../../__mocks__/Auth.mock'; import { newNotification, payments } from '../../../__mocks__/NewNotification.mock'; import { apiClient, externalClient } from '../../../api/apiClients'; -import { PaymentModel, PaymentObject } from '../../../models/NewNotification'; +import { PaymentModel, PaymentObject, PreliminaryInformationsPayload } from '../../../models/NewNotification'; import { GroupStatus } from '../../../models/user'; import { newNotificationMapper } from '../../../utility/notification.utility'; import { store } from '../../store'; @@ -25,7 +25,6 @@ import { setPreliminaryInformations, setSenderInfos, } from '../reducers'; -import { PreliminaryInformationsPayload } from '../types'; const initialState = { loading: false, @@ -41,6 +40,7 @@ const initialState = { taxonomyCode: '', notificationFeePolicy: '', senderDenomination: '', + senderTaxId:'' }, groups: [], isCompleted: false, diff --git a/packages/pn-pa-webapp/src/redux/newNotification/actions.ts b/packages/pn-pa-webapp/src/redux/newNotification/actions.ts index e6442509a..f942ac576 100644 --- a/packages/pn-pa-webapp/src/redux/newNotification/actions.ts +++ b/packages/pn-pa-webapp/src/redux/newNotification/actions.ts @@ -8,17 +8,18 @@ import { NotificationsApi } from '../../api/notifications/Notifications.api'; import { InfoPaApiFactory } from '../../generated-client/info-pa'; import { BffNewNotificationRequest, + BffNewNotificationResponse, NotificationSentApiFactory, } from '../../generated-client/notifications'; import { NewNotification, NewNotificationDocument, - NewNotificationResponse, PaymentObject, + UploadDocumentParams, + UploadDocumentsResponse, } from '../../models/NewNotification'; import { GroupStatus, UserGroup } from '../../models/user'; import { newNotificationMapper } from '../../utility/notification.utility'; -import { UploadDocumentParams, UploadDocumentsResponse } from './types'; export enum NEW_NOTIFICATION_ACTIONS { GET_USER_GROUPS = 'getUserGroups', @@ -182,7 +183,7 @@ export const uploadNotificationPaymentDocument = createAsyncThunk< } ); -export const createNewNotification = createAsyncThunk( +export const createNewNotification = createAsyncThunk( NEW_NOTIFICATION_ACTIONS.CREATE_NOTIFICATION, async (notification: NewNotification, { rejectWithValue }) => { try { @@ -195,7 +196,7 @@ export const createNewNotification = createAsyncThunk, isCompleted: false, diff --git a/packages/pn-pa-webapp/src/redux/newNotification/types.ts b/packages/pn-pa-webapp/src/redux/newNotification/types.ts deleted file mode 100644 index e5742b929..000000000 --- a/packages/pn-pa-webapp/src/redux/newNotification/types.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { PhysicalCommunicationType } from '@pagopa-pn/pn-commons'; - -import { NewNotificationBilingualism, PaymentModel } from '../../models/NewNotification'; - -export interface PreliminaryInformationsPayload extends NewNotificationBilingualism { - paProtocolNumber: string; - subject: string; - abstract?: string; - physicalCommunicationType: PhysicalCommunicationType; - group?: string; - paymentMode: PaymentModel; - taxonomyCode: string; - senderDenomination?: string; -} - -export interface UploadDocumentParams { - id: string; - key: string; - contentType: string; - file: Uint8Array | undefined; - sha256: string; -} - -export interface UploadPaymentResponse { - [key: string]: { - pagoPaForm: UploadDocumentsResponse; - f24flatRate?: UploadDocumentsResponse; - f24standard?: UploadDocumentsResponse; - }; -} - -export interface UploadDocumentsResponse { - [id: string]: { - key: string; - versionToken: string; - }; -} diff --git a/packages/pn-pa-webapp/src/utility/__test__/notification.utility.test.ts b/packages/pn-pa-webapp/src/utility/__test__/notification.utility.test.ts index bad65118b..8061b476e 100644 --- a/packages/pn-pa-webapp/src/utility/__test__/notification.utility.test.ts +++ b/packages/pn-pa-webapp/src/utility/__test__/notification.utility.test.ts @@ -1,5 +1,5 @@ -import { newNotification, newNotificationDTO } from '../../__mocks__/NewNotification.mock'; -import { NewNotificationDTO } from '../../models/NewNotification'; +import { newNotification, newNotificationForBff } from '../../__mocks__/NewNotification.mock'; +import { BffNewNotificationRequest } from '../../generated-client/notifications'; import { getDuplicateValuesByKeys, newNotificationMapper } from '../notification.utility'; const mockArray = [ @@ -14,31 +14,7 @@ const mockArray = [ describe('Test notification utility', () => { it('Map notification from presentation layer to api layer', () => { const result = newNotificationMapper(newNotification); - expect(result).toEqual(newNotificationDTO); - }); - - it('Checks that if physical address has empty required fields, its value is set to undefined', () => { - const request = { - ...newNotification, - recipients: newNotification.recipients.map((recipient, index) => { - if (index === 0) { - recipient.address = ''; - recipient.houseNumber = ''; - } - return recipient; - }), - }; - const response = { - ...newNotificationDTO, - recipients: newNotificationDTO.recipients.map((recipient, index) => { - if (index === 0) { - recipient.physicalAddress = undefined; - } - return recipient; - }), - }; - const result = newNotificationMapper(request); - expect(result).toEqual(response); + expect(result).toEqual(newNotificationForBff); }); it('Checks that getDuplicateValuesByKeys returns duplicate values', () => { @@ -47,6 +23,7 @@ describe('Test notification utility', () => { }); it('Checks that notificationMapper returns correct bilingualism dto', () => { + // fe version after mapper const result = newNotificationMapper({ ...newNotification, lang: 'other', @@ -54,8 +31,9 @@ describe('Test notification utility', () => { additionalAbstract: 'abstract for de', additionalSubject: 'subject for de', }); - const response: NewNotificationDTO = { - ...newNotificationDTO, + // + const response: BffNewNotificationRequest = { + ...newNotificationForBff, subject: 'Multone esagerato|subject for de', abstract: 'abstract for de', additionalLanguages: ['DE'], diff --git a/packages/pn-pa-webapp/src/utility/notification.utility.ts b/packages/pn-pa-webapp/src/utility/notification.utility.ts index 9ab808985..0ccd1ea24 100644 --- a/packages/pn-pa-webapp/src/utility/notification.utility.ts +++ b/packages/pn-pa-webapp/src/utility/notification.utility.ts @@ -4,30 +4,22 @@ import _ from 'lodash'; import { NotificationDetailDocument, NotificationDetailPayment, - NotificationDetailRecipient, PhysicalAddress, RecipientType, } from '@pagopa-pn/pn-commons'; import { NewNotification, - NewNotificationDTO, NewNotificationDocument, NewNotificationLangOther, NewNotificationRecipient, PaymentModel, PaymentObject, } from '../models/NewNotification'; +import { BffNewNotificationRequest, NotificationRecipientV23 } from '../generated-client/notifications'; const checkPhysicalAddress = (recipient: NewNotificationRecipient) => { - if ( - recipient.address && - recipient.houseNumber && - recipient.zip && - recipient.municipality && - recipient.province && - recipient.foreignState - ) { + const address = { address: `${recipient.address} ${recipient.houseNumber}`, addressDetails: recipient.addressDetails, @@ -46,22 +38,14 @@ const checkPhysicalAddress = (recipient: NewNotificationRecipient) => { } }); return address; - } - return undefined; }; const newNotificationRecipientsMapper = ( recipients: Array, paymentMethod?: PaymentModel -): Array => +): Array => recipients.map((recipient) => { - const digitalDomicile = recipient.digitalDomicile - ? { - type: recipient.type, - address: recipient.digitalDomicile, - } - : undefined; - const parsedRecipient: NotificationDetailRecipient = { + const parsedRecipient: NotificationRecipientV23 = { denomination: recipient.recipientType === RecipientType.PG ? recipient.firstName @@ -70,9 +54,12 @@ const newNotificationRecipientsMapper = ( taxId: recipient.taxId, physicalAddress: checkPhysicalAddress(recipient), }; - if (digitalDomicile) { + if (recipient.digitalDomicile) { // eslint-disable-next-line functional/immutable-data - parsedRecipient.digitalDomicile = digitalDomicile; + parsedRecipient.digitalDomicile = { + type: recipient.type, + address: recipient.digitalDomicile, + }; } if (paymentMethod !== PaymentModel.NOTHING) { // eslint-disable-next-line functional/immutable-data @@ -101,9 +88,9 @@ const newNotificationAttachmentsMapper = ( documents.map((document) => newNotificationDocumentMapper(document)); const newNotificationPaymentDocumentsMapper = ( - recipients: Array, + recipients: Array, paymentDocuments: { [key: string]: PaymentObject } -): Array => +): Array => recipients.map((r) => { const payment: NotificationDetailPayment = {}; /* eslint-disable functional/immutable-data */ @@ -139,7 +126,7 @@ const newNotificationPaymentDocumentsMapper = ( return r; }); -export function newNotificationMapper(newNotification: NewNotification): NewNotificationDTO { +export function newNotificationMapper(newNotification: NewNotification): BffNewNotificationRequest { const clonedNotification = _.omit(_.cloneDeep(newNotification), [ 'paymentMode', 'payment', @@ -168,7 +155,7 @@ export function newNotificationMapper(newNotification: NewNotification): NewNoti : undefined; /* eslint-disable functional/immutable-data */ - const newNotificationParsed: NewNotificationDTO = { + const newNotificationParsed: BffNewNotificationRequest = { ...clonedNotification, recipients: [], documents: [],