diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserController.java b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserController.java index 5acba3e..bc71d83 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserController.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserController.java @@ -30,7 +30,16 @@ public EnableUserController(EnableUserService service) { @PostMapping(path = "/users/{id}/enable") @Operation( summary = "Enables a user by ID", - description = "This endpoint serves the purpose of enabling a previously disabled user within the system, with the user's unique identifier specified in the endpoint path. Proper authentication, through an authentication token, is required for secure access. Upon a successful request, the server responds with an HTTP status code of 200, indicating that the user has been successfully enabled. This endpoint provides a crucial mechanism for restoring user access or lifting restrictions, supporting effective user management. In situations where the enabling process encounters errors, the server responds with an appropriate error status code, accompanied by a descriptive error message to assist clients in diagnosing and resolving the issue.", + description = """ + This endpoint serves the purpose of enabling a previously disabled user within the system, with the user's unique identifier specified in the endpoint path. + + Proper authentication, through an authentication token, is required for secure access. + + Upon a successful request, the server responds with an HTTP status code of 200, indicating that the user has been successfully enabled. + + This endpoint provides a crucial mechanism for restoring user access or lifting restrictions, supporting effective user management. + + In situations where the enabling process encounters errors, the server responds with an appropriate error status code, accompanied by a descriptive error message to assist clients in diagnosing and resolving the issue.""", tags = ApiTag.USERS, operationId = "disableUser" ) diff --git a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserControllerTest.java b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserControllerTest.java index 344e4fc..93b4cf0 100644 --- a/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserControllerTest.java +++ b/src/test/java/org/lucoenergia/conluz/infrastructure/admin/user/enable/EnableUserControllerTest.java @@ -10,10 +10,15 @@ import org.lucoenergia.conluz.infrastructure.shared.BaseControllerTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; +import java.util.UUID; + import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Transactional @@ -41,4 +46,37 @@ void testEnableUser() throws Exception { .andExpect(status().isOk()); Assertions.assertTrue(getUserRepository.findByPersonalId(UserPersonalId.of(user.getPersonalId())).get().isEnabled()); } + + @Test + void testWithUnknownUser() throws Exception { + + String authHeader = loginAsDefaultAdmin(); + + final String userId = UUID.randomUUID().toString(); + + mockMvc.perform(post("/api/v1/users/" + userId + "/enable") + .header(HttpHeaders.AUTHORIZATION, authHeader) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.timestamp").isNotEmpty()) + .andExpect(jsonPath("$.status").value(HttpStatus.BAD_REQUEST.value())) + .andExpect(jsonPath("$.message").isNotEmpty()) + .andExpect(jsonPath("$.traceId").isNotEmpty()); + } + + @Test + void testWithoutToken() throws Exception { + + final String userId = UUID.randomUUID().toString(); + + mockMvc.perform(post("/api/v1/users/" + userId + "/enable") + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.timestamp").isNotEmpty()) + .andExpect(jsonPath("$.status").value(HttpStatus.UNAUTHORIZED.value())) + .andExpect(jsonPath("$.message").isNotEmpty()) + .andExpect(jsonPath("$.traceId").isNotEmpty()); + } }