-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-5465] fix: Calculation of moduleOfEpoch Attribute Based on Onbo…
…arding Creation Date (#28)
- Loading branch information
Showing
8 changed files
with
71 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
import it.pagopa.selfcare.mscore.model.institution.Billing; | ||
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.onboarding.Token; | ||
import it.pagopa.selfcare.mscore.model.onboarding.VerifyOnboardingFilters; | ||
import it.pagopa.selfcare.mscore.model.pecnotification.PecNotification; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -22,18 +23,20 @@ | |
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
|
||
import java.time.LocalDate; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
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.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ContextConfiguration(classes = {OnboardingServiceImpl.class}) | ||
|
@@ -139,9 +142,6 @@ 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(); | ||
|
@@ -152,6 +152,7 @@ void persistOnboarding_whenUserExistsOnRegistry() { | |
when(institutionConnector.findById(institution.getId())).thenReturn(institution); | ||
when(institutionSendMailConfig.getPecNotificationDisabled()).thenReturn(false); | ||
when(institutionSendMailConfig.getProducts()).thenReturn(Map.of(onboarding.getProductId(),30)); | ||
when(institutionSendMailConfig.getEpochDatePecNotification()).thenReturn("2024-01-01"); | ||
|
||
String institutionId = institution.getId(); | ||
|
||
|
@@ -169,9 +170,6 @@ void persistOnboarding_whenUserExistsOnRegistry() { | |
@Test | ||
void persistOnboarding_whenPecNotificationIsDisabled() { | ||
|
||
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(); | ||
|
@@ -236,9 +234,6 @@ 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(); | ||
|
@@ -274,6 +269,7 @@ void persistOnboarding_whenUserNotExistsOnRegistry() { | |
when(institutionConnector.findAndUpdate(any(), any(), any(), any())).thenReturn(institution); | ||
when(institutionSendMailConfig.getPecNotificationDisabled()).thenReturn(false); | ||
when(institutionSendMailConfig.getProducts()).thenReturn(Map.of(productId,30)); | ||
when(institutionSendMailConfig.getEpochDatePecNotification()).thenReturn("2024-01-01"); | ||
|
||
StringBuilder statusCode = new StringBuilder(); | ||
|
||
|
@@ -344,15 +340,37 @@ void deleteOnboardedInstitution_deletePecNotificationFails() { | |
verify(pecNotificationConnector, times(1)).findAndDeletePecNotification(institutionId, productId); | ||
} | ||
|
||
|
||
|
||
@Test | ||
public void testCalculateModuleDayOfTheEpoch() { | ||
LocalDate mockCurrentDate = LocalDate.of(2024, 2, 1); // 31 days after epoch | ||
public void insertPecNotification() { | ||
String institutionId = "testInstitution"; | ||
String productId = "testProduct"; | ||
String digitalAddress = "[email protected]"; | ||
OffsetDateTime createdAtOnboarding = OffsetDateTime.of(2024, 8, 30, 10, 0, 0, 0, ZoneOffset.UTC); | ||
|
||
Map<String, Integer> products = new HashMap<>(); | ||
products.put(productId, 30); | ||
|
||
ReflectionTestUtils.setField(onboardingServiceImpl, "sendingFrequencyPecNotification", 30); | ||
ReflectionTestUtils.setField(onboardingServiceImpl, "epochDatePecNotification", "2024-01-01"); | ||
ReflectionTestUtils.setField(onboardingServiceImpl, "currentDate", mockCurrentDate); | ||
when(institutionSendMailConfig.getPecNotificationDisabled()).thenReturn(false); | ||
when(institutionSendMailConfig.getProducts()).thenReturn(products); | ||
when(institutionSendMailConfig.getEpochDatePecNotification()).thenReturn("2024-01-01"); | ||
when(pecNotificationConnector.insertPecNotification(any())).thenReturn(true); | ||
|
||
// Act | ||
onboardingServiceImpl.insertPecNotification(institutionId, productId, digitalAddress, createdAtOnboarding); | ||
|
||
// Assert | ||
ArgumentCaptor<PecNotification> argumentCaptor = ArgumentCaptor.forClass(PecNotification.class); | ||
verify(pecNotificationConnector, times(1)).insertPecNotification(argumentCaptor.capture()); | ||
assertEquals(2, argumentCaptor.getValue().getModuleDayOfTheEpoch()); | ||
} | ||
|
||
@Test | ||
public void testCalculateModuleDayOfTheEpoch() { | ||
OffsetDateTime mockCurrentDate = OffsetDateTime.of(2024, 2, 1, 0, 0, 0, 0, ZoneOffset.UTC); // 31 days after epoch | ||
|
||
int result = onboardingServiceImpl.calculateModuleDayOfTheEpoch(); | ||
int result = onboardingServiceImpl.calculateModuleDayOfTheEpoch("2024-01-01", mockCurrentDate, 30); | ||
|
||
LocalDate epochStart = LocalDate.parse("2024-01-01"); | ||
long daysDiff = ChronoUnit.DAYS.between(epochStart, mockCurrentDate); | ||
|
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 |
---|---|---|
|
@@ -12,10 +12,10 @@ institution-send-mail.destination-mail = ${MAIL_DESTINATION_TEST:true} | |
## If MAIL_DESTINATION_TEST is true, app send mail to this address | ||
institution-send-mail.destination-mail-test-address = ${MAIL_DESTINATION_TEST_ADDRESS:[email protected]} | ||
|
||
institution-send-mail.notification-path= ${MAIL_TEMPLATE_NOTIFICATION_PATH:test.json} | ||
institution-send-mail.first-notification-path =${MAIL_TEMPLATE_FIRST_NOTIFICATION_PATH:test.json} | ||
institution-send-mail.notification-path= ${MAIL_TEMPLATE_NOTIFICATION_PATH:contracts/template/mail/institution-user-list-notification/1.0.0.json} | ||
institution-send-mail.first-notification-path =${MAIL_TEMPLATE_FIRST_NOTIFICATION_PATH:contracts/template/mail/institution-user-list-first-notification/1.0.0.json} | ||
|
||
institution-send-mail.notification-query-size = 1000 | ||
institution-send-mail.notification-query-size = ${MAIL_QUERY_SIZE:10} | ||
institution-send-mail.notification-start-date = 2024-01-01 | ||
institution-send-mail.notification-send-all = ${SEND_ALL_NOTIFICATION:false} | ||
|
||
|
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