Skip to content

Commit

Permalink
changed validation in ChatLinkDto.java from @notblank to @NotNull, (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KizerovDmitriy authored Dec 26, 2024
1 parent 89871ac commit a6a4d2f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions service-api/src/main/java/greencity/dto/user/ChatLinkDto.java
Original file line number Diff line number Diff line change
@@ -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) {
}
5 changes: 5 additions & 0 deletions service/src/test/java/greencity/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -5702,4 +5703,8 @@ public static Employee createTestEmployee(Long id) {
employee.setEmail("[email protected]");
return employee;
}

public static ChatLinkDto getChatLinkDto(String link) {
return new ChatLinkDto(1L, link);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit a6a4d2f

Please sign in to comment.