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

#6125 Numeric data entered in the Name and Surname text fields is not saved #1202

Merged
merged 3 commits into from
Jul 31, 2023
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 @@ -27,10 +27,10 @@
@EqualsAndHashCode
public class UserProfileUpdateDto implements Serializable {
@NotBlank
@Pattern(regexp = "[ЁёІіЇїҐґЄєА-Яа-яA-Za-z-ʼ'`ʹ\\s.]{1,30}")
@Pattern(regexp = "^(?!\\s*$)[ЁёІіЇїҐґЄєА-Яа-яA-Za-z0-9ʼ'`ʹ\\s-]{1,30}$")
private String recipientName;
@NotBlank
@Pattern(regexp = "[ЁёІіЇїҐґЄєА-Яа-яA-Za-z\\s-ʼ'`ʹ.]{1,30}")
@Pattern(regexp = "^(?!\\s*$)[ЁёІіЇїҐґЄєА-Яа-яA-Za-z0-9ʼ'`ʹ\\s-]{1,30}$")
private String recipientSurname;
@Email
@Pattern(regexp = "[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package greencity.dto.user;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.lang.reflect.Field;

import static org.junit.jupiter.api.Assertions.assertEquals;

class UserProfileUpdateDtoTest {
void checkRegexPattern(String fieldName, String testValue, boolean validates) throws NoSuchFieldException {
Field field = UserProfileUpdateDto.class.getDeclaredField(fieldName);
javax.validation.constraints.Pattern[] annotations =
field.getAnnotationsByType(javax.validation.constraints.Pattern.class);
assertEquals(testValue.matches(annotations[0].regexp()), validates);
}

@ParameterizedTest
@ValueSource(
strings = {"John Doe", "абвгґіїьяюєёАБВГҐІЇЬЯЮЄЁ-ʼ'`ʹ", "John-Doe", "John Doe12", "John Doe 12", "Johnʼ'`ʹDoe",
"ValidNameWithMaxLengthEquals30"})
void testValidRecipientName(String name) throws NoSuchFieldException {
checkRegexPattern("recipientName", name, true);
}

@ParameterizedTest
@ValueSource(
strings = {"InvalidLengthOfName31Characters", "", " ", "!?+=@#$%^&*", "тест!", "тест@123", "Hello World!"})
void testInvalidRecipientName(String name) throws NoSuchFieldException {
checkRegexPattern("recipientName", name, false);
}

@ParameterizedTest
@ValueSource(
strings = {"John Doe", "абвгґіїьяюєёАБВГҐІЇЬЯЮЄЁ-ʼ'`ʹ", "John-Doe", "John Doe12", "John Doe 12", "Johnʼ'`ʹDoe",
"ValidNameWithMaxLengthEquals30"})
void testValidRecipientSurname(String name) throws NoSuchFieldException {
checkRegexPattern("recipientSurname", name, true);
}

@ParameterizedTest
@ValueSource(
strings = {"InvalidLengthOfName31Characters", "", " ", "!?+=@#$%^&*", "тест!", "тест@123", "Hello World!"})
void testInvalidRecipientSurname(String name) throws NoSuchFieldException {
checkRegexPattern("recipientSurname", name, false);
}
}