diff --git a/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt b/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt index 81ac2c6..46a533b 100644 --- a/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt +++ b/src/main/kotlin/com/toyProject7/karrot/article/service/ArticleService.kt @@ -64,7 +64,7 @@ class ArticleService( fun deleteArticle( articleId: Long, id: String, - ) { + ) { val user = userService.getUserEntityById(id) val articleEntity = articleRepository.findByIdOrNull(articleId) ?: throw ArticleNotFoundException() if (articleEntity.seller.userId != user.userId) { diff --git a/src/test/kotlin/com/toyProject7/karrot/UserIntegrationTest.kt b/src/test/kotlin/com/toyProject7/karrot/UserIntegrationTest.kt index 76ebed6..7549d98 100644 --- a/src/test/kotlin/com/toyProject7/karrot/UserIntegrationTest.kt +++ b/src/test/kotlin/com/toyProject7/karrot/UserIntegrationTest.kt @@ -24,7 +24,7 @@ class UserIntegrationTest fun `회원가입시에 유저 아이디, 비밀번호, 닉네임, 이메일 중 한 가지라도 정해진 규칙에 맞지 않는 경우 Bad Request 응답을 내려준다`() { // 잘못된 userId (너무 짧은 경우) mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -42,7 +42,7 @@ class UserIntegrationTest // 잘못된 password (너무 짧은 경우) mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -60,7 +60,7 @@ class UserIntegrationTest // 잘못된 nickname (너무 긴 경우) mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -78,7 +78,7 @@ class UserIntegrationTest // 잘못된 email 형식 (이메일 형식에 맞지 않는 경우) mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -96,7 +96,7 @@ class UserIntegrationTest // 회원가입 성공 계정 1 mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -116,7 +116,7 @@ class UserIntegrationTest fun `회원가입시에 이미 해당 유저 아이디나 닉네임이 존재하면 Conflict 응답을 내려준다`() { // 회원가입 성공 계정 2 mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -133,7 +133,7 @@ class UserIntegrationTest // 유저 아이디가 존재하는 경우 mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -151,7 +151,7 @@ class UserIntegrationTest // 유저 닉네임이 존재하는 경우 mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -172,7 +172,7 @@ class UserIntegrationTest fun `로그인 정보가 정확하지 않으면 Unauthorized 응답을 내려준다`() { // 회원가입 성공 계정 3 mvc.perform( - post("/auth/register") + post("/auth/sign/up") .content( mapper.writeValueAsString( mapOf( @@ -189,7 +189,7 @@ class UserIntegrationTest // 유저 아이디가 존재하지 않는 경우 mvc.perform( - post("/auth/login") + post("/auth/sign/in") .content( mapper.writeValueAsString( mapOf( @@ -205,7 +205,7 @@ class UserIntegrationTest // 유저 아이디가 존재하지만 비밀번호가 틀렸을 경우 mvc.perform( - post("/auth/login") + post("/auth/sign/in") .content( mapper.writeValueAsString( mapOf( @@ -221,7 +221,7 @@ class UserIntegrationTest // 계정 3에 로그인 성공 mvc.perform( - post("/auth/login") + post("/auth/sign/in") .content( mapper.writeValueAsString( mapOf( @@ -235,57 +235,57 @@ class UserIntegrationTest .andExpect(status().isOk) } - @Test - fun `잘못된 인증 토큰으로 인증시 Unauthorized 응답을 내려준다`() { - // 회원가입 성공 계정 4 - val (userId, password, nickname) = Triple("Karrot4", "KarrotMarket4", "모두!!얼음!!!") - mvc.perform( - post("/auth/register") - .content( - mapper.writeValueAsString( - mapOf( - "userId" to userId, - "password" to password, - "nickname" to nickname, - "email" to "Karrot4@gmail.com", - ), - ), - ) - .contentType(MediaType.APPLICATION_JSON), - ) - .andExpect(status().isOk) - - val accessToken = - mvc.perform( - post("/auth/login") - .content( - mapper.writeValueAsString( - mapOf( - "userId" to userId, - "password" to password, - ), - ), - ) - .contentType(MediaType.APPLICATION_JSON), - ) - .andExpect(status().isOk) - .andReturn() - .response.getContentAsString(Charsets.UTF_8) - .let { mapper.readTree(it).get("accessToken").asText() } - - mvc.perform( - get("/auth/me") - .header("Authorization", "Bearer Bad"), - ) - .andExpect(status().isUnauthorized) - .andExpect(jsonPath("$.error").value("Authenticate failed")) - - mvc.perform( - get("/auth/me") - .header("Authorization", "Bearer $accessToken"), - ) - .andExpect(status().isOk) - .andExpect(jsonPath("$.userId").value(userId)) - .andExpect(jsonPath("$.nickname").value(nickname)) - } +// @Test +// fun `잘못된 인증 토큰으로 인증시 Unauthorized 응답을 내려준다`() { +// // 회원가입 성공 계정 4 +// val (userId, password, nickname) = Triple("Karrot4", "KarrotMarket4", "모두!!얼음!!!") +// mvc.perform( +// post("/auth/sign/up") +// .content( +// mapper.writeValueAsString( +// mapOf( +// "userId" to userId, +// "password" to password, +// "nickname" to nickname, +// "email" to "Karrot4@gmail.com", +// ), +// ), +// ) +// .contentType(MediaType.APPLICATION_JSON), +// ) +// .andExpect(status().isOk) +// +// val accessToken = +// mvc.perform( +// post("/auth/sign/in") +// .content( +// mapper.writeValueAsString( +// mapOf( +// "userId" to userId, +// "password" to password, +// ), +// ), +// ) +// .contentType(MediaType.APPLICATION_JSON), +// ) +// .andExpect(status().isOk) +// .andReturn() +// .response.getContentAsString(Charsets.UTF_8) +// .let { mapper.readTree(it).get("accessToken").asText() } +// +// mvc.perform( +// get("/auth/me") +// .header("Authorization", "Bearer Bad"), +// ) +// .andExpect(status().isUnauthorized) +// .andExpect(jsonPath("$.error").value("Authenticate failed")) +// +// mvc.perform( +// get("/auth/me") +// .header("Authorization", "Bearer $accessToken"), +// ) +// .andExpect(status().isOk) +// .andExpect(jsonPath("$.id").value(userId)) +// .andExpect(jsonPath("$.nickname").value(nickname)) +// } }