Skip to content

Commit

Permalink
Mapper fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitolo-Andrea committed Oct 23, 2024
1 parent 1f71071 commit 2d6e875
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public Mono<CitizenConsentDTO> createCitizenConsent(CitizenConsentDTO citizenCon
citizenConsent.setCreationDate(LocalDateTime.now());
citizenConsent.setLastUpdateDate(LocalDateTime.now());
log.info("[EMD-CITIZEN][CREATE] Received consent: {}",inputSanify(citizenConsent.toString()));
return citizenRepository.findById(hashedFiscalCode)
return citizenRepository.findByHashedFiscalCodeAndTppId(hashedFiscalCode,citizenConsent.getTppId())
.flatMap(existingConsent -> {
log.info("[EMD][CREATE-CITIZEN-CONSENT] Citizen consent already exists");
return Mono.just(mapperToDTO.map(existingConsent));
})
.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)))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2d6e875

Please sign in to comment.