From f4f03206fd495d76f18f983bfc0c0dfb0435dc57 Mon Sep 17 00:00:00 2001 From: sung-silver Date: Fri, 3 Jan 2025 14:54:38 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[TEST]=20Banner=20API=20=EB=B0=B0=EB=84=88?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../banner/api/BannerApiControllerTest.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java index c58d10a7..b90987b7 100644 --- a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java +++ b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java @@ -1,5 +1,6 @@ package org.sopt.makers.operation.web.banner.api; +import com.fasterxml.jackson.databind.*; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -8,10 +9,11 @@ import org.sopt.makers.operation.filter.JwtAuthenticationFilter; import org.sopt.makers.operation.filter.JwtExceptionFilter; import org.sopt.makers.operation.jwt.JwtTokenProvider; +import org.sopt.makers.operation.web.banner.dto.request.BannerRequest.*; import org.sopt.makers.operation.web.banner.dto.response.BannerResponse; +import org.sopt.makers.operation.web.banner.dto.response.BannerResponse.*; import org.sopt.makers.operation.web.banner.service.BannerService; -import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.ComponentScan; @@ -29,6 +31,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON; 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; @@ -45,6 +48,8 @@ class BannerApiControllerTest { private BannerService bannerService; @Autowired private MockMvc mockMvc; + @Autowired + ObjectMapper objectMapper; @BeforeEach void setMockBanner() { @@ -121,4 +126,35 @@ void getExternalBanners() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.success").value("true")); } + + @Test + @DisplayName("(POST) New Banner") + void createNewBanner() throws Exception { + // given + BannerCreate bannerCreate = new BannerCreate("pg_community", "product", "publisher", + LocalDate.of(2024, 1, 1), LocalDate.of(2024, 12, 31), "link", "image-url-pc", "image-url-mobile" + ); + String request = objectMapper.writeValueAsString(bannerCreate); + BannerDetail givenBannerDetail = bannerService.getBannerDetail(MOCK_BANNER_ID); + when(bannerService.createBanner(bannerCreate)) + .thenReturn(givenBannerDetail); + + // when & then + this.mockMvc.perform(post("/api/v1/banners") + .contentType(APPLICATION_JSON) + .content(request)) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.success").value("true")) + .andExpect(jsonPath("$.message").value(BannerSuccessCode.SUCCESS_CREATE_BANNER.getMessage())) + .andExpect(jsonPath("$.data.id").value(givenBannerDetail.bannerId())) + .andExpect(jsonPath("$.data.status").value(givenBannerDetail.bannerStatus())) + .andExpect(jsonPath("$.data.location").value(givenBannerDetail.bannerLocation())) + .andExpect(jsonPath("$.data.content_type").value(givenBannerDetail.bannerType())) + .andExpect(jsonPath("$.data.publisher").value(givenBannerDetail.publisher())) + .andExpect(jsonPath("$.data.link").value(givenBannerDetail.link())) + .andExpect(jsonPath("$.data.start_date").value(givenBannerDetail.startDate().toString())) + .andExpect(jsonPath("$.data.end_date").value(givenBannerDetail.endDate().toString())) + .andExpect(jsonPath("$.data.image_url_pc").value(givenBannerDetail.pcImageUrl())) + .andExpect(jsonPath("$.data.image_url_mobile").value(givenBannerDetail.mobileImageUrl())); + } } From 2d91cea799924e18a7b1e4291b115a2e6a4ea46c Mon Sep 17 00:00:00 2001 From: sung-silver Date: Fri, 3 Jan 2025 14:58:34 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[TEST]=20test=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/web/banner/api/BannerApiControllerTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java index b90987b7..fdaf97b3 100644 --- a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java +++ b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java @@ -139,10 +139,12 @@ void createNewBanner() throws Exception { when(bannerService.createBanner(bannerCreate)) .thenReturn(givenBannerDetail); - // when & then - this.mockMvc.perform(post("/api/v1/banners") + this.mockMvc.perform( + // when + post("/api/v1/banners") .contentType(APPLICATION_JSON) .content(request)) + // then .andExpect(status().isCreated()) .andExpect(jsonPath("$.success").value("true")) .andExpect(jsonPath("$.message").value(BannerSuccessCode.SUCCESS_CREATE_BANNER.getMessage())) From b604002313eb98e0f71581bdf9668fd7e2fa5ee9 Mon Sep 17 00:00:00 2001 From: sung-silver Date: Fri, 3 Jan 2025 17:35:19 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[CHORE]=20=EC=82=AC=EC=9A=A9=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/makers/operation/web/banner/service/BannerService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/operation-api/src/main/java/org/sopt/makers/operation/web/banner/service/BannerService.java b/operation-api/src/main/java/org/sopt/makers/operation/web/banner/service/BannerService.java index 7c14ae53..a30548ed 100644 --- a/operation-api/src/main/java/org/sopt/makers/operation/web/banner/service/BannerService.java +++ b/operation-api/src/main/java/org/sopt/makers/operation/web/banner/service/BannerService.java @@ -4,7 +4,6 @@ import org.sopt.makers.operation.web.banner.dto.request.*; import org.sopt.makers.operation.web.banner.dto.response.BannerResponse; -import org.sopt.makers.operation.web.banner.dto.response.BannerResponse.BannerDetail; import org.sopt.makers.operation.web.banner.dto.response.BannerResponse.BannerImageUrl; public interface BannerService { From e4a6f09cffdd3cefc2a99b53273446b406c8d22e Mon Sep 17 00:00:00 2001 From: sung-silver Date: Mon, 6 Jan 2025 14:50:56 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[TEST]=20=EC=BD=94=EB=93=9C=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../banner/api/BannerApiControllerTest.java | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java index fdaf97b3..b73d8fd7 100644 --- a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java +++ b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java @@ -1,9 +1,7 @@ package org.sopt.makers.operation.web.banner.api; import com.fasterxml.jackson.databind.*; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.*; import org.sopt.makers.operation.code.success.web.BannerSuccessCode; import org.sopt.makers.operation.filter.JwtAuthenticationFilter; @@ -11,7 +9,6 @@ import org.sopt.makers.operation.jwt.JwtTokenProvider; import org.sopt.makers.operation.web.banner.dto.request.BannerRequest.*; import org.sopt.makers.operation.web.banner.dto.response.BannerResponse; -import org.sopt.makers.operation.web.banner.dto.response.BannerResponse.*; import org.sopt.makers.operation.web.banner.service.BannerService; import org.springframework.test.web.servlet.MockMvc; @@ -25,6 +22,8 @@ import java.security.Principal; import java.time.LocalDate; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -94,6 +93,7 @@ void getBannerDetail() throws Exception { @DisplayName("(DELETE) Banner Delete") void deleteBanner() throws Exception { //given + bannerService.deleteBanner(MOCK_BANNER_ID); BannerResponse.BannerDetail mockBannerDetail = bannerService.getBannerDetail(MOCK_BANNER_ID); this.mockMvc.perform( @@ -105,7 +105,6 @@ void deleteBanner() throws Exception { //then .andExpect(status().isNoContent()) .andExpect(jsonPath("$.success").value("true")); - } @Test @@ -127,36 +126,38 @@ void getExternalBanners() throws Exception { .andExpect(jsonPath("$.success").value("true")); } - @Test - @DisplayName("(POST) New Banner") - void createNewBanner() throws Exception { - // given - BannerCreate bannerCreate = new BannerCreate("pg_community", "product", "publisher", - LocalDate.of(2024, 1, 1), LocalDate.of(2024, 12, 31), "link", "image-url-pc", "image-url-mobile" - ); - String request = objectMapper.writeValueAsString(bannerCreate); - BannerDetail givenBannerDetail = bannerService.getBannerDetail(MOCK_BANNER_ID); - when(bannerService.createBanner(bannerCreate)) - .thenReturn(givenBannerDetail); - - this.mockMvc.perform( - // when - post("/api/v1/banners") - .contentType(APPLICATION_JSON) - .content(request)) - // then - .andExpect(status().isCreated()) - .andExpect(jsonPath("$.success").value("true")) - .andExpect(jsonPath("$.message").value(BannerSuccessCode.SUCCESS_CREATE_BANNER.getMessage())) - .andExpect(jsonPath("$.data.id").value(givenBannerDetail.bannerId())) - .andExpect(jsonPath("$.data.status").value(givenBannerDetail.bannerStatus())) - .andExpect(jsonPath("$.data.location").value(givenBannerDetail.bannerLocation())) - .andExpect(jsonPath("$.data.content_type").value(givenBannerDetail.bannerType())) - .andExpect(jsonPath("$.data.publisher").value(givenBannerDetail.publisher())) - .andExpect(jsonPath("$.data.link").value(givenBannerDetail.link())) - .andExpect(jsonPath("$.data.start_date").value(givenBannerDetail.startDate().toString())) - .andExpect(jsonPath("$.data.end_date").value(givenBannerDetail.endDate().toString())) - .andExpect(jsonPath("$.data.image_url_pc").value(givenBannerDetail.pcImageUrl())) - .andExpect(jsonPath("$.data.image_url_mobile").value(givenBannerDetail.mobileImageUrl())); + @Nested + class CreateBannerTests { + @Test + @DisplayName("(POST) New Banner") + void createNewBanner() throws Exception { + // given + BannerCreate bannerCreate = new BannerCreate("pg_community", "product", "publisher", + LocalDate.of(2024, 1, 1), LocalDate.of(2024, 12, 31), "link", "image-url-pc", "image-url-mobile"); + BannerResponse.BannerDetail mockBannerDetail = new BannerResponse.BannerDetail( + MOCK_BANNER_ID, "in_progress", "pg_community", "product", "publisher", "link", + LocalDate.of(2024, 1, 1), LocalDate.of(2024, 12, 31), "image-url-pc", "image-url-mobile"); + String request = objectMapper.writeValueAsString(bannerCreate); + when(bannerService.createBanner(any(BannerCreate.class))).thenReturn(mockBannerDetail); + + // when + mockMvc.perform(post("/api/v1/banners") + .contentType(APPLICATION_JSON) + .content(request)) + // then + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.success").value(true)) + .andExpect(jsonPath("$.message").value(BannerSuccessCode.SUCCESS_CREATE_BANNER.getMessage())) + .andExpect(jsonPath("$.data.id").value(mockBannerDetail.bannerId())) + .andExpect(jsonPath("$.data.status").value(mockBannerDetail.bannerStatus())) + .andExpect(jsonPath("$.data.location").value(mockBannerDetail.bannerLocation())) + .andExpect(jsonPath("$.data.content_type").value(mockBannerDetail.bannerType())) + .andExpect(jsonPath("$.data.publisher").value(mockBannerDetail.publisher())) + .andExpect(jsonPath("$.data.link").value(mockBannerDetail.link())) + .andExpect(jsonPath("$.data.start_date").value(mockBannerDetail.startDate().toString())) + .andExpect(jsonPath("$.data.end_date").value(mockBannerDetail.endDate().toString())) + .andExpect(jsonPath("$.data.image_url_pc").value(mockBannerDetail.pcImageUrl())) + .andExpect(jsonPath("$.data.image_url_mobile").value(mockBannerDetail.mobileImageUrl())); + } } } From 00dfdded7ca30827918131d9d12ea94569caefab Mon Sep 17 00:00:00 2001 From: sung-silver Date: Mon, 6 Jan 2025 15:45:58 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[TEST]=20=EB=B0=B0=EB=84=88=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EC=97=90=20=EB=8C=80=ED=95=9C=20given=20=EC=A0=88=20?= =?UTF-8?q?=EC=A0=81=EC=A0=88=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/web/banner/api/BannerApiControllerTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java index b73d8fd7..1790714f 100644 --- a/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java +++ b/operation-api/src/test/java/org/sopt/makers/operation/web/banner/api/BannerApiControllerTest.java @@ -93,8 +93,7 @@ void getBannerDetail() throws Exception { @DisplayName("(DELETE) Banner Delete") void deleteBanner() throws Exception { //given - bannerService.deleteBanner(MOCK_BANNER_ID); - BannerResponse.BannerDetail mockBannerDetail = bannerService.getBannerDetail(MOCK_BANNER_ID); + doNothing().when(bannerService).deleteBanner(MOCK_BANNER_ID); this.mockMvc.perform( //when