From 8974e933cdc98b338dc83a76b2431c34aec66799 Mon Sep 17 00:00:00 2001 From: Denis Natusch Date: Sun, 14 Jan 2024 13:56:12 +0100 Subject: [PATCH] These action fail in browser --- .../java/catering/users/UserController.java | 2 +- .../users/UserControllerIntegrationTests.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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")); + } }