fix: delete request (#532)
* fix: corrects delete endpoint to follow HTTP DELETE standard (#509) * fix: corrects delete endpoint to follow HTTP DELETE standard * fix: refactor for consistent formatting * feat: improve account deletion to use delete method * test: fix account tests --------- Co-authored-by: Patrick Bpds <patrickbpds@gmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Patrick Bpds
parent
3d8b00baa4
commit
aee76e9aee
@@ -87,7 +87,7 @@ describe('Account Component', () => {
|
||||
fireEvent.click(confirmButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(api.postJSON).toHaveBeenCalledWith(ApiConfig.deleteAccountUrl, {});
|
||||
expect(api.deleteNoContent).toHaveBeenCalledWith(ApiConfig.deleteAccountUrl);
|
||||
expect(authContextMock.signOut).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ function Account(): React.ReactNode {
|
||||
*/
|
||||
const deleteAccount = async (): Promise<void> => {
|
||||
setShowAlert(false);
|
||||
await api.postJSON(ApiConfig.deleteAccountUrl, {});
|
||||
await api.deleteNoContent(ApiConfig.deleteAccountUrl);
|
||||
signOut();
|
||||
clearStorage();
|
||||
};
|
||||
|
||||
+6
-4
@@ -11,8 +11,9 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class UserSessionController {
|
||||
*
|
||||
* @returns {@link UserResponse} with the user information.
|
||||
*/
|
||||
@PostMapping("/delete-account")
|
||||
@DeleteMapping("/delete-account")
|
||||
@Operation(
|
||||
summary = "Delete the user account.",
|
||||
description = "Delete all the user data and information from the server.",
|
||||
@@ -63,7 +64,8 @@ public class UserSessionController {
|
||||
description = "Unauthorized. Access Denied",
|
||||
content = @Content(schema = @Schema(implementation = Void.class)))
|
||||
})
|
||||
public UserResponse deleteAccount() {
|
||||
return userSessionService.deleteCurrentUserAccount();
|
||||
public ResponseEntity<UserResponse> deleteAccount() {
|
||||
UserResponse deleted = userSessionService.deleteCurrentUserAccount();
|
||||
return ResponseEntity.ok(deleted);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@ package br.com.tasknoteapp.server.controller;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@@ -68,7 +68,7 @@ class UserSessionControllerTest {
|
||||
|
||||
mockMvc
|
||||
.perform(
|
||||
post("/rest/user-sessions/delete-account")
|
||||
delete("/rest/user-sessions/delete-account")
|
||||
.with(csrf().asHeader())
|
||||
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
@@ -81,7 +81,7 @@ class UserSessionControllerTest {
|
||||
void deleteAccount_unauthorized_shouldFail() throws Exception {
|
||||
mockMvc
|
||||
.perform(
|
||||
post("/rest/user-sessions/delete-account")
|
||||
delete("/rest/user-sessions/delete-account")
|
||||
.with(csrf().asHeader())
|
||||
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
Reference in New Issue
Block a user