From cd20d2cb0b5802738d33e688f3e23b0db9fa2d09 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 19:45:06 +0900 Subject: [PATCH 01/13] =?UTF-8?q?[#94]=20MemesIntegrationTest=20=EB=B0=88?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memes/MemesIntegrationTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java new file mode 100644 index 0000000..2224805 --- /dev/null +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java @@ -0,0 +1,58 @@ +package com.example.memetory.domain.memes; + +import static com.example.memetory.domain.meme.MemeFixture.*; +import static io.restassured.RestAssured.*; +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; + +import com.example.memetory.domain.meme.entity.Meme; +import com.example.memetory.domain.meme.repository.MemeRepository; +import com.example.memetory.domain.memes.dto.request.GenerateMemesRequest; +import com.example.memetory.domain.memes.dto.response.MemesResponse; +import com.example.memetory.domain.memes.repository.MemesRepository; +import com.example.memetory.global.integration.BaseIntegrationTest; + +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; + +@DisplayName("Memes 통합 테스트의 ") +public class MemesIntegrationTest extends BaseIntegrationTest { + @Autowired + private MemeRepository memeRepository; + @Autowired + private MemesRepository memesRepository; + + @Test + @DisplayName("GenerateMemesRequest을 통한 Memes 생성 성공") + public void Given_GenerateMemesRequest_When_registerMemes_Then_MemesResponse() { + // given + Meme meme = memeRepository.save(MEME(member)); + + final String title = "new Memes"; + GenerateMemesRequest request = new GenerateMemesRequest(meme.getId(), title); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .body(request) + .when() + .post("/memes") + .then() + .log() + .all() + .extract(); + + MemesResponse result = response.jsonPath().getObject("data", MemesResponse.class); + + // then + assertThat(result.getTitle()).isEqualTo(title); + } +} From 855e9417d3db7378f03da9d819c4e46c1faa4db0 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 19:48:23 +0900 Subject: [PATCH 02/13] =?UTF-8?q?[#94]=20MemesIntegrationTest=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20memeId?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EC=97=90=EB=9F=AC=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memes/MemesIntegrationTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java index 2224805..c5aa63d 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java @@ -1,6 +1,7 @@ package com.example.memetory.domain.memes; import static com.example.memetory.domain.meme.MemeFixture.*; +import static com.example.memetory.global.response.ErrorCode.*; import static io.restassured.RestAssured.*; import static org.assertj.core.api.Assertions.*; @@ -55,4 +56,32 @@ public void Given_GenerateMemesRequest_When_registerMemes_Then_MemesResponse() { // then assertThat(result.getTitle()).isEqualTo(title); } + + @Test + @DisplayName("존재하지 않는 MemeId로 인한 MEME_NOT_FOUND 반환") + public void Given_NotExistedMemeId_When_findMemberMemePageResponse_Throw_NotFoundMemberMemeException() { + // given + final String title = "new Memes"; + GenerateMemesRequest request = new GenerateMemesRequest(-1L, title); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .body(request) + .when() + .post("/memes") + .then() + .log() + .all() + .extract(); + + String result = response.jsonPath().get(ERROR_MESSAGE); + + // then + assertThat(result).isEqualTo(MEME_NOT_FOUND.getMessage()); + } } From 88471ef888569b608eb50119b2e1b462f6202a72 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 19:59:16 +0900 Subject: [PATCH 03/13] =?UTF-8?q?[#94]=20MemesIntegrationTest=20memesId?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EB=B0=88=EC=8A=A4=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memes/MemesIntegrationTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java index c5aa63d..d3377a1 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java @@ -1,7 +1,9 @@ package com.example.memetory.domain.memes; import static com.example.memetory.domain.meme.MemeFixture.*; +import static com.example.memetory.domain.memes.MemesFixture.*; import static com.example.memetory.global.response.ErrorCode.*; +import static com.example.memetory.global.response.ResultCode.*; import static io.restassured.RestAssured.*; import static org.assertj.core.api.Assertions.*; @@ -14,6 +16,7 @@ import com.example.memetory.domain.meme.repository.MemeRepository; import com.example.memetory.domain.memes.dto.request.GenerateMemesRequest; import com.example.memetory.domain.memes.dto.response.MemesResponse; +import com.example.memetory.domain.memes.entity.Memes; import com.example.memetory.domain.memes.repository.MemesRepository; import com.example.memetory.global.integration.BaseIntegrationTest; @@ -84,4 +87,30 @@ public void Given_NotExistedMemeId_When_findMemberMemePageResponse_Throw_NotFoun // then assertThat(result).isEqualTo(MEME_NOT_FOUND.getMessage()); } + + @Test + @DisplayName("memesId를 통한 밈스 삭제 성공") + public void Given_memesId_When_deleteMemes_Then_DELETE_MEMES_SUCCESS() throws Exception { + // given + Meme meme = memeRepository.save(MEME(member)); + Memes memes = memesRepository.save(MEMES(member, meme)); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .delete("/memes/{memesId}", memes.getId()) + .then() + .log() + .all() + .extract(); + + String result = response.jsonPath().get(MESSAGE); + + // then + assertThat(result).isEqualTo(DELETE_MEMES_SUCCESS.getMessage()); + } } From 6d2777995fd8abae14f4a76b2e1f72e27103503b Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 20:03:01 +0900 Subject: [PATCH 04/13] =?UTF-8?q?[#94]=20MemesIntegrationTest=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=97=86=EB=8A=94=20=EB=A9=A4=EB=B2=84=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20deleteMemes=EC=8B=9C=20MEMES=5FACCESS=5FDE?= =?UTF-8?q?NY=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memes/MemesIntegrationTest.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java index d3377a1..74d31d9 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java @@ -1,5 +1,6 @@ package com.example.memetory.domain.memes; +import static com.example.memetory.domain.member.MemberFixture.*; import static com.example.memetory.domain.meme.MemeFixture.*; import static com.example.memetory.domain.memes.MemesFixture.*; import static com.example.memetory.global.response.ErrorCode.*; @@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; +import com.example.memetory.domain.member.entity.Member; import com.example.memetory.domain.meme.entity.Meme; import com.example.memetory.domain.meme.repository.MemeRepository; import com.example.memetory.domain.memes.dto.request.GenerateMemesRequest; @@ -90,7 +92,7 @@ public void Given_NotExistedMemeId_When_findMemberMemePageResponse_Throw_NotFoun @Test @DisplayName("memesId를 통한 밈스 삭제 성공") - public void Given_memesId_When_deleteMemes_Then_DELETE_MEMES_SUCCESS() throws Exception { + public void Given_memesId_When_deleteMemes_Then_DELETE_MEMES_SUCCESS() { // given Meme meme = memeRepository.save(MEME(member)); Memes memes = memesRepository.save(MEMES(member, meme)); @@ -113,4 +115,31 @@ public void Given_memesId_When_deleteMemes_Then_DELETE_MEMES_SUCCESS() throws Ex // then assertThat(result).isEqualTo(DELETE_MEMES_SUCCESS.getMessage()); } + + @DisplayName("권한 없는 멤버로 인한 MEMES_ACCESS_DENY 반환") + @Test + public void Given_unAuthorizedMember_When_deleteMemes_Then_MEMES_ACCESS_DENY() { + // given + Member unAuthorizationMember = memberRepository.save(OTHER_MEMBER()); + Meme meme = memeRepository.save(MEME(unAuthorizationMember)); + Memes memes = memesRepository.save(MEMES(unAuthorizationMember, meme)); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .delete("/memes/{memesId}", memes.getId()) + .then() + .log() + .all() + .extract(); + + String result = response.jsonPath().get(ERROR_MESSAGE); + + // then + assertThat(result).isEqualTo(MEMES_ACCESS_DENY.getMessage()); + } } From 1d6656782fdc43c04631edc0dfd4aac28e63489c Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 20:16:06 +0900 Subject: [PATCH 05/13] =?UTF-8?q?[#94]=20MemesIntegrationTest=20memesId?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EB=B0=88=EC=8A=A4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memes/MemesIntegrationTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java index 74d31d9..738f39d 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java @@ -142,4 +142,30 @@ public void Given_unAuthorizedMember_When_deleteMemes_Then_MEMES_ACCESS_DENY() { // then assertThat(result).isEqualTo(MEMES_ACCESS_DENY.getMessage()); } + + @Test + @DisplayName("memesId를 통한 MemesResponse 반환 성공") + public void Given_memesId_When_findMemesResponse_Thee_MemeResponse() { + Meme meme = memeRepository.save(MEME(member)); + Memes memes = memesRepository.save(MEMES(member, meme)); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .get("/memes/{memesId}", memes.getId()) + .then() + .log() + .all() + .extract(); + + MemesResponse result = response.jsonPath().getObject("data", MemesResponse.class); + + // then + assertThat(result.getMemesId()).isEqualTo(memes.getId()); + } + } From 53de94b9dab9cbd442a24cbc54ad33790cddf783 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 20:28:23 +0900 Subject: [PATCH 06/13] =?UTF-8?q?[#94]=20MemesIntegrationTest=20pageable?= =?UTF-8?q?=EC=9D=84=20=ED=86=B5=ED=95=9C=20MemesInfoSliceResponse=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memes/MemesIntegrationTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java index 738f39d..6f40120 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesIntegrationTest.java @@ -7,6 +7,7 @@ import static com.example.memetory.global.response.ResultCode.*; import static io.restassured.RestAssured.*; import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -17,6 +18,7 @@ import com.example.memetory.domain.meme.entity.Meme; import com.example.memetory.domain.meme.repository.MemeRepository; import com.example.memetory.domain.memes.dto.request.GenerateMemesRequest; +import com.example.memetory.domain.memes.dto.response.MemesInfoSliceResponse; import com.example.memetory.domain.memes.dto.response.MemesResponse; import com.example.memetory.domain.memes.entity.Memes; import com.example.memetory.domain.memes.repository.MemesRepository; @@ -168,4 +170,33 @@ public void Given_memesId_When_findMemesResponse_Thee_MemeResponse() { assertThat(result.getMemesId()).isEqualTo(memes.getId()); } + @Test + @DisplayName("Pageable을 통한 MemesInfoSliceResponse 반환 성공") + public void Given_Pageable_When_findMemesInfoSliceResponse_Then_MemesInfoPageResponse() throws Exception { + final int SIZE = 10; + Meme meme = memeRepository.save(MEME(member)); + + for (int i = 0; i < SIZE + 1; i++) { + memesRepository.save(MEMES(member, meme)); + } + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .get("/memes?page={page}&size={size}", 0, SIZE) + .then() + .log() + .all() + .extract(); + + MemesInfoSliceResponse result = response.jsonPath().getObject("data", MemesInfoSliceResponse.class); + + // then + assertTrue(result.isHasNext()); + assertThat(result.getMemesInfoResponseList()).hasSize(SIZE); + } } From 3267cb2b3f39fa2106fae480c4435a93b93786ce Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 20:43:37 +0900 Subject: [PATCH 07/13] =?UTF-8?q?[#94]=20MemesLikeIntegrationTest=20memesI?= =?UTF-8?q?d=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=EB=93=B1=EB=A1=9D=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memes/controller/MemesLikeController.java | 17 ++++++ .../memes/MemesLikeIntegrationTest.java | 54 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java create mode 100644 backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java new file mode 100644 index 0000000..52de11c --- /dev/null +++ b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java @@ -0,0 +1,17 @@ +package com.example.memetory.domain.memes.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.example.memetory.domain.like.service.LikeService; +import com.example.memetory.domain.memes.service.MemesService; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/memes/like") +public class MemesLikeController { + private final MemesService memesService; + private final LikeService likeService; +} diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java new file mode 100644 index 0000000..03b70d3 --- /dev/null +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java @@ -0,0 +1,54 @@ +package com.example.memetory.domain.memes; + +import static com.example.memetory.domain.meme.MemeFixture.*; +import static com.example.memetory.domain.memes.MemesFixture.*; +import static com.example.memetory.global.response.ResultCode.*; +import static io.restassured.RestAssured.*; +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import com.example.memetory.domain.meme.entity.Meme; +import com.example.memetory.domain.meme.repository.MemeRepository; +import com.example.memetory.domain.memes.entity.Memes; +import com.example.memetory.domain.memes.repository.MemesRepository; +import com.example.memetory.global.integration.BaseIntegrationTest; + +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; + +public class MemesLikeIntegrationTest extends BaseIntegrationTest { + @Autowired + MemeRepository memeRepository; + @Autowired + MemesRepository memesRepository; + + @Test + @DisplayName("memesId를 통한 좋아요 등록 성공") + void Given_memesId_When_registerLike_Then_CREATE_LIKE_SUCCESS() { + Meme meme = memeRepository.save(MEME(member)); + Memes memes = memesRepository.save(MEMES(member, meme)); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .post("/memes/{memesId}/like", memes.getId()) + .then() + .log() + .all() + .extract(); + + String result = response.jsonPath().get(MESSAGE); + + // then + assertThat(result).isEqualTo(CREATE_LIKE_SUCCESS.getMessage()); + memesRepository.findByMemesId(memes.getId()) + .ifPresent(m -> assertThat(m.getLikeCount()).isEqualTo(2L)); + } +} From f368a063dddce65f934c0cd95c2d451cd4cefddb Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 20:47:09 +0900 Subject: [PATCH 08/13] =?UTF-8?q?[#94]=20MemesLikeIntegrationTest=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=20=EB=93=B1=EB=A1=9D=EB=90=9C=20=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20LIKE=5FNOT?= =?UTF-8?q?=5FCREATE=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memes/MemesLikeIntegrationTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java index 03b70d3..77a9f99 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java @@ -1,15 +1,27 @@ package com.example.memetory.domain.memes; +import static com.example.memetory.domain.like.LikeFixture.*; import static com.example.memetory.domain.meme.MemeFixture.*; import static com.example.memetory.domain.memes.MemesFixture.*; +import static com.example.memetory.global.response.ErrorCode.*; import static com.example.memetory.global.response.ResultCode.*; import static io.restassured.RestAssured.*; import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; +import com.example.memetory.domain.like.dto.LikeServiceDto; +import com.example.memetory.domain.like.exception.NotCreateLikeException; +import com.example.memetory.domain.like.repository.LikeRepository; import com.example.memetory.domain.meme.entity.Meme; import com.example.memetory.domain.meme.repository.MemeRepository; import com.example.memetory.domain.memes.entity.Memes; @@ -24,6 +36,8 @@ public class MemesLikeIntegrationTest extends BaseIntegrationTest { MemeRepository memeRepository; @Autowired MemesRepository memesRepository; + @Autowired + LikeRepository likeRepository; @Test @DisplayName("memesId를 통한 좋아요 등록 성공") @@ -51,4 +65,31 @@ void Given_memesId_When_registerLike_Then_CREATE_LIKE_SUCCESS() { memesRepository.findByMemesId(memes.getId()) .ifPresent(m -> assertThat(m.getLikeCount()).isEqualTo(2L)); } + + @Test + @DisplayName("DB에 존재하는 좋아요로 인한 LIKE_NOT_CREATE 반환") + void Given_ExistLike_When_registerLike_Then_LIKE_NOT_CREATE() throws Exception { + // given + Meme meme = memeRepository.save(MEME(member)); + Memes memes = memesRepository.save(MEMES(member, meme)); + likeRepository.save(LIKE(member, memes)); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .post("/memes/{memesId}/like", memes.getId()) + .then() + .log() + .all() + .extract(); + + String result = response.jsonPath().get(ERROR_MESSAGE); + + // then + assertThat(result).isEqualTo(LIKE_NOT_CREATE.getMessage()); + } } From 7e3e4348a85a7069f9fd7d42a6dc0a2955df1aa3 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 20:51:53 +0900 Subject: [PATCH 09/13] =?UTF-8?q?[#94]=20MemesLikeIntegrationTest=20memesI?= =?UTF-8?q?d=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memes/MemesLikeIntegrationTest.java | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java index 77a9f99..fa44fc9 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java @@ -7,20 +7,13 @@ import static com.example.memetory.global.response.ResultCode.*; import static io.restassured.RestAssured.*; import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; -import com.example.memetory.domain.like.dto.LikeServiceDto; -import com.example.memetory.domain.like.exception.NotCreateLikeException; +import com.example.memetory.domain.like.entity.Like; import com.example.memetory.domain.like.repository.LikeRepository; import com.example.memetory.domain.meme.entity.Meme; import com.example.memetory.domain.meme.repository.MemeRepository; @@ -39,12 +32,21 @@ public class MemesLikeIntegrationTest extends BaseIntegrationTest { @Autowired LikeRepository likeRepository; + private Meme meme; + private Memes memes; + + @Override + @BeforeEach + public void setUp() { + super.setUp(); + + meme = memeRepository.save(MEME(member)); + memes = memesRepository.save(MEMES(member, meme)); + } + @Test @DisplayName("memesId를 통한 좋아요 등록 성공") void Given_memesId_When_registerLike_Then_CREATE_LIKE_SUCCESS() { - Meme meme = memeRepository.save(MEME(member)); - Memes memes = memesRepository.save(MEMES(member, meme)); - // when ExtractableResponse response = given() @@ -70,8 +72,6 @@ void Given_memesId_When_registerLike_Then_CREATE_LIKE_SUCCESS() { @DisplayName("DB에 존재하는 좋아요로 인한 LIKE_NOT_CREATE 반환") void Given_ExistLike_When_registerLike_Then_LIKE_NOT_CREATE() throws Exception { // given - Meme meme = memeRepository.save(MEME(member)); - Memes memes = memesRepository.save(MEMES(member, meme)); likeRepository.save(LIKE(member, memes)); // when @@ -92,4 +92,29 @@ void Given_ExistLike_When_registerLike_Then_LIKE_NOT_CREATE() throws Exception { // then assertThat(result).isEqualTo(LIKE_NOT_CREATE.getMessage()); } + + @Test + @DisplayName("memesId를 통한 좋아요 삭제 성공") + void Given_memesId_When_cancelLike_Then_DELETE_LIKE_SUCCESS() { + // given + Like like = likeRepository.save(LIKE(member, memes)); + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .delete("/memes/{memesId}/like", memes.getId()) + .then() + .log() + .all() + .extract(); + + String result = response.jsonPath().get(MESSAGE); + + // then + assertThat(result).isEqualTo(DELETE_LIKE_SUCCESS.getMessage()); + } } From d553e577bd0877a912ef8ae6be63ab63ca3bcc34 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 21:14:29 +0900 Subject: [PATCH 10/13] =?UTF-8?q?[#94]=20MemesLikeIntegrationTest=20?= =?UTF-8?q?=EC=98=AC=ED=83=80=EC=9E=84=20=EC=A2=8B=EC=95=84=EC=9A=94=20Top?= =?UTF-8?q?10=20=EB=B0=88=EC=8A=A4=20=EB=B0=98=ED=99=98=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memes/MemesLikeIntegrationTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java index fa44fc9..a37895f 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java @@ -7,16 +7,24 @@ import static com.example.memetory.global.response.ResultCode.*; import static io.restassured.RestAssured.*; import static org.assertj.core.api.Assertions.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; import com.example.memetory.domain.like.entity.Like; import com.example.memetory.domain.like.repository.LikeRepository; import com.example.memetory.domain.meme.entity.Meme; import com.example.memetory.domain.meme.repository.MemeRepository; +import com.example.memetory.domain.memes.dto.response.MemesInfoResponse; import com.example.memetory.domain.memes.entity.Memes; import com.example.memetory.domain.memes.repository.MemesRepository; import com.example.memetory.global.integration.BaseIntegrationTest; @@ -117,4 +125,56 @@ void Given_memesId_When_cancelLike_Then_DELETE_LIKE_SUCCESS() { // then assertThat(result).isEqualTo(DELETE_LIKE_SUCCESS.getMessage()); } + + @Test + @DisplayName("DB에 없는 좋아요로 인한 LIKE_NOT_FOUND 반환") + void Given_NotExistLike_When_cancelLike_Then_LIKE_NOT_FOUND() { + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .delete("/memes/{memesId}/like", memes.getId()) + .then() + .log() + .all() + .extract(); + + String result = response.jsonPath().get(ERROR_MESSAGE); + + // then + assertThat(result).isEqualTo(LIKE_NOT_FOUND.getMessage()); + } + + @Test + @DisplayName("올타임 좋아요 Top 10 밈스 반환 성공") + public void When_findTopMemesByLike_Then_GET_TOP_TEN_MEMES_SUCCESS() { + // given + final Long SIZE = 15L; + + for (long i = 0; i < SIZE; i++) { + memesRepository.save(MEMES_SET_LIKE(member, meme, i)); + } + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .get("/memes/like/all") + .then() + .log() + .all() + .extract(); + + List responses = response.jsonPath().getList("data", MemesInfoResponse.class); + + // then + assertThat(responses).hasSize(10); + assertThat(responses.get(0).getLikeCount()).isEqualTo(SIZE - 1); + } } From 93bc75533d3b84701027b78e02e2e2bc4c525aa0 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 21:49:24 +0900 Subject: [PATCH 11/13] =?UTF-8?q?[#94]=20MemesLikeIntegrationTest=20?= =?UTF-8?q?=EC=A3=BC=EA=B0=84=20=EC=A2=8B=EC=95=84=EC=9A=94=20Top10=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20=EA=B5=AC=ED=98=84=20:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../memes/MemesLikeIntegrationTest.java | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java index a37895f..7b9dd32 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java @@ -7,18 +7,16 @@ import static com.example.memetory.global.response.ResultCode.*; import static io.restassured.RestAssured.*; import static org.assertj.core.api.Assertions.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import java.time.LocalDate; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.ZSetOperations; import com.example.memetory.domain.like.entity.Like; import com.example.memetory.domain.like.repository.LikeRepository; @@ -40,6 +38,11 @@ public class MemesLikeIntegrationTest extends BaseIntegrationTest { @Autowired LikeRepository likeRepository; + @Autowired + private ZSetOperations rankingZSet; + @Autowired + private RedisConnectionFactory redisConnectionFactory; + private Meme meme; private Memes memes; @@ -47,6 +50,7 @@ public class MemesLikeIntegrationTest extends BaseIntegrationTest { @BeforeEach public void setUp() { super.setUp(); + redisConnectionFactory.getConnection().flushAll(); meme = memeRepository.save(MEME(member)); memes = memesRepository.save(MEMES(member, meme)); @@ -177,4 +181,38 @@ public void When_findTopMemesByLike_Then_GET_TOP_TEN_MEMES_SUCCESS() { assertThat(responses).hasSize(10); assertThat(responses.get(0).getLikeCount()).isEqualTo(SIZE - 1); } + + @Test + @DisplayName("주간 좋아요 Top 10 밈스 반환 성공") + public void When_findTopMemesByLikeForWeek_Then_GET_WEEK_TOP_TEN_MEMES_SUCCESS() { + // given + final Long SIZE = 15L; + String dateKey = "LIKE_RANKING_DATE::" + LocalDate.now().minusDays(1); + + for (Long i = 0L; i < SIZE; i++) { + // 총 좋아요 수와 오늘 좋아요 수의 차이를 주기 위해 + 3 + Memes rankMemes = memesRepository.save(MEMES_SET_LIKE(member, meme, i + 3)); + + rankingZSet.add(dateKey, rankMemes.getId(), i); + } + + // when + ExtractableResponse response = + given() + .log() + .all() + .auth().oauth2(accessToken) + .when() + .get("/memes/like/week") + .then() + .log() + .all() + .extract(); + + List responses = response.jsonPath().getList("data", MemesInfoResponse.class); + + // then + assertThat(responses).hasSize(10); + assertThat(responses.get(0).getLikeCount()).isEqualTo(SIZE - 1); + } } From 49ff1a91fa76bcc2bf7206faf22ba8c6cb9d6a21 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 22:01:18 +0900 Subject: [PATCH 12/13] =?UTF-8?q?[#94]=20MemesController=EC=9D=98=20?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=20=EA=B4=80=EB=A0=A8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B6=84=EB=A6=AC=ED=95=98=EC=97=AC=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=EC=9D=84=20=EB=82=AE=EC=B6=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/memes/controller/MemesApi.java | 73 ---------------- .../memes/controller/MemesController.java | 45 ---------- .../domain/memes/controller/MemesLikeApi.java | 87 +++++++++++++++++++ .../memes/controller/MemesLikeController.java | 57 +++++++++++- .../memes/MemesLikeIntegrationTest.java | 1 + 5 files changed, 143 insertions(+), 120 deletions(-) create mode 100644 backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeApi.java diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesApi.java b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesApi.java index deb8e5e..32a8118 100644 --- a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesApi.java +++ b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesApi.java @@ -33,45 +33,6 @@ ResponseEntity registerMemes( GenerateMemesRequest generateMemesRequest ); - @Operation( - summary = "meme`s 인기차트 조회", - description = "좋아요 수 많은 순으로 10개 조회", - security = {@SecurityRequirement(name = "access_token")} - ) - @ApiResponses(value = { - @ApiResponse( - responseCode = "200", - description = "인기차트 조회" - ) - }) - ResponseEntity findTopMemesByLike(); - - @Operation( - summary = "meme`s 이달의 인기차트 조회", - description = "최근 한 달 동안 좋아요 수 많은 순으로 10개 조회", - security = {@SecurityRequirement(name = "access_token")} - ) - @ApiResponses(value = { - @ApiResponse( - responseCode = "200", - description = "이달의 인기차트 조회" - ) - }) - ResponseEntity findTopMemesByLikeForMonth(); - - @Operation( - summary = "meme`s 이주의 인기차트 조회", - description = "최근 한 주 동안 좋아요 수 많은 순으로 10개 조회", - security = {@SecurityRequirement(name = "access_token")} - ) - @ApiResponses(value = { - @ApiResponse( - responseCode = "200", - description = "이주의 인기차트 조회" - ) - }) - ResponseEntity findTopMemesByLikeForWeek(); - @Operation( summary = "meme`s 삭제", description = "meme`s 삭제", @@ -115,38 +76,4 @@ ResponseEntity findMemesResponse( ) }) ResponseEntity findMemesInfoSliceResponse(Pageable pageable); - - @Operation( - summary = "meme`s 좋아요 등록", - description = "공유된 meme`s 게시물에 좋아요를 등록한다.", - security = {@SecurityRequirement(name = "access_token")} - ) - @ApiResponses(value = { - @ApiResponse( - responseCode = "201", - description = "좋아요 등록!" - ) - }) - ResponseEntity registerLike( - @Parameter(hidden = true) String email, - @Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true) - Long memesId - ); - - @Operation( - summary = "meme`s 좋아요 취소", - description = "공유된 meme`s 게시물에 등록된 좋아요를 취소한다.", - security = {@SecurityRequirement(name = "access_token")} - ) - @ApiResponses(value = { - @ApiResponse( - responseCode = "200", - description = "좋아요 취소!" - ) - }) - ResponseEntity cancelLike( - @Parameter(hidden = true) String email, - @Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true) - Long memesId - ); } diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesController.java b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesController.java index 8110eac..0e0b245 100644 --- a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesController.java +++ b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesController.java @@ -2,8 +2,6 @@ import static com.example.memetory.global.response.ResultCode.*; -import java.util.List; - import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -15,11 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.example.memetory.domain.like.dto.LikeServiceDto; -import com.example.memetory.domain.like.service.LikeService; import com.example.memetory.domain.memes.dto.MemesServiceDto; import com.example.memetory.domain.memes.dto.request.GenerateMemesRequest; -import com.example.memetory.domain.memes.dto.response.MemesInfoResponse; import com.example.memetory.domain.memes.dto.response.MemesInfoSliceResponse; import com.example.memetory.domain.memes.dto.response.MemesResponse; import com.example.memetory.domain.memes.service.MemesService; @@ -33,7 +28,6 @@ @RequestMapping("/memes") public class MemesController implements MemesApi { private final MemesService memesService; - private final LikeService likeService; @GetMapping @Override @@ -68,43 +62,4 @@ public ResponseEntity deleteMemes(@LoginMemberEmail String email memesService.deleteMemes(memesServiceDto); return ResponseEntity.ok(ResultResponse.of(DELETE_MEMES_SUCCESS)); } - - @GetMapping("/like/all") - @Override - public ResponseEntity findTopMemesByLike() { - List response = memesService.findTopMemesByLike(); - return ResponseEntity.ok(ResultResponse.of(GET_TOP_TEN_MEMES_SUCCESS, response)); - } - - @GetMapping("/like/month") - @Override - public ResponseEntity findTopMemesByLikeForMonth() { - List response = memesService.findTopMemesByLikeForMonth(); - return ResponseEntity.ok(ResultResponse.of(GET_MONTH_TOP_TEN_MEMES_SUCCESS, response)); - } - - @GetMapping("/like/week") - @Override - public ResponseEntity findTopMemesByLikeForWeek() { - List response = memesService.findTopMemesByLikeForWeek(); - return ResponseEntity.ok(ResultResponse.of(GET_WEEK_TOP_TEN_MEMES_SUCCESS, response)); - } - - @PostMapping("/{memesId}/like") - @Override - public ResponseEntity registerLike(@LoginMemberEmail String email, @PathVariable Long memesId) { - LikeServiceDto likeServiceDto = LikeServiceDto.fromEmailAndMemesId(email, memesId); - likeService.registerLike(likeServiceDto); - - return ResponseEntity.status(HttpStatus.CREATED).body(ResultResponse.of(CREATE_LIKE_SUCCESS)); - } - - @DeleteMapping("/{memesId}/like") - @Override - public ResponseEntity cancelLike(@LoginMemberEmail String email, @PathVariable Long memesId) { - LikeServiceDto likeServiceDto = LikeServiceDto.fromEmailAndMemesId(email, memesId); - likeService.cancelLike(likeServiceDto); - - return ResponseEntity.ok(ResultResponse.of(DELETE_LIKE_SUCCESS)); - } } diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeApi.java b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeApi.java new file mode 100644 index 0000000..cf15945 --- /dev/null +++ b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeApi.java @@ -0,0 +1,87 @@ +package com.example.memetory.domain.memes.controller; + +import org.springframework.http.ResponseEntity; + +import com.example.memetory.global.response.ResultResponse; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; + +public interface MemesLikeApi { + @Operation( + summary = "meme`s 인기차트 조회", + description = "좋아요 수 많은 순으로 10개 조회", + security = {@SecurityRequirement(name = "access_token")} + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "인기차트 조회" + ) + }) + ResponseEntity findTopMemesByLike(); + + @Operation( + summary = "meme`s 이달의 인기차트 조회", + description = "최근 한 달 동안 좋아요 수 많은 순으로 10개 조회", + security = {@SecurityRequirement(name = "access_token")} + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "이달의 인기차트 조회" + ) + }) + ResponseEntity findTopMemesByLikeForMonth(); + + @Operation( + summary = "meme`s 이주의 인기차트 조회", + description = "최근 한 주 동안 좋아요 수 많은 순으로 10개 조회", + security = {@SecurityRequirement(name = "access_token")} + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "이주의 인기차트 조회" + ) + }) + ResponseEntity findTopMemesByLikeForWeek(); + + @Operation( + summary = "meme`s 좋아요 등록", + description = "공유된 meme`s 게시물에 좋아요를 등록한다.", + security = {@SecurityRequirement(name = "access_token")} + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "201", + description = "좋아요 등록!" + ) + }) + ResponseEntity registerLike( + @Parameter(hidden = true) String email, + @Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true) + Long memesId + ); + + @Operation( + summary = "meme`s 좋아요 취소", + description = "공유된 meme`s 게시물에 등록된 좋아요를 취소한다.", + security = {@SecurityRequirement(name = "access_token")} + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", + description = "좋아요 취소!" + ) + }) + ResponseEntity cancelLike( + @Parameter(hidden = true) String email, + @Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true) + Long memesId + ); +} diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java index 52de11c..0ba8222 100644 --- a/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java +++ b/backend/memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesLikeController.java @@ -1,17 +1,70 @@ package com.example.memetory.domain.memes.controller; +import static com.example.memetory.global.response.ResultCode.*; + +import java.util.List; + +import org.springframework.http.HttpStatus; +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.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.example.memetory.domain.like.dto.LikeServiceDto; import com.example.memetory.domain.like.service.LikeService; +import com.example.memetory.domain.memes.dto.response.MemesInfoResponse; import com.example.memetory.domain.memes.service.MemesService; +import com.example.memetory.global.annotation.LoginMemberEmail; +import com.example.memetory.global.response.ResultResponse; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor -@RequestMapping("/memes/like") -public class MemesLikeController { +@RequestMapping("/memes") +public class MemesLikeController implements MemesLikeApi { private final MemesService memesService; private final LikeService likeService; + + @GetMapping("/like/all") + @Override + public ResponseEntity findTopMemesByLike() { + List response = memesService.findTopMemesByLike(); + return ResponseEntity.ok(ResultResponse.of(GET_TOP_TEN_MEMES_SUCCESS, response)); + } + + @GetMapping("/like/month") + @Override + public ResponseEntity findTopMemesByLikeForMonth() { + List response = memesService.findTopMemesByLikeForMonth(); + return ResponseEntity.ok(ResultResponse.of(GET_MONTH_TOP_TEN_MEMES_SUCCESS, response)); + } + + @GetMapping("/like/week") + @Override + public ResponseEntity findTopMemesByLikeForWeek() { + List response = memesService.findTopMemesByLikeForWeek(); + return ResponseEntity.ok(ResultResponse.of(GET_WEEK_TOP_TEN_MEMES_SUCCESS, response)); + } + + @PostMapping("/{memesId}/like") + @Override + public ResponseEntity registerLike(@LoginMemberEmail String email, @PathVariable Long memesId) { + LikeServiceDto likeServiceDto = LikeServiceDto.fromEmailAndMemesId(email, memesId); + likeService.registerLike(likeServiceDto); + + return ResponseEntity.status(HttpStatus.CREATED).body(ResultResponse.of(CREATE_LIKE_SUCCESS)); + } + + @DeleteMapping("/{memesId}/like") + @Override + public ResponseEntity cancelLike(@LoginMemberEmail String email, @PathVariable Long memesId) { + LikeServiceDto likeServiceDto = LikeServiceDto.fromEmailAndMemesId(email, memesId); + likeService.cancelLike(likeServiceDto); + + return ResponseEntity.ok(ResultResponse.of(DELETE_LIKE_SUCCESS)); + } } diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java index 7b9dd32..bb93efb 100644 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java +++ b/backend/memetory/src/test/java/com/example/memetory/domain/memes/MemesLikeIntegrationTest.java @@ -30,6 +30,7 @@ import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +@DisplayName("MemesLike 통합 테스트의 ") public class MemesLikeIntegrationTest extends BaseIntegrationTest { @Autowired MemeRepository memeRepository; From 69249295f6f3795845ac874355a7c6c1ca1b5d48 Mon Sep 17 00:00:00 2001 From: JunRain Date: Thu, 13 Jun 2024 22:02:18 +0900 Subject: [PATCH 13/13] =?UTF-8?q?[#94]=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84=EC=9C=BC=EB=A1=9C=20Con?= =?UTF-8?q?troller=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberControllerTest.java | 94 ------- .../meme/controller/MemeControllerTest.java | 119 --------- .../memes/controller/MemesControllerTest.java | 246 ------------------ 3 files changed, 459 deletions(-) delete mode 100644 backend/memetory/src/test/java/com/example/memetory/domain/member/controller/MemberControllerTest.java delete mode 100644 backend/memetory/src/test/java/com/example/memetory/domain/meme/controller/MemeControllerTest.java delete mode 100644 backend/memetory/src/test/java/com/example/memetory/domain/memes/controller/MemesControllerTest.java diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/member/controller/MemberControllerTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/member/controller/MemberControllerTest.java deleted file mode 100644 index 1d05d35..0000000 --- a/backend/memetory/src/test/java/com/example/memetory/domain/member/controller/MemberControllerTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.example.memetory.domain.member.controller; - -import static com.example.memetory.domain.member.MemberFixture.*; -import static com.example.memetory.global.response.ErrorCode.*; -import static com.example.memetory.global.response.ResultCode.*; -import static org.mockito.BDDMockito.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; - -import com.example.memetory.domain.member.dto.MemberServiceDto; -import com.example.memetory.domain.member.dto.request.MemberUpdateRequest; -import com.example.memetory.domain.member.dto.response.MemberResponse; -import com.example.memetory.domain.member.exception.DuplicatedMemberException; -import com.example.memetory.domain.member.service.MemberService; -import com.example.memetory.global.BaseControllerTest; - -@DisplayName("Member 컨트롤러 테스트의 ") -@WebMvcTest(MemberController.class) -public class MemberControllerTest extends BaseControllerTest { - @MockBean - private MemberService memberService; - - @Test - @DisplayName("MemberUpdateRequest를 통한 멤버 업데이트 성공") - public void Given_MemberUpdateRequest_When_updateMember_Then_UPDATRE_MEMBER_SUCCESS() throws Exception { - // given - MemberUpdateRequest request = new MemberUpdateRequest("junrain2", "imageUrl2"); - MemberResponse expectedResult = MemberResponse.of(MEMBER()); - String expectedNickname = expectedResult.getNickName(); - - given(memberService.updateMember(any())).willReturn(expectedResult); - - // when - final ResultActions perform = mockMvc.perform(post("/member") - .contentType(MediaType.APPLICATION_JSON) - .content(toRequestBody(request)) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE).value(UPDATE_MEMBER_SUCCESS.getMessage())) - .andExpect(jsonPath("$.data.nickName").value(expectedNickname)); - } - - @Test - @DisplayName("중복된 닉네임으로 인한 NICKNAME_IS_DUPLICATED 반환") - public void Given_MemberUpdateRequest_When_updateMember_Then_NICKNAME_IS_DUPLICATED() throws Exception { - // given - MemberUpdateRequest request = new MemberUpdateRequest("junrain2", "imageUrl2"); - - doThrow(new DuplicatedMemberException()).when(memberService).updateMember(any()); - - // when - final ResultActions perform = mockMvc.perform(post("/member") - .contentType(MediaType.APPLICATION_JSON) - .content(toRequestBody(request)) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - perform.andExpect(status().isConflict()) - .andExpect(jsonPath(ERROR_MESSAGE).value(NICKNAME_IS_DUPLICATED.getMessage())); - } - - @Test - @DisplayName("email을 통한 MemberResponse 반환 성공") - public void Given_email_When_findMember_Then_MemberResponse() throws Exception { - // given - MemberResponse expectedResult = MemberResponse.of(MEMBER()); - String expectedNickname = expectedResult.getNickName(); - - given(memberService.findMemberResponse(any(MemberServiceDto.class))).willReturn(expectedResult); - - // when - final ResultActions perform = mockMvc.perform(get("/member") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE).value(GET_MEMBER_SUCCESS.getMessage())) - .andExpect(jsonPath("$.data.nickName").value(expectedNickname)); - } -} diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/meme/controller/MemeControllerTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/meme/controller/MemeControllerTest.java deleted file mode 100644 index 36b7411..0000000 --- a/backend/memetory/src/test/java/com/example/memetory/domain/meme/controller/MemeControllerTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.example.memetory.domain.meme.controller; - -import static com.example.memetory.domain.meme.MemeFixture.*; -import static com.example.memetory.global.response.ErrorCode.*; -import static com.example.memetory.global.response.ResultCode.*; -import static org.mockito.BDDMockito.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; - -import com.example.memetory.domain.meme.dto.MemePageResponse; -import com.example.memetory.domain.meme.dto.MemeResponse; -import com.example.memetory.domain.meme.dto.MemeServiceDto; -import com.example.memetory.domain.meme.exception.AccessDeniedMemeException; -import com.example.memetory.domain.meme.exception.NotFoundMemeException; -import com.example.memetory.domain.meme.service.MemeService; -import com.example.memetory.global.BaseControllerTest; - -@DisplayName("Meme 컨트롤러 테스트의 ") -@WebMvcTest(MemeController.class) -public class MemeControllerTest extends BaseControllerTest { - @MockBean - private MemeService memeService; - - /** - *Todo - * register와 callback은 외부 API를 활용하는 메서드이기 떄문에 테스트 법 공부가 필요 - */ - - @Test - @DisplayName("이메일과 밈id를 통한 멤버의 MemeResponse 반환 성공") - void Given_emailAndMemeId_When_findMemberMemeResponse_Then_Member_MemeResponse() throws Exception { - // given - MemeResponse returnedMemeResponse = MemeResponse.of(MEME(loginMember)); - given(memeService.findMemberMemeResponse(any())).willReturn(returnedMemeResponse); - - // when - final ResultActions perform = mockMvc.perform( - get("/meme/-1") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE, GET_ONE_MEME_SUCCESS.getMessage()).exists()) - .andExpect(jsonPath("$.data.s3Url").exists()); - } - - @Test - @DisplayName("권한 없는 멤버 이메일로 인한 AccessDeniedMemeException 반환") - void Given_NotPermissionMemberId_When_findMemberMemeResponse_Throw_AccessDeniedMemberMemeException() throws Exception { - // given - given(memeService.findMemberMemeResponse(any(MemeServiceDto.class))).willThrow(new AccessDeniedMemeException()); - - // when - final ResultActions perform = mockMvc.perform( - get("/meme/-1") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - perform.andExpect(status().isForbidden()) - .andExpect(jsonPath(ERROR_MESSAGE, MEME_ACCESS_DENY.getMessage()).exists()); - } - - @Test - @DisplayName("존재하지 않는 memeId로 인한 NotFoundMemeException 반환") - void Given_NotExistMemeId_Then_findMemberMemeResponse_Throw_NotFoundMemberMemeException() throws Exception { - // given - Long notExistMemeId = -1L; - - given(memeService.findMemberMemeResponse(any(MemeServiceDto.class))).willThrow(new NotFoundMemeException()); - - // when - final ResultActions perform = mockMvc.perform( - get("/meme/" + notExistMemeId) - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - perform.andExpect(status().isNotFound()) - .andExpect(jsonPath(ERROR_MESSAGE, MEME_NOT_FOUND.getMessage()).exists()); - } - - @Test - @DisplayName("이메일과 Pageable을 통한 멤버의 MemePageResponse 반환 성공") - void Given_emailAndPageable_When_findMemberMemePageResponse_Then_Member_MemePageResponse() throws Exception { - // given - List memeList = List.of(MEME(loginMember), OTHER_MEME(loginMember)) - .stream() - .map(MemeResponse::of) - .toList(); - MemePageResponse memePageResponse = MemePageResponse.builder().memeList(memeList).build(); - - given(memeService.findMemberMemePageResponse(any(), any())).willReturn(memePageResponse); - - // when - final ResultActions perform = mockMvc.perform( - get("/meme?page=0&size=10").contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)).andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE).value(GET_MEMBER_MEME_SUCCESS.getMessage())) - .andExpect(jsonPath("$.data.memeList").isArray()); - } -} diff --git a/backend/memetory/src/test/java/com/example/memetory/domain/memes/controller/MemesControllerTest.java b/backend/memetory/src/test/java/com/example/memetory/domain/memes/controller/MemesControllerTest.java deleted file mode 100644 index bca2c48..0000000 --- a/backend/memetory/src/test/java/com/example/memetory/domain/memes/controller/MemesControllerTest.java +++ /dev/null @@ -1,246 +0,0 @@ -package com.example.memetory.domain.memes.controller; - -import static com.example.memetory.domain.meme.MemeFixture.*; -import static com.example.memetory.domain.memes.MemesFixture.*; -import static com.example.memetory.global.response.ErrorCode.*; -import static com.example.memetory.global.response.ResultCode.*; -import static org.mockito.BDDMockito.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import java.util.List; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; - -import com.example.memetory.domain.like.dto.LikeServiceDto; -import com.example.memetory.domain.like.exception.NotCreateLikeException; -import com.example.memetory.domain.like.exception.NotFoundLikeException; -import com.example.memetory.domain.like.service.LikeService; -import com.example.memetory.domain.meme.entity.Meme; -import com.example.memetory.domain.memes.dto.MemesServiceDto; -import com.example.memetory.domain.memes.dto.request.GenerateMemesRequest; -import com.example.memetory.domain.memes.dto.response.MemesInfoResponse; -import com.example.memetory.domain.memes.dto.response.MemesInfoSliceResponse; -import com.example.memetory.domain.memes.dto.response.MemesResponse; -import com.example.memetory.domain.memes.exception.AccessDinedMemesException; -import com.example.memetory.domain.memes.service.MemesService; -import com.example.memetory.global.BaseControllerTest; - -@DisplayName("Memes 컨트롤러 테스트의 ") -@WebMvcTest(MemesController.class) -public class MemesControllerTest extends BaseControllerTest { - @MockBean - private MemesService memesService; - @MockBean - private LikeService likeService; - - @Test - @DisplayName("GenerateMemesRequest을 통한 Memes 생성 성공") - public void Given_GenerateMemesRequest_When_registerMemes_Then_MemesResponse() throws Exception { - // given - final String title = "new Memes"; - - Meme meme = MEME(loginMember); - - GenerateMemesRequest request = new GenerateMemesRequest(meme.getId(), title); - MemesResponse response = MemesResponse.of(MEMES(loginMember, meme)); - - given(memesService.registerMemes(any(MemesServiceDto.class))).willReturn(response); - - // when - final ResultActions perform = mockMvc.perform( - post("/memes") - .contentType(MediaType.APPLICATION_JSON) - .content(toRequestBody(request)) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - // then - perform.andExpect(status().isCreated()) - .andExpect(jsonPath(MESSAGE).value(CREATE_MEMES_SUCCESS.getMessage())) - .andExpect(jsonPath("$.data.title").value(title)); - } - - @Test - @DisplayName("memesId를 통한 밈스 삭제 성공") - public void Given_memesId_When_deleteMemes_Then_DELETE_MEMES_SUCCESS() throws Exception { - // when - final ResultActions perform = mockMvc.perform( - delete("/memes/-1") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE).value(DELETE_MEMES_SUCCESS.getMessage())); - } - - @Test - @DisplayName("권한 없는 멤버로 인한 MEMES_ACCESS_DENY 반환") - public void Given_unAuthorizedMember_When_deleteMemes_Then_MEMES_ACCESS_DENY() throws Exception { - // given - doThrow(new AccessDinedMemesException()).when(memesService).deleteMemes(any()); - - // when - final ResultActions perform = mockMvc.perform( - delete("/memes/-1") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - // then - perform.andExpect(status().isForbidden()) - .andExpect(jsonPath(ERROR_MESSAGE).value(MEMES_ACCESS_DENY.getMessage())); - } - - @Test - @DisplayName("올타임 좋아요 Top 10 밈스 반환 성공") - public void When_findTopMemesByLike_Then_GET_TOP_TEN_MEMES_SUCCESS() throws Exception { - // when - final ResultActions perform = mockMvc.perform( - get("/memes/like/all") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE).value(GET_TOP_TEN_MEMES_SUCCESS.getMessage())); - } - - @Test - @DisplayName("주간 좋아요 Top 10 밈스 반환 성공") - public void When_findTopMemesByLikeForWeek_Then_GET_WEEK_TOP_TEN_MEMES_SUCCESS() throws Exception { - // when - final ResultActions perform = mockMvc.perform( - get("/memes/like/week") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE).value(GET_WEEK_TOP_TEN_MEMES_SUCCESS.getMessage())); - } - - @Test - @DisplayName("밈스 id를 통한 MemesResponse 반환 성공") - public void Given_memesId_When_findMemesResponse_Thee_MemeResponse() throws Exception { - Meme meme = MEME(loginMember); - MemesResponse response = MemesResponse.of(MEMES(loginMember, meme)); - given(memesService.findMemesResponse(any())).willReturn(response); - - // when - final ResultActions perform = mockMvc.perform( - get("/memes/-1") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - // then - perform.andExpect(status().isOk()) - .andExpectAll( - jsonPath(MESSAGE).value(GET_ONE_MEMES_SUCCESS.getMessage()), - jsonPath("$.data.likeCount").value("1")); - } - - @Test - @DisplayName("Pageable을 통한 MemesInfoSliceResponse 반환 성공") - public void Given_Pageable_When_findMemesInfoSliceResponse_Then_MemesInfoPageResponse() throws Exception { - final String page = "page=0&size=10"; - Meme meme = MEME(loginMember); - - MemesInfoSliceResponse response = MemesInfoSliceResponse.builder() - .memesInfoResponseList(List.of(MemesInfoResponse.of(MEMES(loginMember, meme)))) - .currentPage(0) - .hasNext(false) - .build(); - given(memesService.findMemesInfoSliceResponse(any())).willReturn(response); - - String expectedTitle = response.getMemesInfoResponseList().get(0).getTitle(); - - // when - final ResultActions perform = mockMvc.perform( - get("/memes?" + page) - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken) - ).andDo(print()); - - // then - perform.andExpect(status().isOk()).andExpectAll( - jsonPath(MESSAGE).value(GET_ALL_MEMES_SUCCESS.getMessage()), - jsonPath("$.data.memesInfoResponseList[0].title").value(expectedTitle)); - } - - @Test - @DisplayName("memesId를 통한 좋아요 등록 성공") - void Given_memesId_When_registerLike_Then_CREATE_LIKE_SUCCESS() throws Exception { - // when - final ResultActions perform = mockMvc.perform(post("/memes/-1/like") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - verify(likeService).registerLike(any(LikeServiceDto.class)); - perform.andExpect(status().isCreated()) - .andExpect(jsonPath(MESSAGE).value(CREATE_LIKE_SUCCESS.getMessage())); - } - - @Test - @DisplayName("DB에 존재하는 좋아요로 인한 LIKE_NOT_CREATE 반환") - void Given_ExistLike_When_registerLike_Then_LIKE_NOT_CREATE() throws Exception { - // given - doThrow(new NotCreateLikeException()).when(likeService).registerLike(any(LikeServiceDto.class)); - - // when - final ResultActions perform = mockMvc.perform(post("/memes/-1/like") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - verify(likeService).registerLike(any(LikeServiceDto.class)); - perform.andExpect(status().isConflict()) - .andExpect(jsonPath(ERROR_MESSAGE).value(LIKE_NOT_CREATE.getMessage())); - } - - @Test - @DisplayName("memesId를 통한 좋아요 삭제 성공") - void Given_memesId_When_cancelLike_Then_DELETE_LIKE_SUCCESS() throws Exception { - // when - final ResultActions perform = mockMvc.perform(delete("/memes/-1/like") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - verify(likeService).cancelLike(any(LikeServiceDto.class)); - perform.andExpect(status().isOk()) - .andExpect(jsonPath(MESSAGE).value(DELETE_LIKE_SUCCESS.getMessage())); - } - - @Test - @DisplayName("DB에 없는 좋아요로 인한 LIKE_NOT_FOUND 반환") - void Given_NotExistLike_When_cancelLike_Then_LIKE_NOT_FOUND() throws Exception { - // given - doThrow(new NotFoundLikeException()).when(likeService).cancelLike(any(LikeServiceDto.class)); - - // when - final ResultActions perform = mockMvc.perform(delete("/memes/-1/like") - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken)) - .andDo(print()); - - // then - perform.andExpect(status().isNotFound()) - .andExpect(jsonPath(ERROR_MESSAGE).value(LIKE_NOT_FOUND.getMessage())); - } -}