This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-5169] feat : Added record PecNotification in persistOnboarding (#…
…525)
- Loading branch information
1 parent
aa1ec3a
commit bd592f5
Showing
9 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,25 +13,25 @@ | |
import it.pagopa.selfcare.mscore.model.institution.Institution; | ||
import it.pagopa.selfcare.mscore.model.institution.Onboarding; | ||
import it.pagopa.selfcare.mscore.model.onboarding.*; | ||
import it.pagopa.selfcare.mscore.model.pecnotification.PecNotification; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.*; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
|
||
import java.time.LocalDate; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static it.pagopa.selfcare.mscore.constant.GenericError.DELETE_NOTIFICATION_OPERATION_ERROR; | ||
import static it.pagopa.selfcare.mscore.constant.GenericError.ONBOARDING_OPERATION_ERROR; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ContextConfiguration(classes = {OnboardingServiceImpl.class}) | ||
|
@@ -134,12 +134,16 @@ void testVerifyOnboardingInfo5() { | |
@Test | ||
void persistOnboarding_whenUserExistsOnRegistry() { | ||
|
||
ReflectionTestUtils.setField(onboardingServiceImpl, "sendingFrequencyPecNotification", 30); | ||
ReflectionTestUtils.setField(onboardingServiceImpl, "epochDatePecNotification", "2024-01-01"); | ||
|
||
Onboarding onboarding = dummyOnboarding(); | ||
onboarding.setStatus(UtilEnumList.VALID_RELATIONSHIP_STATES.get(0)); | ||
|
||
Institution institution = new Institution(); | ||
institution.setId("institutionId"); | ||
institution.setOnboarding(List.of(onboarding, dummyOnboarding())); | ||
|
||
when(pecNotificationConnector.insertPecNotification(any(PecNotification.class))).thenReturn(true); | ||
when(institutionConnector.findById(institution.getId())).thenReturn(institution); | ||
|
||
String institutionId = institution.getId(); | ||
|
@@ -195,6 +199,9 @@ void persistOnboarding_shouldRollback() { | |
@Test | ||
void persistOnboarding_whenUserNotExistsOnRegistry() { | ||
|
||
ReflectionTestUtils.setField(onboardingServiceImpl, "sendingFrequencyPecNotification", 30); | ||
ReflectionTestUtils.setField(onboardingServiceImpl, "epochDatePecNotification", "2024-01-01"); | ||
|
||
String pricingPlan = "pricingPlan"; | ||
String productId = "productId"; | ||
Billing billing = new Billing(); | ||
|
@@ -214,7 +221,7 @@ void persistOnboarding_whenUserNotExistsOnRegistry() { | |
Institution institution = new Institution(); | ||
institution.setId("institutionId"); | ||
institution.setOnboarding(List.of(onboarding)); | ||
|
||
institution.setDigitalAddress("[email protected]"); | ||
|
||
Token token = new Token(); | ||
token.setId(onboarding.getTokenId()); | ||
|
@@ -225,6 +232,7 @@ void persistOnboarding_whenUserNotExistsOnRegistry() { | |
token.setStatus(onboarding.getStatus()); | ||
token.setContractSigned(onboarding.getContract()); | ||
|
||
when(pecNotificationConnector.insertPecNotification(any(PecNotification.class))).thenReturn(true); | ||
when(institutionConnector.findById(institution.getId())).thenReturn(institution); | ||
when(institutionConnector.findAndUpdate(any(), any(), any(), any())).thenReturn(institution); | ||
|
||
|
@@ -240,6 +248,11 @@ void persistOnboarding_whenUserNotExistsOnRegistry() { | |
assertEquals(actual.getCreatedAt().getDayOfYear(), LocalDate.now().getDayOfYear()); | ||
assertEquals(HttpStatus.CREATED.value(), Integer.parseInt(statusCode.toString())); | ||
|
||
ArgumentCaptor< PecNotification > argCaptor = ArgumentCaptor.forClass(PecNotification.class); | ||
verify(pecNotificationConnector, times(1)). insertPecNotification(argCaptor.capture()); | ||
assertEquals(productId, argCaptor.getValue().getProductId()); | ||
assertEquals("institutionId", argCaptor.getValue().getInstitutionId()); | ||
assertEquals("[email protected]", argCaptor.getValue().getDigitalAddress()); | ||
} | ||
|
||
private Onboarding dummyOnboarding() { | ||
|
@@ -291,5 +304,22 @@ void deleteOnboardedInstitution_deletePecNotificationFails() { | |
verify(institutionConnector, times(1)).findAndDeleteOnboarding(institutionId, productId); | ||
verify(pecNotificationConnector, times(1)).findAndDeletePecNotification(institutionId, productId); | ||
} | ||
|
||
@Test | ||
public void testCalculateModuleDayOfTheEpoch() { | ||
LocalDate mockCurrentDate = LocalDate.of(2024, 2, 1); // 31 days after epoch | ||
|
||
ReflectionTestUtils.setField(onboardingServiceImpl, "sendingFrequencyPecNotification", 30); | ||
ReflectionTestUtils.setField(onboardingServiceImpl, "epochDatePecNotification", "2024-01-01"); | ||
ReflectionTestUtils.setField(onboardingServiceImpl, "currentDate", mockCurrentDate); | ||
|
||
int result = onboardingServiceImpl.calculateModuleDayOfTheEpoch(); | ||
|
||
LocalDate epochStart = LocalDate.parse("2024-01-01"); | ||
long daysDiff = ChronoUnit.DAYS.between(epochStart, mockCurrentDate); | ||
int expected = (int) (daysDiff % 30); | ||
|
||
assertEquals(expected, result); | ||
} | ||
} | ||
|