Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #125

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.vi.appointmentservice.api.calcom.repository.MembershipsRepository;
import com.vi.appointmentservice.api.calcom.repository.WebhookRepository;
import com.vi.appointmentservice.api.facade.AppointmentType;
import com.vi.appointmentservice.api.facade.DefaultTextConstants;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -173,4 +174,14 @@ public void deleteEventType(Long eventTypeId) {
eventTypeRepository.removeTeamEventTypeMembershipsForEventType(eventTypeId);
eventTypeRepository.removeTeamEventHostsForEventType(eventTypeId);
}

public void updateEventTypeTitle(Long calComUserId, String displayName) {
CalcomEventType eventTypeByUserId = getEventTypeByUserId(calComUserId);
if (eventTypeByUserId.getTitle().contains(DefaultTextConstants.BERATUNG_MIT)) {
eventTypeByUserId.setTitle(DefaultTextConstants.BERATUNG_MIT_DEM_DER_BERATER_IN + " " + displayName);
eventTypeRepository.updateEventType(eventTypeByUserId);
} else {
log.warn("Skipping update of EventType because event type for the user {} does not contain text {}", calComUserId, DefaultTextConstants.BERATUNG_MIT_DEM_DER_BERATER_IN);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.vi.appointmentservice.api.facade;

import com.google.common.collect.Lists;
import com.vi.appointmentservice.api.calcom.model.CalcomEventType;
import com.vi.appointmentservice.api.calcom.model.CalcomUser;
import com.vi.appointmentservice.api.calcom.repository.AvailabilityRepository;
import com.vi.appointmentservice.api.calcom.repository.BookingRepository;
Expand Down Expand Up @@ -76,8 +78,11 @@ public void patchAppointmentUser(String consultantId, PatchConsultantDTO consult
var name = getDisplayNameOrFallbackToFirstname(consultant);
Optional<CalcomUserToConsultant> userConsultant = userToConsultantRepository
.findByConsultantId(consultantId);
Long calComUserId = userConsultant.orElseThrow().getCalComUserId();
calComUserService
.updateUsername(userConsultant.orElseThrow().getCalComUserId(), name);
.updateUsername(calComUserId, name);

calComEventTypeService.updateEventTypeTitle(calComUserId, name);
}

private void linkConsultantToAppointmentUser(
Expand All @@ -90,7 +95,7 @@ private void linkConsultantToAppointmentUser(
void setupDefaultScheduleAndEventType(CalcomUser calcomUser) {
Long defaultScheduleId = scheduleRepository.createDefaultSchedule(calcomUser.getId());
AppointmentType defaultAppointmentType = appointmentService.createDefaultAppointmentType();
defaultAppointmentType.setTitle("Beratung mit dem / der Berater:in");
defaultAppointmentType.setTitle(DefaultTextConstants.BERATUNG_MIT_DEM_DER_BERATER_IN);
calComEventTypeService
.createEventType(calcomUser, defaultAppointmentType,
defaultScheduleId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.vi.appointmentservice.api.facade;

public class DefaultTextConstants {

private DefaultTextConstants() {
// private constructor to hide the implicit public one
}

public static final String BERATUNG_MIT = "Beratung mit ";
public static final String BERATUNG_MIT_DEM_DER_BERATER_IN = "Beratung mit dem / der Berater:in";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vi.appointmentservice.api.service.calcom;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -12,6 +13,7 @@
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
Expand Down Expand Up @@ -63,4 +65,23 @@ public void shouldCreateEventTypeAndNotUpdateLocationsIfAppointmentTypeDoesNotCo
Mockito.verify(eventTypeRepository, Mockito.never()).updateLocations(Mockito.anyInt(), Mockito.anyString());
}

@Test
public void shouldUpdateEventTypeTitle() {
// given
var eventType = new CalcomEventType();
eventType.setId(1);
eventType.setTitle("Beratung mit dem / der Berater:in ConsultantFirstname");

Long calcomUserId = 2L;
when(eventTypeRepository.getEventTypeByUserId(calcomUserId)).thenReturn(eventType);

// when
calcomEventTypeService.updateEventTypeTitle(calcomUserId, "ConsultantDisplayName");
// then

ArgumentCaptor<CalcomEventType> captor = ArgumentCaptor.forClass(CalcomEventType.class);
Mockito.verify(eventTypeRepository).updateEventType(captor.capture());
assertThat(captor.getValue().getTitle()).isEqualTo("Beratung mit dem / der Berater:in ConsultantDisplayName");
}

}
Loading