Skip to content

Commit

Permalink
[P4ADEV-1726] fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedetta-fabbri committed Jan 8, 2025
1 parent 3f700a0 commit 0f98c7d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.gov.pagopa.pu.debtpositions.mapper;

import it.gov.pagopa.pu.debtpositions.citizen.service.DataCipherService;
import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO;
import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
import it.gov.pagopa.pu.debtpositions.model.InstallmentNoPII;
Expand All @@ -10,6 +11,12 @@
@Service
public class InstallmentPIIMapper {

private final DataCipherService dataCipherService;

public InstallmentPIIMapper(DataCipherService dataCipherService) {
this.dataCipherService = dataCipherService;
}

public Pair<InstallmentNoPII, InstallmentPIIDTO> map(InstallmentDTO installment) {
InstallmentNoPII installmentNoPII = new InstallmentNoPII();

Expand All @@ -30,6 +37,7 @@ public Pair<InstallmentNoPII, InstallmentPIIDTO> map(InstallmentDTO installment)
installmentNoPII.setBalance(installment.getBalance());
installmentNoPII.setLegacyPaymentMetadata(installment.getLegacyPaymentMetadata());
installmentNoPII.setDebtorEntityType(installment.getDebtor().getUniqueIdentifierType().charAt(0));
installmentNoPII.setDebtorFiscalCodeHash(dataCipherService.hash(installment.getDebtor().getUniqueIdentifierCode()));
installmentNoPII.setCreationDate(installment.getCreationDate());
installmentNoPII.setUpdateDate(installment.getUpdateDate());
installmentNoPII.setUpdateOperatorExternalId(1L); // TODO to check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
package it.gov.pagopa.pu.debtpositions.mapper;

import it.gov.pagopa.pu.debtpositions.citizen.service.DataCipherService;
import it.gov.pagopa.pu.debtpositions.dto.InstallmentPIIDTO;
import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
import it.gov.pagopa.pu.debtpositions.model.InstallmentNoPII;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.util.Pair;

import static it.gov.pagopa.pu.debtpositions.util.TestUtils.checkNotNullFields;
import static it.gov.pagopa.pu.debtpositions.util.faker.InstallmentFaker.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith(MockitoExtension.class)
class InstallmentPIIMapperTest {

private InstallmentPIIMapper mapper;

@Mock
private DataCipherService dataCipherServiceMock;

@BeforeEach
void init(){
mapper = new InstallmentPIIMapper();
mapper = new InstallmentPIIMapper(dataCipherServiceMock);
}

@AfterEach
void verifyNotMoreInvocation() {
Mockito.verifyNoMoreInteractions(dataCipherServiceMock);
}

@Test
Expand All @@ -26,6 +41,9 @@ void testMap(){
InstallmentPIIDTO installmentPIIDTOExpected = buildInstallmentPIIDTO();

InstallmentDTO installmentDTO = buildInstallmentDTO();
byte[] expectedHashedCF = {};
Mockito.when(dataCipherServiceMock.hash(installmentDTO.getDebtor().getUniqueIdentifierCode())).thenReturn(expectedHashedCF);

Pair<InstallmentNoPII, InstallmentPIIDTO> result = mapper.map(installmentDTO);

assertEquals(installmentNoPIIExpected, result.getFirst());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static InstallmentNoPII buildInstallmentNoPII(){
.legacyPaymentMetadata("legacyPaymentMetadata")
.humanFriendlyRemittanceInformation("humanFriendlyRemittanceInformation")
.debtorEntityType('F')
.debtorFiscalCodeHash(new byte[] {})
.balance("balance")
.build();
}
Expand Down

0 comments on commit 0f98c7d

Please sign in to comment.