Add more username tests

These test validate, that no username validation will be performed,
if the form has an error.
This commit is contained in:
Denis Natusch 2024-01-15 01:20:42 +01:00
parent 073600a92c
commit de900d2eeb
No known key found for this signature in database
GPG key ID: 5E57BD8EDACFA985

View file

@ -61,6 +61,8 @@ class UserControllerIntegrationTests {
createTestUser("eva"); createTestUser("eva");
createTestUser("sarah"); createTestUser("sarah");
createTestUser("paul"); createTestUser("paul");
createTestUser("maria");
createTestUser("adam");
} }
@Test @Test
@ -401,4 +403,45 @@ class UserControllerIntegrationTests {
.andExpect(redirectedUrl("/")); .andExpect(redirectedUrl("/"));
} }
@Test
@WithMockUser(username = "maria", password = "123")
void alreadyExistingNameCheckWillNotBePerformedIfFormHasErrorProfile() throws Exception {
assertTrue(userManagement.getUserByName("maria").isPresent());
MockHttpServletRequestBuilder createMessage = post("/profile")
.param("username", "admin")
.param("password", "\0")
.param("address", "Baum Straße");
assertThat(mvc.perform(createMessage).andReturn().getResponse().getContentAsString())
.contains("Ungültiges Passwort")
.contains("Ungültiger Name")
.doesNotContain("Ungültiger Nutzername");
}
@Test
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
void alreadyExistingNameCheckWillNotBePerformedIfFormHasErrorCustomer() throws Exception {
assertThat(userManagement.getUsers().findAll())
.extracting("username", "fullName", "address")
.contains(tuple("adam", "Adam Klaus", "Baum Weg"));
assertThat(mvc.perform(post("/customers/edit/" + userManagement.getUserByName("adam").get().getId())
.param("username", "adam")
.param("address", "Baum Straße"))
.andReturn().getResponse().getContentAsString())
.contains("Ungültiger Name")
.doesNotContain("Ungültiger Nutzername");
}
@Test
@WithAnonymousUser
void alreadyExistingNameCheckWillNotBePerformedIfFormHasErrorRegistration() throws Exception {
MockHttpServletRequestBuilder createCustomer = post("/register")
.param("username", "admin")
.param("password", "\0")
.param("fullName", "Tom Klaus")
.param("address", "Baum Weg");
assertThat(mvc.perform(createCustomer).andReturn().getResponse().getContentAsString())
.contains("Ungültiges Passwort")
.doesNotContain("Ungültiger Nutzername");
}
} }