diff --git a/service-api/src/main/java/greencity/dto/user/ChatLinkDto.java b/service-api/src/main/java/greencity/dto/user/ChatLinkDto.java index c6c98a942..236698c1d 100644 --- a/service-api/src/main/java/greencity/dto/user/ChatLinkDto.java +++ b/service-api/src/main/java/greencity/dto/user/ChatLinkDto.java @@ -1,12 +1,12 @@ package greencity.dto.user; import com.fasterxml.jackson.annotation.JsonProperty; -import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; import org.hibernate.validator.constraints.Length; public record ChatLinkDto( Long userId, - @JsonProperty("link") @Length(max = 255) @NotBlank @Pattern(regexp = "^https://my\\.binotel\\.ua.*", + @JsonProperty("link") @Length(max = 255) @NotNull @Pattern(regexp = "^https://my\\.binotel\\.ua.*", message = "Link must start with 'https://my.binotel.ua'") String link) { } diff --git a/service/src/test/java/greencity/ModelUtils.java b/service/src/test/java/greencity/ModelUtils.java index 684cf12f6..f56b19955 100644 --- a/service/src/test/java/greencity/ModelUtils.java +++ b/service/src/test/java/greencity/ModelUtils.java @@ -113,6 +113,7 @@ import greencity.dto.tariff.GetTariffLimitsDto; import greencity.dto.tariff.GetTariffsInfoDto; import greencity.dto.tariff.SetTariffLimitsDto; +import greencity.dto.user.ChatLinkDto; import greencity.dto.user.PersonalDataDto; import greencity.dto.user.UserInfoDto; import greencity.dto.user.UserPointsAndAllBagsDto; @@ -5702,4 +5703,8 @@ public static Employee createTestEmployee(Long id) { employee.setEmail("test@example.com"); return employee; } + + public static ChatLinkDto getChatLinkDto(String link) { + return new ChatLinkDto(1L, link); + } } diff --git a/service/src/test/java/greencity/service/ubs/OrdersAdminsPageServiceImplTest.java b/service/src/test/java/greencity/service/ubs/OrdersAdminsPageServiceImplTest.java index 307fb6338..894c7a625 100644 --- a/service/src/test/java/greencity/service/ubs/OrdersAdminsPageServiceImplTest.java +++ b/service/src/test/java/greencity/service/ubs/OrdersAdminsPageServiceImplTest.java @@ -133,6 +133,7 @@ class OrdersAdminsPageServiceImplTest { private static final String ADDRESS_COMMENT = "commentToAddressForClient"; private static final String CLIENT_COMMENT = "commentForOrderByClient"; private static final String ORDER_COMMENT = "commentsForOrder"; + private static final String CHAT_LINK = "https://my.binotel.ua/f/chat/#/visitor/21269249.12893974"; @Test void getParametersForOrdersExceptionTable() { @@ -1362,7 +1363,26 @@ void addChatLinkToUserTest() { when(userRepository.findById(anyLong())).thenReturn(Optional.ofNullable(ModelUtils.getUser())); ordersAdminsPageService - .addChatLinkToUser(new ChatLinkDto(1L, "https://my.binotel.ua/f/chat/#/visitor/21269249.12893974")); + .addChatLinkToUser(ModelUtils.getChatLinkDto(CHAT_LINK)); + + verify(userRepository).findById(anyLong()); + verify(userRepository).save(any(User.class)); + } + + @Test + void addChatLinkToUserWithNotExistingUserTest() { + ChatLinkDto chatLinkDto = ModelUtils.getChatLinkDto(CHAT_LINK); + when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); + + assertThrows(NotFoundException.class, + () -> ordersAdminsPageService.addChatLinkToUser(chatLinkDto)); + } + + @Test + void addChatLinkToUserWithEmptyLinkTest() { + when(userRepository.findById(anyLong())).thenReturn(Optional.ofNullable(ModelUtils.getUser())); + + ordersAdminsPageService.addChatLinkToUser(ModelUtils.getChatLinkDto("")); verify(userRepository).findById(anyLong()); verify(userRepository).save(any(User.class));