These action fail in browser

This commit is contained in:
Denis Natusch 2024-01-14 13:56:12 +01:00
parent ff8bbdca15
commit 8974e933cd
No known key found for this signature in database
GPG key ID: 5E57BD8EDACFA985
2 changed files with 20 additions and 1 deletions

View file

@ -155,7 +155,7 @@ public class UserController {
if (
!result.hasErrors() &&
!userManagement.getUserByName(form.getUsername()).isEmpty() &&
!user.getUsername().equals(form.getUsername())
(user.getUsername() != form.getUsername())
) {
result.rejectValue("username", "username already in use");
}

View file

@ -59,6 +59,7 @@ class UserControllerIntegrationTests {
createTestUser("paul");
createTestUser("mark");
createTestUser("eva");
createTestUser("sarah");
}
@Test
@ -133,6 +134,8 @@ class UserControllerIntegrationTests {
String streetPost = userManagement.getUserByName("tim").get().getAddress();
assertThat(streetPost).isNotEqualTo(streetPre);
System.out.println(streetPre);
System.out.println(streetPost);
}
// This test is necessary, because the password in the profile form is not
@ -353,4 +356,20 @@ class UserControllerIntegrationTests {
).andExpect(content().string(containsString("Ungültiger Nutzername")));
assertTrue(userAccountManagement.findByUsername("eva").isPresent());
}
@Test
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
void editCustomerDetailsExeptUsername() throws Exception {
mvc.perform(post("/customers/edit/" + userManagement.getUserByName("sarah").get().getId())
.param("username", "sarah")
.param("fullName", "Moan Klaus")
.param("address", "Baum Straße"))
.andExpect(redirectedUrl("/customers"));
assertThat(userManagement.getUsers().findAll())
.extracting("username", "fullName", "address")
.contains(tuple("sarah", "Moan Klaus", "Baum Straße"));
mvc.perform(get("/customers/edit/" + userManagement.getUserByName("sarah").get().getId()))
.andExpect(status().isOk())
.andExpect(view().name("edit-customer"));
}
}