diff --git a/src/main/java/catering/users/UserController.java b/src/main/java/catering/users/UserController.java index 5404c70..66ba41f 100644 --- a/src/main/java/catering/users/UserController.java +++ b/src/main/java/catering/users/UserController.java @@ -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"); } diff --git a/src/test/java/catering/users/UserControllerIntegrationTests.java b/src/test/java/catering/users/UserControllerIntegrationTests.java index a6456b6..5fc7521 100644 --- a/src/test/java/catering/users/UserControllerIntegrationTests.java +++ b/src/test/java/catering/users/UserControllerIntegrationTests.java @@ -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")); + } }