From 7d693e687b649a212998549bc2d3b35b30aed7fc Mon Sep 17 00:00:00 2001 From: Vitolo-Andrea <157486351+Vitolo-Andrea@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:35:12 +0200 Subject: [PATCH] Mapper fix (#5) --- .../citizen/service/CitizenServiceImpl.java | 2 +- .../citizen/service/CitizenServiceTest.java | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceImpl.java b/src/main/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceImpl.java index 35bd2b1..feb0baf 100644 --- a/src/main/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceImpl.java +++ b/src/main/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceImpl.java @@ -48,7 +48,7 @@ public Mono createCitizenConsent(CitizenConsentDTO citizenCon .switchIfEmpty( citizenRepository.save(citizenConsent) .doOnSuccess(savedConsent -> log.info("[EMD][CREATE-CITIZEN-CONSENT] Created new citizen consent")) - .map(mapperToDTO::map) + .flatMap(savedConsent -> Mono.just(mapperToDTO.map(savedConsent))) // Map the saved consent ); } diff --git a/src/test/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceTest.java b/src/test/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceTest.java index ad99409..5f3b54e 100644 --- a/src/test/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceTest.java +++ b/src/test/java/it/gov/pagopa/onboarding/citizen/service/CitizenServiceTest.java @@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; @ExtendWith({SpringExtension.class, MockitoExtension.class}) @ContextConfiguration(classes = { @@ -61,6 +62,26 @@ void createCitizenConsent_Ok() { Mockito.when(citizenRepository.save(Mockito.any())) .thenReturn(Mono.just(CITIZEN_CONSENT)); + Mockito.when(citizenRepository.findById(anyString())) + .thenReturn(Mono.empty()); + + CitizenConsentDTO response = citizenService.createCitizenConsent(CITIZEN_CONSENT_DTO).block(); + assertNotNull(response); + + assertEquals(citizenConsentDTO, response); + } + + @Test + void createCitizenConsent_AlreadyExists() { + + CitizenConsentDTO citizenConsentDTO = dtoMapper.map(CITIZEN_CONSENT); + + Mockito.when(citizenRepository.save(Mockito.any())) + .thenReturn(Mono.empty()); + + Mockito.when(citizenRepository.findById(anyString())) + .thenReturn(Mono.just(CITIZEN_CONSENT)); + CitizenConsentDTO response = citizenService.createCitizenConsent(CITIZEN_CONSENT_DTO).block(); assertNotNull(response); @@ -103,7 +124,7 @@ void updateChannelState_Ko_CitizenNotOnboarded() { Executable executable = () -> citizenService.updateChannelState(FISCAL_CODE, TPP_ID, true).block(); ClientExceptionWithBody exception = assertThrows(ClientExceptionWithBody.class, executable); - assertEquals("Citizen not founded during update state process", exception.getMessage()); + assertEquals("Citizen consent not founded during update state process", exception.getMessage()); } @Test @@ -126,7 +147,7 @@ void getConsentStatus_Ko_CitizenNotOnboarded() { Executable executable = () -> citizenService.getConsentStatus(FISCAL_CODE, TPP_ID).block(); ClientExceptionWithBody exception = assertThrows(ClientExceptionWithBody.class, executable); - assertEquals("Citizen not founded during get process ", exception.getMessage()); + assertEquals("Citizen consent not founded during get process ", exception.getMessage()); } @Test