From c624e2ad49f8532812e3798fee7884cc6a7281f4 Mon Sep 17 00:00:00 2001 From: Village_Water Date: Thu, 7 Nov 2024 09:29:09 +0900 Subject: [PATCH] fix: user test --- src/test/java/com/kert/UserTest.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/kert/UserTest.java b/src/test/java/com/kert/UserTest.java index 30d6edb..4b899af 100644 --- a/src/test/java/com/kert/UserTest.java +++ b/src/test/java/com/kert/UserTest.java @@ -248,8 +248,18 @@ public void deleteUserByIdWithAdmin() throws Exception { } @Test - @DisplayName("delete user with not_admin") - public void deleteUserByIdWithNotAdmin() throws Exception { - mockMvc.perform(delete("/users/", testUser.getStudentId()).header("Authorization", "Bearer " + userJwtToken)).andExpect(status().isForbidden()); + @DisplayName("delete user with self") + public void deleteUserByIdWithSelf() throws Exception { + when(userService.getUserById(testUser.getStudentId())).thenReturn(testUser); + + mockMvc.perform(delete("/users/{studentId}", testUser.getStudentId()).header("Authorization", "Bearer " + userJwtToken)).andExpect(status().isNoContent()); + } + + @Test + @DisplayName("delete user with another") + public void deleteUserByIdWithAnother() throws Exception { + when(userService.getUserById(2L)).thenReturn(new User()); + + mockMvc.perform(delete("/users/2", testUser.getStudentId()).header("Authorization", "Bearer " + userJwtToken)).andExpect(status().isForbidden()); } }