Skip to content

Commit

Permalink
chore: Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu committed Oct 21, 2024
1 parent e50904a commit 4adc6c4
Showing 1 changed file with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,25 @@
import it.pagopa.selfcare.onboarding.common.InstitutionType;
import it.pagopa.selfcare.onboarding.common.WorkflowType;
import it.pagopa.selfcare.onboarding.dto.*;
import it.pagopa.selfcare.onboarding.dto.QueueEvent;
import it.pagopa.selfcare.onboarding.dto.UserToNotify;
import it.pagopa.selfcare.onboarding.entity.Billing;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.Token;
import it.pagopa.selfcare.onboarding.exception.NotificationException;
import it.pagopa.selfcare.onboarding.repository.TokenRepository;
import it.pagopa.selfcare.onboarding.utils.BaseNotificationBuilder;
import it.pagopa.selfcare.onboarding.utils.NotificationBuilderFactory;
import it.pagopa.selfcare.onboarding.utils.QueueEventExaminer;
import it.pagopa.selfcare.onboarding.utils.*;
import it.pagopa.selfcare.product.entity.Product;
import it.pagopa.selfcare.product.service.ProductService;
import jakarta.inject.Inject;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;
import org.openapi.quarkus.core_json.api.InstitutionApi;
import org.openapi.quarkus.core_json.model.InstitutionResponse;
import org.openapi.quarkus.user_json.model.UserDataResponse;
import org.openapi.quarkus.user_json.model.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.logging.Logger;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -51,6 +48,9 @@ public class NotificationEventServiceDefaultTest {
@InjectMock
NotificationBuilderFactory notificationBuilderFactory;

@InjectMock
NotificationUserBuilderFactory notificationUserBuilderFactory;

@InjectMock
TokenRepository tokenRepository;

Expand Down Expand Up @@ -362,10 +362,63 @@ void notificationEventUserMapTest() {

assertEquals("userId", properties.get("userId"));
assertEquals("OPERATOR", properties.get("role"));
}

@Test
void getNotificationUserToSendTest() {
Onboarding onboarding = createOnboarding();
InstitutionResponse institutionResponse = new InstitutionResponse();
Token token = new Token();
NotificationsResources notificationsResources = new NotificationsResources(onboarding,
institutionResponse, token, QueueEvent.ADD);

OnboardedProductResponse onboardedProductResponse = new OnboardedProductResponse();
onboardedProductResponse.productId("prod-fd-garantito");
onboardedProductResponse.setEnv(Env.ROOT);
onboardedProductResponse.setStatus(OnboardedProductState.ACTIVE);


UserResponse userResponse = new UserResponse();
userResponse.setId("userId");
userResponse.setTaxCode("taxcode");
userResponse.setName("Name");
userResponse.setSurname("Surname");
userResponse.setEmail("prv@email");
HashMap<String, String> workContacts = new HashMap<String, String>();
workContacts.put("email", "work@email");
userResponse.setWorkContacts(workContacts);

UserDataResponse userDataResponse = new UserDataResponse();
userDataResponse.setId("userId");
userDataResponse.institutionId("institutionId");
userDataResponse.setInstitutionDescription("Institution Name");
userDataResponse.setUserMailUuid("userMailId");
userDataResponse.role("MANAGER");
userDataResponse.setStatus("ADD");
userDataResponse.setProducts(List.of(onboardedProductResponse));
userDataResponse.setUserResponse(userResponse);

NotificationUserToSend notificationUserToSendMock = new NotificationUserToSend();
notificationUserToSendMock.setId("eventId");
notificationUserToSendMock.setInstitutionId("institutionId");
notificationUserToSendMock.setProduct("prod-fd-garantito");
notificationUserToSendMock.setOnboardingTokenId("onboardingId");

FdNotificationBuilder fdNotificationBuilder = mock(FdNotificationBuilder.class);
when(notificationUserBuilderFactory.create(any())).thenReturn(fdNotificationBuilder);
when(fdNotificationBuilder.buildUserNotificationToSend(any(), any(), any(), any(), any(), any(), any(),
any(), any())).thenReturn(notificationUserToSendMock);
when(fdNotificationBuilder.shouldSendUserNotification(any(), any())).thenReturn(true);
doNothing().when(eventHubRestClient).sendMessage(anyString(), anyString());


NotificationUserToSend notificationUserToSend = NotificationEventServiceDefault.getNotificationUserToSend(notificationsResources, userDataResponse,
onboardedProductResponse, fdNotificationBuilder);

assertNotNull(notificationUserToSend);
}


private static InstitutionToNotify getInstitutionToNotify() {
InstitutionToNotify institution = new InstitutionToNotify();
institution.setDescription("description");
Expand Down Expand Up @@ -393,4 +446,5 @@ private static NotificationUserToSend getNotificationUserBaseToSend() {
notificationUserToSend.setProduct("prod");
return notificationUserToSend;
}

}

0 comments on commit 4adc6c4

Please sign in to comment.