Skip to content

Commit

Permalink
feat: DELPHI-190-Add_Information_to_Advice_Seeker_Profile
Browse files Browse the repository at this point in the history
Add new information and adapt tests
  • Loading branch information
Leandro13Silva13 committed Dec 2, 2024
1 parent dfe861d commit e789a25
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/userservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,9 @@ components:
type: integer
format: int64
example: 100
agencyName:
type: string
example: AgencyName
consultingType:
type: integer
example: 1
Expand Down Expand Up @@ -2275,6 +2278,9 @@ components:
isTeamSession:
type: boolean
example: false
create_date:
type: string
description: date of user registration
age:
type: integer
example: 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ private ConsultantSessionDTO toConsultantSessionDTO(Session session) {

var consultantSessionDTO =
new ConsultantSessionDTO()
.agencyName(agencyService.getAgency(session.getAgencyId()).getName())
.isTeamSession(session.isTeamSession())
.agencyId(session.getAgencyId())
.consultingType(session.getConsultingTypeId())
Expand All @@ -647,6 +648,7 @@ private ConsultantSessionDTO toConsultantSessionDTO(Session session) {
.consultantId(nonNull(session.getConsultant()) ? session.getConsultant().getId() : null)
.consultantRcId(
nonNull(session.getConsultant()) ? session.getConsultant().getRocketChatId() : null)
.createDate(String.valueOf(session.getCreateDate()))
.age(session.getUserAge())
.gender(session.getUserGender())
.counsellingRelation(session.getCounsellingRelation())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;

import com.neovisionaries.i18n.LanguageCode;
import de.caritas.cob.userservice.agencyserivce.generated.ApiClient;
import de.caritas.cob.userservice.agencyserivce.generated.web.AgencyControllerApi;
import de.caritas.cob.userservice.api.UserServiceApplication;
import de.caritas.cob.userservice.api.adapters.web.dto.AgencyDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.ConsultantSessionDTO;
import de.caritas.cob.userservice.api.config.apiclient.AgencyServiceApiControllerFactory;
import de.caritas.cob.userservice.api.config.apiclient.TopicServiceApiControllerFactory;
Expand All @@ -21,6 +23,7 @@
import de.caritas.cob.userservice.api.port.out.ConsultantRepository;
import de.caritas.cob.userservice.api.port.out.SessionRepository;
import de.caritas.cob.userservice.api.port.out.UserRepository;
import de.caritas.cob.userservice.api.service.agency.AgencyService;
import de.caritas.cob.userservice.topicservice.generated.web.TopicControllerApi;
import java.util.Collections;
import java.util.Set;
Expand All @@ -44,6 +47,8 @@ class SessionServiceIT {

@Autowired private SessionService sessionService;

@MockBean private AgencyService agencyService;

@Autowired private SessionRepository sessionRepository;

@Autowired private ConsultantRepository consultantRepository;
Expand All @@ -65,6 +70,11 @@ private void setUp() {
when(topicServiceApiControllerFactory.createControllerApi()).thenReturn(topicControllerApi);
when(agencyServiceApiControllerFactory.createControllerApi()).thenReturn(agencyControllerApi);
when(agencyControllerApi.getApiClient()).thenReturn(new ApiClient());

AgencyDTO mockAgency = new AgencyDTO();
mockAgency.setId(1L);
mockAgency.setName("Mock Agency");
when(agencyService.getAgency(anyLong())).thenReturn(mockAgency);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static org.powermock.reflect.Whitebox.setInternalState;

import com.neovisionaries.i18n.LanguageCode;
import de.caritas.cob.userservice.api.adapters.web.dto.AgencyDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.ConsultantSessionDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.ConsultantSessionResponseDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.SessionConsultantForConsultantDTO;
Expand Down Expand Up @@ -580,6 +581,8 @@ void fetchSessionForConsultant_Should_Return_ValidConsultantSessionDTO() {
session.setConsultant(CONSULTANT_WITH_AGENCY);
session.setUser(USER_WITH_RC_ID);
when(sessionRepository.findById(session.getId())).thenReturn(Optional.of(session));
AgencyDTO agencyDTO = Mockito.mock(AgencyDTO.class);
when(agencyService.getAgency(session.getAgencyId())).thenReturn(agencyDTO);

ConsultantSessionDTO result =
sessionService.fetchSessionForConsultant(session.getId(), CONSULTANT_WITH_AGENCY);
Expand All @@ -600,6 +603,7 @@ void fetchSessionForConsultant_Should_Return_ValidConsultantSessionDTO() {
assertEquals(session.getUserGender(), result.getGender());
assertEquals(session.getCounsellingRelation(), result.getCounsellingRelation());
assertEquals(session.getReferer(), result.getReferer());
assertEquals(String.valueOf(session.getCreateDate()), result.getCreateDate());
}

@Test
Expand All @@ -613,6 +617,8 @@ void fetchSessionForConsultant_Should_Return_ValidConsultantSessionDTO() {
session.setConsultant(CONSULTANT_WITH_AGENCY);
session.setUser(USER_WITH_RC_ID);
when(sessionRepository.findById(session.getId())).thenReturn(Optional.of(session));
AgencyDTO agencyDTO = Mockito.mock(AgencyDTO.class);
when(agencyService.getAgency(session.getAgencyId())).thenReturn(agencyDTO);

ConsultantSessionDTO result =
sessionService.fetchSessionForConsultant(session.getId(), CONSULTANT_WITH_AGENCY);
Expand All @@ -636,6 +642,8 @@ void fetchSessionForConsultant_Should_Return_ValidConsultantSessionDTO() {
session.setConsultant(CONSULTANT_WITH_AGENCY);
session.setUser(USER_WITH_RC_ID);
when(sessionRepository.findById(session.getId())).thenReturn(Optional.of(session));
AgencyDTO agencyDTO = Mockito.mock(AgencyDTO.class);
when(agencyService.getAgency(session.getAgencyId())).thenReturn(agencyDTO);

sessionService.fetchSessionForConsultant(session.getId(), CONSULTANT_WITH_AGENCY);

Expand All @@ -647,6 +655,26 @@ void fetchSessionForConsultant_Should_Return_ValidConsultantSessionDTO() {
ReflectionTestUtils.setField(sessionService, "topicsFeatureEnabled", false);
}

@Test
void
fetchSessionForConsultant_Should_Return_ConsultantSessionDTO_containing_createDate_and_agencyName() {

Session session = easyRandom.nextObject(Session.class);
session.setConsultant(CONSULTANT_WITH_AGENCY);
session.setUser(USER_WITH_RC_ID);
when(sessionRepository.findById(session.getId())).thenReturn(Optional.of(session));
AgencyDTO agencyDTO = new AgencyDTO();
agencyDTO.name("TestName");
when(agencyService.getAgency(session.getAgencyId())).thenReturn(agencyDTO);

ConsultantSessionDTO result =
sessionService.fetchSessionForConsultant(session.getId(), CONSULTANT_WITH_AGENCY);

assertNotNull(result.getAgencyName());
assertEquals("TestName", result.getAgencyName());
assertEquals(String.valueOf(session.getCreateDate()), result.getCreateDate());
}

@Test
void fetchSessionForConsultant_Should_ThrowForbiddenException_When_NoPermission() {

Expand All @@ -672,6 +700,8 @@ void fetchSessionForConsultant_Should_Return_ConsultantSessionDTO_WhenConsultant
session.setAgencyId(
CONSULTANT_WITH_AGENCY.getConsultantAgencies().iterator().next().getAgencyId());
when(sessionRepository.findById(session.getId())).thenReturn(Optional.of(session));
AgencyDTO agencyDTO = Mockito.mock(AgencyDTO.class);
when(agencyService.getAgency(session.getAgencyId())).thenReturn(agencyDTO);

assertNotNull(
sessionService.fetchSessionForConsultant(session.getId(), CONSULTANT_WITH_AGENCY));
Expand All @@ -688,6 +718,8 @@ void fetchSessionForConsultant_Should_Return_ConsultantSessionDTO_WhenConsultant
session.setAgencyId(
CONSULTANT_WITH_AGENCY.getConsultantAgencies().iterator().next().getAgencyId());
when(sessionRepository.findById(session.getId())).thenReturn(Optional.of(session));
AgencyDTO agencyDTO = Mockito.mock(AgencyDTO.class);
when(agencyService.getAgency(session.getAgencyId())).thenReturn(agencyDTO);

assertNotNull(
sessionService.fetchSessionForConsultant(session.getId(), CONSULTANT_WITH_AGENCY));
Expand Down

0 comments on commit e789a25

Please sign in to comment.