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

Update signup with empty names #299

Merged
merged 17 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 @@ -73,12 +73,10 @@ public class Account extends AbstractAuditingEntity implements Identifiable<Long
@ToString.Exclude
private String password;

@NotBlank
@Size(min = 1, max = 50)
@Size(max = 50)
private String firstName;

@NotBlank
@Size(min = 1, max = 50)
@Size(max = 50)
private String lastName;

@OneToMany(mappedBy = "account", cascade = ALL, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.hexlet.typoreporter.domain.account.constraint.AccountUsername;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -20,11 +19,9 @@ public class UpdateProfile {
message = "The email \"${validatedValue}\" is not valid")
private String email;

@NotBlank
@Size(min = 1, max = 50)
@Size(max = 50)
private String firstName;

@NotBlank
@Size(min = 1, max = 50)
@Size(max = 50)
private String lastName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.hexlet.typoreporter.domain.account.constraint.AccountUsername;
import io.hexlet.typoreporter.service.dto.FieldMatchConsiderCase;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -38,11 +37,9 @@ public class SignupAccountModel {
@ToString.Exclude
private String confirmPassword;

@NotBlank
@Size(min = 1, max = 50)
@Size(max = 50)
private String firstName;

@NotBlank
@Size(min = 1, max = 50)
@Size(max = 50)
private String lastName;
}
18 changes: 18 additions & 0 deletions src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static void datasourceProperties(DynamicPropertyRegistry registry) {

private static final String EMAIL_UPPER_CASE = "[email protected]";
private static final String EMAIL_LOWER_CASE = EMAIL_UPPER_CASE.toLowerCase();
private static final String EMPTY_NAME = "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давайте не будем это в статические свойства класса выносить. У нас ведь только один тест использует это свойство. Достаточно локальной переменной

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

исправлено


private final SignupAccountModel model = new SignupAccountModel(
"model_upper_case",
Expand Down Expand Up @@ -93,6 +94,23 @@ void createAccountWithIgnoreEmailCase() throws Exception {
assertThat(accountRepository.count()).isEqualTo(1L);
}

@Test
void createAccountWithEmptyNames() throws Exception {
String emptyNamesUser = "testEmptyNamesUser";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше просто username, email, если считаете, что переменные нужны. А то сейчас диссонанс, называется empty, а по факту там не путсая строка

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

исправлено

String emptyNamesEmail = "[email protected]";
String emptyNamesPassword = "P@$$w0rd";
mockMvc.perform(post("/signup")
.param("username", emptyNamesUser)
.param("email", emptyNamesEmail)
.param("password", emptyNamesPassword)
.param("confirmPassword", emptyNamesPassword)
.param("firstName", EMPTY_NAME)
.param("lastName", EMPTY_NAME)
.with(csrf()))
.andReturn();
assertThat(accountRepository.findAccountByEmail(emptyNamesEmail)).isNotEmpty();
}

@Test
void createAccountWithWrongEmailDomain() throws Exception {
String userName = "testUser";
Expand Down
Loading