From 833872eb17af57a9d1ea38f577067e5e4f397863 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 07:22:52 +0900 Subject: [PATCH 01/29] =?UTF-8?q?[#246]test:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EC=82=AC=EC=9A=A9=EA=B0=80=EB=8A=A5=ED=95=9C=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=EC=9D=84=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CouponControllerTest.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java diff --git a/src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java b/src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java new file mode 100644 index 00000000..ce6b36d5 --- /dev/null +++ b/src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java @@ -0,0 +1,77 @@ +package bc1.gream.domain.coupon.controller; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import bc1.gream.domain.buy.service.query.BuyQueryService; +import bc1.gream.domain.coupon.entity.Coupon; +import bc1.gream.domain.coupon.service.qeury.CouponQueryService; +import bc1.gream.global.security.UserDetailsImpl; +import bc1.gream.global.security.WithMockCustomUser; +import bc1.gream.test.CouponTest; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@WebMvcTest(controllers = CouponController.class) +@WithMockCustomUser +@ActiveProfiles("test") +class CouponControllerTest implements CouponTest { + + @Autowired + protected ObjectMapper objectMapper; + @MockBean + CouponQueryService couponQueryService; + @MockBean + BuyQueryService buyQueryService; + @Autowired + private MockMvc mockMvc; + @Autowired + private WebApplicationContext context; + + @BeforeEach + void setUp() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(context) + .alwaysDo(print()).build(); + } + + @Test + void 로그인_한_유저가_사용가능한_쿠폰을_조회하는_컨트롤러_기능_성공_테스트() throws Exception { + + // given + List couponList = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + couponList.add((i % 2 == 0) ? TEST_COUPON_FIX : TEST_COUPON_RATE); + } + + given(couponQueryService.availableCouponList(any(UserDetailsImpl.class))).willReturn(couponList); + + // when - then + mockMvc.perform(get("/api/coupons")) + .andExpectAll( + status().isOk(), + jsonPath("$.code").value(0), + jsonPath("$.message").value("정상 처리 되었습니다"), + jsonPath("$.data.size()").value(5), + jsonPath("$.data[0].discountType").value("FIX"), + jsonPath("$.data[1].discountType").value("RATE") + ); + } + + @Test + void unavailableCouponList() { + } +} \ No newline at end of file From 52352c0c2da5626a7bc3e548bef48d4ab4fc691c Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 07:29:30 +0900 Subject: [PATCH 02/29] =?UTF-8?q?[#246]test:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EC=82=AC=EC=9A=A9=ED=95=9C=20=EC=BF=A0=ED=8F=B0?= =?UTF-8?q?=EC=9D=84=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CouponControllerTest.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java b/src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java index ce6b36d5..fbb2b2fa 100644 --- a/src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java +++ b/src/test/java/bc1/gream/domain/coupon/controller/CouponControllerTest.java @@ -72,6 +72,24 @@ void setUp() { } @Test - void unavailableCouponList() { + void 로그인_한_유저가_이미_사용한_쿠폰을_조회하는_컨트롤러_기능_성공_테스트() throws Exception { + + // given + List couponList = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + couponList.add((i % 2 == 0) ? TEST_COUPON_RATE_USED : TEST_COUPON_FIX_USED); + } + given(couponQueryService.unavailableCouponList(any(UserDetailsImpl.class))).willReturn(couponList); + + // when - then + mockMvc.perform(get("/api/coupons/used")) + .andExpectAll( + status().isOk(), + jsonPath("$.code").value(0), + jsonPath("$.message").value("정상 처리 되었습니다"), + jsonPath("$.data.size()").value(5), + jsonPath("$.data[0].discountType").value("RATE"), + jsonPath("$.data[1].discountType").value("FIX") + ); } } \ No newline at end of file From c10726145338f5566daf23a4e56263f86a3daf6c Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 07:29:40 +0900 Subject: [PATCH 03/29] =?UTF-8?q?[#246]test:=20=EC=9D=B4=EB=AF=B8=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=9C=20=EC=BF=A0=ED=8F=B0=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=8A=A4=ED=85=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/bc1/gream/test/CouponTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/bc1/gream/test/CouponTest.java b/src/test/java/bc1/gream/test/CouponTest.java index 6b0135a7..add0ce49 100644 --- a/src/test/java/bc1/gream/test/CouponTest.java +++ b/src/test/java/bc1/gream/test/CouponTest.java @@ -51,4 +51,18 @@ public interface CouponTest extends UserTest { .status(TEST_COUPON_STATUS_AVAILABLE) .user(TEST_USER) .build(); + + Coupon TEST_COUPON_FIX_USED = Coupon.builder() + .name(TEST_COUPON_NAME) + .discountType(TEST_DISCOUNT_TYPE_WON) + .discount(TEST_DISCOUNT) + .status(TEST_COUPON_STATUS_ALREADY_USED) + .build(); + + Coupon TEST_COUPON_RATE_USED = Coupon.builder() + .name(TEST_COUPON_NAME) + .discountType(TEST_DISCOUNT_TYPE_PERCENT) + .discount(TEST_DISCOUNT_PERCENT) + .status(TEST_COUPON_STATUS_ALREADY_USED) + .build(); } From dd746aab344ae9418febb09c67400f7c4c3bd94a Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:12:50 +0900 Subject: [PATCH 04/29] =?UTF-8?q?[#246]test:=20=EA=B4=80=EB=A6=AC=EC=9E=90?= =?UTF-8?q?=EA=B0=80=5F=EC=82=AC=EC=9A=A9=EC=9E=90=EC=97=90=EA=B2=8C=5F?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=EC=9D=84=5F=EB=93=B1=EB=A1=9D=ED=95=B4?= =?UTF-8?q?=EC=A3=BC=EB=8A=94=5FProvider=5F=EC=84=B1=EA=B3=B5=5F=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coupon/provider/CouponProviderTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/bc1/gream/domain/coupon/provider/CouponProviderTest.java diff --git a/src/test/java/bc1/gream/domain/coupon/provider/CouponProviderTest.java b/src/test/java/bc1/gream/domain/coupon/provider/CouponProviderTest.java new file mode 100644 index 00000000..4fbcb627 --- /dev/null +++ b/src/test/java/bc1/gream/domain/coupon/provider/CouponProviderTest.java @@ -0,0 +1,54 @@ +package bc1.gream.domain.coupon.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + +import bc1.gream.domain.admin.dto.request.AdminCreateCouponRequestDto; +import bc1.gream.domain.coupon.entity.Coupon; +import bc1.gream.domain.coupon.entity.DiscountType; +import bc1.gream.domain.coupon.service.command.CouponCommandService; +import bc1.gream.domain.user.entity.User; +import bc1.gream.domain.user.repository.UserRepository; +import bc1.gream.test.CouponTest; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class CouponProviderTest implements CouponTest { + + @InjectMocks + private CouponProvider couponProvider; + @Mock + private UserRepository userRepository; + @Mock + private CouponCommandService couponCommandService; + + @Test + void 관리자가_사용자에게_쿠폰을_등록해주는_Provider_성공_테스트() { + + // given + AdminCreateCouponRequestDto requestDto = AdminCreateCouponRequestDto.builder() + .name("TEST COUPON") + .discountType(DiscountType.FIX) + .discount(500L) + .userLoginId(TEST_USER_LOGIN_ID) + .build(); + + given(userRepository.findByLoginId(any(String.class))).willReturn(Optional.of(TEST_USER)); + given(couponCommandService.createCoupon(any(User.class), any(AdminCreateCouponRequestDto.class))).willReturn(TEST_COUPON_FIX); + + // when + Coupon resultCoupon = couponProvider.createCoupon(requestDto); + + // then + assertThat(resultCoupon.getName()).isEqualTo(requestDto.name()); + assertThat(resultCoupon.getDiscount()).isEqualTo(requestDto.discount()); + assertThat(resultCoupon.getDiscountType()).isEqualTo(requestDto.discountType()); + + } +} \ No newline at end of file From 2dd87842daafd79a768b8c94899f72b476376baf Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:13:01 +0900 Subject: [PATCH 05/29] =?UTF-8?q?[#246]test:=20=EA=B4=80=EB=A6=AC=EC=9E=90?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8A=A4=ED=85=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/bc1/gream/test/UserTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/bc1/gream/test/UserTest.java b/src/test/java/bc1/gream/test/UserTest.java index f527bd15..f229b34c 100644 --- a/src/test/java/bc1/gream/test/UserTest.java +++ b/src/test/java/bc1/gream/test/UserTest.java @@ -44,4 +44,17 @@ public interface UserTest { .role(UserRole.USER) .provider(Provider.LOCAL) .build(); + + Long TEST_ADMIN_USER_ID = 3L; + String TEST_ADMIN_LOGIN_ID = "admin01"; + String TEST_ADMIN_NICKNAME = "admin01"; + String TEST_ADMIN_PASSWORD = "ABcd5678#&"; + + User TEST_ADMIN_USER = User.builder() + .loginId(TEST_ADMIN_LOGIN_ID) + .nickname(TEST_ADMIN_NICKNAME) + .password(TEST_ADMIN_PASSWORD) + .role(UserRole.ADMIN) + .provider(Provider.LOCAL) + .build(); } From e58d9f61fc4deb90079fbc305244a9ae53c04d8d Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:15:55 +0900 Subject: [PATCH 06/29] =?UTF-8?q?[#246]test:=20=EC=BF=A0=ED=8F=B0=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EC=B2=B4=ED=81=AC=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=84=B1=EA=B3=B5=20/=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/qeury/CouponQueryServiceTest.java | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java diff --git a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java new file mode 100644 index 00000000..5c27cea9 --- /dev/null +++ b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java @@ -0,0 +1,108 @@ +package bc1.gream.domain.coupon.service.qeury; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + +import bc1.gream.domain.coupon.entity.Coupon; +import bc1.gream.domain.coupon.entity.CouponStatus; +import bc1.gream.domain.coupon.repository.CouponRepository; +import bc1.gream.global.common.ResultCase; +import bc1.gream.global.exception.GlobalException; +import bc1.gream.test.CouponTest; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class CouponQueryServiceTest implements CouponTest { + + @InjectMocks + private CouponQueryService couponQueryService; + + @Mock + private CouponRepository couponRepository; + + @Test + void 쿠폰이_상태가_원하는_상태인지_체크하는_서비스_기능_성공_테스트() { + + // given + given(couponRepository.findById(any(Long.class))).willReturn(Optional.of(TEST_COUPON_OF_TEST_USER)); + + // when + Coupon coupon = couponQueryService.checkCoupon(TEST_COUPON_ID, TEST_USER, CouponStatus.AVAILABLE); + + // then + assertThat(coupon.getName()).isEqualTo(TEST_COUPON_OF_TEST_USER.getName()); + assertThat(coupon.getDiscount()).isEqualTo(TEST_COUPON_OF_TEST_USER.getDiscount()); + assertThat(coupon.getDiscountType()).isEqualTo(TEST_COUPON_OF_TEST_USER.getDiscountType()); + } + + @Test + void 쿠폰이_상태가_원하는_상태인지_체크하는_서비스_기능_쿠폰이_존재하지_않으므로_인한_테스트() { + + // given + given(couponRepository.findById(any(Long.class))).willReturn(Optional.empty()); + + // when + GlobalException exception = assertThrows(GlobalException.class, () -> { + couponQueryService.checkCoupon(TEST_COUPON_ID, TEST_BUYER, CouponStatus.AVAILABLE); + }); + + // then + assertThat(exception.getResultCase()).isEqualTo(ResultCase.COUPON_NOT_FOUND); + assertThat(exception.getResultCase().getCode()).isEqualTo(ResultCase.COUPON_NOT_FOUND.getCode()); + assertThat(exception.getResultCase().getMessage()).isEqualTo(ResultCase.COUPON_NOT_FOUND.getMessage()); + } + + @Test + void 쿠폰이_상태가_원하는_상태인지_체크하는_서비스_기능_로그인한_유저의_쿠폰이_아님으로_인한_실패_테스트() { + + // given + given(couponRepository.findById(any(Long.class))).willReturn(Optional.of(TEST_COUPON_OF_TEST_USER)); + + // when + GlobalException exception = assertThrows(GlobalException.class, () -> { + couponQueryService.checkCoupon(TEST_COUPON_ID, TEST_BUYER, CouponStatus.AVAILABLE); + }); + + // then + assertThat(exception.getResultCase()).isEqualTo(ResultCase.NOT_AUTHORIZED); + assertThat(exception.getResultCase().getCode()).isEqualTo(ResultCase.NOT_AUTHORIZED.getCode()); + assertThat(exception.getResultCase().getMessage()).isEqualTo(ResultCase.NOT_AUTHORIZED.getMessage()); + } + + @Test + void 쿠폰이_사용가능한지_체크하는_서비스_기능_이미_사용한_쿠폰으로_인한_실패_테스트() { + + // given + given(couponRepository.findById(any(Long.class))).willReturn(Optional.of(TEST_COUPON_OF_TEST_USER)); + + // when + GlobalException exception = assertThrows(GlobalException.class, () -> { + couponQueryService.checkCoupon(TEST_COUPON_ID, TEST_USER, CouponStatus.ALREADY_USED); + }); + + // then + assertThat(exception.getResultCase()).isEqualTo(ResultCase.COUPON_STATUS_CHANGE_FAIL); + assertThat(exception.getResultCase().getCode()).isEqualTo(ResultCase.COUPON_STATUS_CHANGE_FAIL.getCode()); + assertThat(exception.getResultCase().getMessage()).isEqualTo(ResultCase.COUPON_STATUS_CHANGE_FAIL.getMessage()); + } + + @Test + void availableCouponList() { + + } + + @Test + void unavailableCouponList() { + } + + @Test + void findCouponById() { + } +} \ No newline at end of file From a4e615e6508321192203758ae77adbd118e91fc3 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:16:30 +0900 Subject: [PATCH 07/29] =?UTF-8?q?[#246]test:=20=EA=B8=B0=EC=A1=B4=20User?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EC=95=88=EC=97=90=20=EC=9E=88=EB=8D=98=20CouponQueryServiceTes?= =?UTF-8?q?t=20Coupon=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/qeury/CouponQueryServiceTest.java | 24 ++++++++++ .../user/service/CouponQueryServiceTest.java | 47 ------------------- 2 files changed, 24 insertions(+), 47 deletions(-) delete mode 100644 src/test/java/bc1/gream/domain/user/service/CouponQueryServiceTest.java diff --git a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java index 5c27cea9..2c78d14a 100644 --- a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java @@ -2,16 +2,22 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import bc1.gream.domain.coupon.entity.Coupon; import bc1.gream.domain.coupon.entity.CouponStatus; import bc1.gream.domain.coupon.repository.CouponRepository; +import bc1.gream.domain.user.entity.User; import bc1.gream.global.common.ResultCase; import bc1.gream.global.exception.GlobalException; import bc1.gream.test.CouponTest; import java.util.Optional; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -105,4 +111,22 @@ void unavailableCouponList() { @Test void findCouponById() { } + + @Test + @DisplayName("쿠폰에 대한 회원 접근권한을 검증합니다.") + public void 쿠폰_회원접근권한_검증() { + // GIVEN + User mockUser = mock(User.class); + given(mockUser.getLoginId()).willReturn(TEST_USER_LOGIN_ID); + Coupon mockCoupon = mock(Coupon.class); + given(mockCoupon.getUser()).willReturn(mockUser); + + // WHEN + boolean matchCouponUser = couponQueryService.isMatchCouponUser(mockUser, mockCoupon); + + // THEN + assertTrue(matchCouponUser); + verify(mockUser, times(2)).getLoginId(); // verify getLoginId() has called on mockUser + verify(mockCoupon, times(1)).getUser(); // verify getUser() has called on mockCoupon + } } \ No newline at end of file diff --git a/src/test/java/bc1/gream/domain/user/service/CouponQueryServiceTest.java b/src/test/java/bc1/gream/domain/user/service/CouponQueryServiceTest.java deleted file mode 100644 index ecf77ad6..00000000 --- a/src/test/java/bc1/gream/domain/user/service/CouponQueryServiceTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package bc1.gream.domain.user.service; - -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import bc1.gream.domain.coupon.entity.Coupon; -import bc1.gream.domain.coupon.repository.CouponRepository; -import bc1.gream.domain.coupon.service.qeury.CouponQueryService; -import bc1.gream.domain.user.entity.User; -import bc1.gream.test.CouponTest; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class CouponQueryServiceTest implements CouponTest { - - @Mock - private CouponRepository couponRepository; - - @InjectMocks - private CouponQueryService couponQueryService; - - @Test - @DisplayName("쿠폰에 대한 회원 접근권한을 검증합니다.") - public void 쿠폰_회원접근권한_검증() { - // GIVEN - User mockUser = mock(User.class); - given(mockUser.getLoginId()).willReturn(TEST_USER_LOGIN_ID); - Coupon mockCoupon = mock(Coupon.class); - given(mockCoupon.getUser()).willReturn(mockUser); - - // WHEN - boolean matchCouponUser = couponQueryService.isMatchCouponUser(mockUser, mockCoupon); - - // THEN - assertTrue(matchCouponUser); - verify(mockUser, times(2)).getLoginId(); // verify getLoginId() has called on mockUser - verify(mockCoupon, times(1)).getUser(); // verify getUser() has called on mockCoupon - } -} \ No newline at end of file From 717ce17d2729de29ad2b02690f7c064f4f6b8d8d Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:09:24 +0900 Subject: [PATCH 08/29] =?UTF-8?q?[#246]test:=20=EC=BF=A0=ED=8F=B0=EC=9D=B4?= =?UTF-8?q?=20=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=EC=9E=85=EC=B0=B0=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EB=B6=84=ED=95=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/query/BuyQueryServiceTest.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/test/java/bc1/gream/domain/buy/service/query/BuyQueryServiceTest.java b/src/test/java/bc1/gream/domain/buy/service/query/BuyQueryServiceTest.java index cf61f1ee..c6fffe69 100644 --- a/src/test/java/bc1/gream/domain/buy/service/query/BuyQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/buy/service/query/BuyQueryServiceTest.java @@ -137,7 +137,7 @@ class BuyQueryServiceTest implements BuyTest, CouponTest { } @Test - void 현재_진행중인_유저의_구매입찰_전체_조회_서비스_기능_성공_테스트() { + void 현재_진행중인_유저의_구매입찰에_쿠폰이_존재할때_전체_조회_서비스_기능_성공_테스트() { // given List responseDtoList = new ArrayList<>(); @@ -146,7 +146,7 @@ class BuyQueryServiceTest implements BuyTest, CouponTest { .buyId((long) i) .price(1000L * i) .discountPrice(1000L * i) - .coupon((i % 2 == 0) ? TEST_COUPON_FIX : null) + .coupon(TEST_COUPON_FIX) .build(); responseDtoList.add(responseDto); @@ -158,13 +158,44 @@ class BuyQueryServiceTest implements BuyTest, CouponTest { // then assertThat(resultList.size()).isEqualTo(5); - assertThat(resultList.get(0).discountPrice()).isEqualTo(responseDtoList.get(0).discountPrice()); + assertThat(resultList.get(0).discountPrice()).isEqualTo( + CouponCalculator.calculateDiscount(TEST_COUPON_FIX, responseDtoList.get(0).discountPrice())); assertThat(resultList.get(1).discountPrice()).isEqualTo( CouponCalculator.calculateDiscount(TEST_COUPON_FIX, responseDtoList.get(1).discountPrice())); - assertThat(resultList.get(2).discountPrice()).isEqualTo(responseDtoList.get(2).discountPrice()); + assertThat(resultList.get(2).discountPrice()).isEqualTo( + CouponCalculator.calculateDiscount(TEST_COUPON_FIX, responseDtoList.get(2).discountPrice())); assertThat(resultList.get(3).discountPrice()).isEqualTo( CouponCalculator.calculateDiscount(TEST_COUPON_FIX, responseDtoList.get(3).discountPrice())); - assertThat(resultList.get(4).discountPrice()).isEqualTo(responseDtoList.get(4).discountPrice()); + assertThat(resultList.get(4).discountPrice()).isEqualTo( + CouponCalculator.calculateDiscount(TEST_COUPON_FIX, responseDtoList.get(4).discountPrice())); + } + + @Test + void 현재_진행중인_유저의_구매입찰에_쿠폰이_존재하지_않을때_전체_조회_서비스_기능_성공_테스트() { + + // given + List responseDtoList = new ArrayList<>(); + for (int i = 1; i <= 5; i++) { + BuyCheckBidResponseDto responseDto = BuyCheckBidResponseDto.builder() + .buyId((long) i) + .price(1000L * i) + .discountPrice(1000L * i) + .coupon(null) + .build(); + + responseDtoList.add(responseDto); + } + given(buyRepository.findAllBuyBidCoupon(any(User.class))).willReturn(responseDtoList); + + // when + List resultList = buyQueryService.findAllBuyBidCoupon(TEST_USER); + + // then + assertThat(resultList.size()).isEqualTo(5); + assertThat(resultList.get(0).discountPrice()).isEqualTo(responseDtoList.get(0).discountPrice()); + assertThat(resultList.get(1).discountPrice()).isEqualTo(responseDtoList.get(1).discountPrice()); + assertThat(resultList.get(2).discountPrice()).isEqualTo(responseDtoList.get(2).discountPrice()); + assertThat(resultList.get(3).discountPrice()).isEqualTo(responseDtoList.get(3).discountPrice()); } @Test From d29c35f274a9b29cea8f515be932f6c7bde0586b Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:14:23 +0900 Subject: [PATCH 09/29] =?UTF-8?q?[#246]refactor:=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EB=90=9C=20=EC=BF=A0=ED=8F=B0=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=20=EB=A1=9C=EC=A7=81=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coupon/service/qeury/CouponQueryService.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/main/java/bc1/gream/domain/coupon/service/qeury/CouponQueryService.java b/src/main/java/bc1/gream/domain/coupon/service/qeury/CouponQueryService.java index 6fe8aa08..8395d5cd 100644 --- a/src/main/java/bc1/gream/domain/coupon/service/qeury/CouponQueryService.java +++ b/src/main/java/bc1/gream/domain/coupon/service/qeury/CouponQueryService.java @@ -24,11 +24,7 @@ public class CouponQueryService { public Coupon checkCoupon(Long couponId, User buyer, CouponStatus status) { - Coupon coupon = findByCouponId(couponId); - - if (!isCheckCouponUser(coupon, buyer)) { - throw new GlobalException(ResultCase.NOT_AUTHORIZED); - } + Coupon coupon = findCouponById(couponId, buyer); if (!isCheckCouponStatus(coupon, status)) { throw new GlobalException(ResultCase.COUPON_STATUS_CHANGE_FAIL); @@ -37,16 +33,6 @@ public Coupon checkCoupon(Long couponId, User buyer, CouponStatus status) { return coupon; } - private Coupon findByCouponId(Long couponId) { - return couponRepository.findById(couponId).orElseThrow( - () -> new GlobalException(ResultCase.COUPON_NOT_FOUND) - ); - } - - private boolean isCheckCouponUser(Coupon coupon, User user) { - return coupon.getUser().getLoginId().equals(user.getLoginId()); - } - private boolean isCheckCouponStatus(Coupon coupon, CouponStatus status) { return coupon.getStatus().equals(status); } From 0ee700887638f70404f03f8e304d6a9da53dbf56 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:33:52 +0900 Subject: [PATCH 10/29] =?UTF-8?q?[#246]refactor:=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=9C=20=EC=9C=A0=EC=A0=80=EC=9D=98=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/qeury/CouponQueryServiceTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java index 2c78d14a..5e4f4f7d 100644 --- a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java @@ -15,7 +15,10 @@ import bc1.gream.domain.user.entity.User; import bc1.gream.global.common.ResultCase; import bc1.gream.global.exception.GlobalException; +import bc1.gream.global.security.UserDetailsImpl; import bc1.gream.test.CouponTest; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -100,8 +103,25 @@ class CouponQueryServiceTest implements CouponTest { } @Test - void availableCouponList() { + void 사용_가능한_유저의_쿠폰_리스트_조회_성공_테스트() { + // given + List couponList = new ArrayList<>(); + + for (int i = 0; i < 3; i++) { + couponList.add(TEST_COUPON_FIX); + } + + given(couponRepository.availableCoupon(any(User.class))).willReturn(couponList); + UserDetailsImpl userDetails = new UserDetailsImpl(TEST_USER); + + // when + List resultList = couponQueryService.availableCouponList(userDetails); + + // then + assertThat(resultList.get(0)).isEqualTo(couponList.get(0)); + assertThat(resultList.get(1)).isEqualTo(couponList.get(1)); + assertThat(resultList.get(2)).isEqualTo(couponList.get(2)); } @Test From e2746a06e2033a75f693c0c1d348478f7b6bd48c Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:37:59 +0900 Subject: [PATCH 11/29] =?UTF-8?q?[#246]test:=20=EC=82=AC=EC=9A=A9=EC=9D=B4?= =?UTF-8?q?=20=EB=B6=88=EA=B0=80=EB=8A=A5=ED=95=9C=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=9D=98=20=EC=BF=A0=ED=8F=B0=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/qeury/CouponQueryServiceTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java index 5e4f4f7d..4d664fa8 100644 --- a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java @@ -126,6 +126,24 @@ class CouponQueryServiceTest implements CouponTest { @Test void unavailableCouponList() { + + // given + List couponList = new ArrayList<>(); + + for (int i = 0; i < 3; i++) { + couponList.add(TEST_COUPON_FIX_USED); + } + + given(couponRepository.unavailable(any(User.class))).willReturn(couponList); + UserDetailsImpl userDetails = new UserDetailsImpl(TEST_USER); + + // when + List resultList = couponQueryService.unavailableCouponList(userDetails); + + // then + assertThat(resultList.get(0)).isEqualTo(couponList.get(0)); + assertThat(resultList.get(1)).isEqualTo(couponList.get(1)); + assertThat(resultList.get(2)).isEqualTo(couponList.get(2)); } @Test From 449f69dc6a04a171beec629e3d27bf54e8cc1b0b Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:52:32 +0900 Subject: [PATCH 12/29] =?UTF-8?q?[#246]test:=20=EC=BF=A0=ED=8F=B0=EC=9D=84?= =?UTF-8?q?=20=EC=BF=A0=ED=8F=B0=EC=95=84=EC=9D=B4=EB=94=94=EC=99=80=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EC=A0=95=EB=B3=B4=EB=A1=9C=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=ED=95=98=EB=8A=94=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/qeury/CouponQueryServiceTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java index 4d664fa8..40600873 100644 --- a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java @@ -147,7 +147,18 @@ void unavailableCouponList() { } @Test - void findCouponById() { + void 쿠폰을_아이디와_유저로_체크하는_서비스_기능_성공_테스트() { + + // given + given(couponRepository.findById(any(Long.class))).willReturn(Optional.of(TEST_COUPON_OF_TEST_USER)); + + // when + Coupon coupon = couponQueryService.findCouponById(TEST_COUPON_ID, TEST_USER); + + // then + assertThat(coupon.getName()).isEqualTo(TEST_COUPON_OF_TEST_USER.getName()); + assertThat(coupon.getDiscount()).isEqualTo(TEST_COUPON_OF_TEST_USER.getDiscount()); + assertThat(coupon.getStatus()).isEqualTo(TEST_COUPON_OF_TEST_USER.getStatus()); } @Test From 4a25d15e4fb55cb6ec35189cb07dcc2358134a0c Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:52:53 +0900 Subject: [PATCH 13/29] =?UTF-8?q?[#246]test:=20=EC=BF=A0=ED=8F=B0=EC=9D=84?= =?UTF-8?q?=20=EC=BF=A0=ED=8F=B0=EC=95=84=EC=9D=B4=EB=94=94=EC=99=80=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EC=A0=95=EB=B3=B4=EB=A1=9C=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=ED=95=98=EB=8A=94=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=8B=A4=ED=8C=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/qeury/CouponQueryServiceTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java index 40600873..97e22059 100644 --- a/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/coupon/service/qeury/CouponQueryServiceTest.java @@ -161,6 +161,40 @@ void unavailableCouponList() { assertThat(coupon.getStatus()).isEqualTo(TEST_COUPON_OF_TEST_USER.getStatus()); } + @Test + void 쿠폰을_아이디와_유저로_체크하는_서비스_기능_쿠폰이_존재하지_않으므로_인한_실패_테스트() { + + // given + given(couponRepository.findById(any(Long.class))).willReturn(Optional.empty()); + + // when + GlobalException exception = assertThrows(GlobalException.class, () -> { + couponQueryService.findCouponById(TEST_COUPON_ID, TEST_USER); + }); + + // then + assertThat(exception.getResultCase()).isEqualTo(ResultCase.COUPON_NOT_FOUND); + assertThat(exception.getResultCase().getCode()).isEqualTo(ResultCase.COUPON_NOT_FOUND.getCode()); + assertThat(exception.getResultCase().getMessage()).isEqualTo(ResultCase.COUPON_NOT_FOUND.getMessage()); + } + + @Test + void 쿠폰을_아이디와_유저로_체크하는_서비스_기능_쿠폰이_유저의_소유가_아니므로_인한_실패_테스트() { + + // given + given(couponRepository.findById(any(Long.class))).willReturn(Optional.of(TEST_COUPON_OF_TEST_USER)); + + // when + GlobalException exception = assertThrows(GlobalException.class, () -> { + couponQueryService.findCouponById(TEST_COUPON_ID, TEST_BUYER); + }); + + // then + assertThat(exception.getResultCase()).isEqualTo(ResultCase.NOT_AUTHORIZED); + assertThat(exception.getResultCase().getCode()).isEqualTo(ResultCase.NOT_AUTHORIZED.getCode()); + assertThat(exception.getResultCase().getMessage()).isEqualTo(ResultCase.NOT_AUTHORIZED.getMessage()); + } + @Test @DisplayName("쿠폰에 대한 회원 접근권한을 검증합니다.") public void 쿠폰_회원접근권한_검증() { From 76cc9f9f9e8527de7a3719397517f1b49063d4ec Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:10:30 +0900 Subject: [PATCH 14/29] =?UTF-8?q?[#254]test:=20=ED=99=98=EA=B8=89=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8A=A4?= =?UTF-8?q?=ED=85=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/bc1/gream/test/RefundTest.java | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/bc1/gream/test/RefundTest.java diff --git a/src/test/java/bc1/gream/test/RefundTest.java b/src/test/java/bc1/gream/test/RefundTest.java new file mode 100644 index 00000000..b876b1ca --- /dev/null +++ b/src/test/java/bc1/gream/test/RefundTest.java @@ -0,0 +1,21 @@ +package bc1.gream.test; + +import bc1.gream.domain.user.entity.Refund; + +public interface RefundTest extends UserTest { + + Long TEST_REFUND_ID = 1L; + + Long TEST_REFUND_POINT = 1000L; + + String TEST_REFUND_BANK = "농협은행"; + + String TEST_REFUND_ACCOUNT_NUMBER = "111-1111-1111111"; + + Refund TEST_REFUND = Refund.builder() + .point(TEST_REFUND_POINT) + .bank(TEST_REFUND_BANK) + .accountNumber(TEST_REFUND_ACCOUNT_NUMBER) + .user(TEST_USER) + .build(); +} From 6904d29f69bd1ba72dd21fb6f2aa63fa517bf341 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:11:52 +0900 Subject: [PATCH 15/29] =?UTF-8?q?[#254]test:=20=EC=8B=A0=EC=B2=AD=EB=90=9C?= =?UTF-8?q?=20=ED=99=98=EA=B8=89=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=EC=9E=90=EA=B0=80=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/AdminControllerTest.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java index 11a50432..5fadf7e4 100644 --- a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java +++ b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java @@ -1,19 +1,27 @@ package bc1.gream.domain.admin.controller; +import static org.mockito.BDDMockito.given; +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.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import bc1.gream.domain.admin.dto.request.AdminCreateCouponRequestDto; +import bc1.gream.domain.admin.dto.request.AdminGetRefundRequestDto; import bc1.gream.domain.coupon.entity.DiscountType; import bc1.gream.domain.coupon.provider.CouponProvider; import bc1.gream.domain.product.service.command.ProductCommandService; +import bc1.gream.domain.user.entity.Refund; import bc1.gream.domain.user.entity.UserRole; import bc1.gream.domain.user.service.command.RefundCommandService; import bc1.gream.domain.user.service.query.RefundQueryService; import bc1.gream.global.security.WithMockCustomUser; +import bc1.gream.test.RefundTest; import bc1.gream.test.UserTest; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +36,7 @@ @WebMvcTest(controllers = AdminController.class) @WithMockCustomUser(loginId = "adminId12", password = "adminPw12!", userRole = UserRole.ADMIN) @ActiveProfiles("test") -class AdminControllerTest { +class AdminControllerTest implements RefundTest { @Autowired WebApplicationContext context; @@ -49,9 +57,37 @@ class AdminControllerTest { void setUp() { this.mockMvc = MockMvcBuilders .webAppContextSetup(context) + .alwaysDo(print()) .build(); } + @Test + void 신청된_환급_리스트를_관리자가_조회하는_컨트롤러_기능_성공_테스트() throws Exception { + + // given + AdminGetRefundRequestDto requestDto = new AdminGetRefundRequestDto(); + + String json = objectMapper.writeValueAsString(requestDto); + + List responseList = new ArrayList<>(); + + for (int i = 0; i < 5; i++) { + responseList.add(TEST_REFUND); + } + + given(refundQueryService.getRefunds()).willReturn(responseList); + + // when - then + mockMvc.perform(get("/api/admin/refunds") + .content(json) + .contentType(MediaType.APPLICATION_JSON)) + .andExpectAll( + status().isOk(), + jsonPath("$.code").value(0), + jsonPath("$.message").value("정상 처리 되었습니다") + ); + } + @Test public void 새로운_쿠폰_추가_정상요청() throws Exception { // GIVEN From e33400d41fc4801c55b5c521b73fa83062ab5ee0 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:12:13 +0900 Subject: [PATCH 16/29] =?UTF-8?q?[#254]test:=20=EA=B4=80=EB=A6=AC=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EC=83=88=EB=A1=9C=EC=9A=B4=20=EC=83=81=ED=92=88?= =?UTF-8?q?=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/AdminControllerTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java index 5fadf7e4..679365f4 100644 --- a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java +++ b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java @@ -9,6 +9,7 @@ import bc1.gream.domain.admin.dto.request.AdminCreateCouponRequestDto; import bc1.gream.domain.admin.dto.request.AdminGetRefundRequestDto; +import bc1.gream.domain.admin.dto.request.AdminProductRequestDto; import bc1.gream.domain.coupon.entity.DiscountType; import bc1.gream.domain.coupon.provider.CouponProvider; import bc1.gream.domain.product.service.command.ProductCommandService; @@ -88,6 +89,31 @@ void setUp() { ); } + @Test + void 관리자가_새로운_상품을_추가하는_컨트롤러_기능_성공_테스트() throws Exception { + + // given + AdminProductRequestDto requestDto = AdminProductRequestDto.builder() + .brand("스타벅스") + .name("콜드브루") + .imageUrl("C:/") + .description("콜드브루") + .price(6000L) + .build(); + + String json = objectMapper.writeValueAsString(requestDto); + + // when - then + mockMvc.perform(post("/api/admin/products") + .content(json) + .contentType(MediaType.APPLICATION_JSON)) + .andExpectAll( + status().isOk(), + jsonPath("$.code").value(0), + jsonPath("$.message").value("정상 처리 되었습니다") + ); + } + @Test public void 새로운_쿠폰_추가_정상요청() throws Exception { // GIVEN From 9d3d0999d6dde394ba1855b8565e78b83f8a9089 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:12:35 +0900 Subject: [PATCH 17/29] =?UTF-8?q?[#254]test:=20=EC=9C=A0=EC=A0=80=EA=B0=80?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD=ED=95=9C=20=ED=99=98=EA=B8=89=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EA=B4=80=EB=A6=AC=EC=9E=90=EA=B0=80=20=EC=8A=B9?= =?UTF-8?q?=EC=9D=B8=ED=95=98=EB=8A=94=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/AdminControllerTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java index 679365f4..beb38553 100644 --- a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java +++ b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java @@ -1,6 +1,8 @@ package bc1.gream.domain.admin.controller; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +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.MockMvcResultHandlers.print; @@ -10,6 +12,7 @@ import bc1.gream.domain.admin.dto.request.AdminCreateCouponRequestDto; import bc1.gream.domain.admin.dto.request.AdminGetRefundRequestDto; import bc1.gream.domain.admin.dto.request.AdminProductRequestDto; +import bc1.gream.domain.admin.dto.request.AdminRefundPassResponseDto; import bc1.gream.domain.coupon.entity.DiscountType; import bc1.gream.domain.coupon.provider.CouponProvider; import bc1.gream.domain.product.service.command.ProductCommandService; @@ -114,6 +117,22 @@ void setUp() { ); } + @Test + void 유저가_요청한_환급내역_관리자가_승인하는_컨트롤러_기능_성공_테스트() throws Exception { + + // given + AdminRefundPassResponseDto responseDto = new AdminRefundPassResponseDto(); + given(refundCommandService.approveRefund(any(Long.class))).willReturn(responseDto); + + // when - then + mockMvc.perform(delete("/api/admin/refund/{id}", TEST_REFUND_ID)) + .andExpectAll( + status().isOk(), + jsonPath("$.code").value(0), + jsonPath("$.message").value("정상 처리 되었습니다") + ); + } + @Test public void 새로운_쿠폰_추가_정상요청() throws Exception { // GIVEN From 881366e0b1ab7b815c1a043827727f919e027e48 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:30:45 +0900 Subject: [PATCH 18/29] =?UTF-8?q?[#256]test:=20=EC=83=88=EB=A1=9C=EC=9A=B4?= =?UTF-8?q?=20=EA=B8=B0=ED=94=84=ED=8B=B0=EC=BD=98=EC=9D=84=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=ED=95=98=EB=8A=94=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/GifticonCommandServiceTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java diff --git a/src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java b/src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java new file mode 100644 index 00000000..321983ac --- /dev/null +++ b/src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java @@ -0,0 +1,32 @@ +package bc1.gream.domain.gifticon.service.command; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import bc1.gream.domain.gifticon.entity.Gifticon; +import bc1.gream.domain.gifticon.repository.GifticonRepository; +import bc1.gream.test.GifticonTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class GifticonCommandServiceTest implements GifticonTest { + + @InjectMocks + private GifticonCommandService gifticonCommandService; + @Mock + private GifticonRepository gifticonRepository; + + @Test + void 새로운_기프티콘을_등록하는_서비스_기능_성공_테스트() { + // given - when + gifticonCommandService.saveGifticon(TEST_GIFTICON_URL, TEST_ORDER); + + // then + verify(gifticonRepository, times(1)).save(any(Gifticon.class)); + } +} \ No newline at end of file From e5e174ae015fa6a28c5ad7e053464d2dba9d3752 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:31:49 +0900 Subject: [PATCH 19/29] =?UTF-8?q?[#256]test:=20=EB=93=B1=EB=A1=9D=EB=90=98?= =?UTF-8?q?=EC=96=B4=EC=9E=88=EB=8A=94=20=ED=82=A4=ED=94=84=ED=8B=B0?= =?UTF-8?q?=EC=BD=98=EC=9D=84=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/command/GifticonCommandServiceTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java b/src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java index 321983ac..0efb7e08 100644 --- a/src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java +++ b/src/test/java/bc1/gream/domain/gifticon/service/command/GifticonCommandServiceTest.java @@ -29,4 +29,13 @@ class GifticonCommandServiceTest implements GifticonTest { // then verify(gifticonRepository, times(1)).save(any(Gifticon.class)); } + + @Test + void 등록되어있는_기프티콘을_삭제하는_서비스_기능_성공_테스트() { + // given - when + gifticonCommandService.delete(TEST_GIFTICON); + + // then + verify(gifticonRepository, times(1)).delete(any(Gifticon.class)); + } } \ No newline at end of file From f6ba1b31ec030103816527f0bb7f2e2583a3900a Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:39:54 +0900 Subject: [PATCH 20/29] =?UTF-8?q?[#256]test:=20=ED=8C=90=EB=A7=A4=EC=9E=90?= =?UTF-8?q?=20=EA=B8=B0=EC=A4=80=20=ED=8C=90=EB=A7=A4=EA=B0=80=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=EB=90=9C=20=EA=B8=B0=ED=94=84=ED=8B=B0=EC=BD=98=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query/GifticonQueryServiceTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java diff --git a/src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java b/src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java new file mode 100644 index 00000000..e2b83f69 --- /dev/null +++ b/src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java @@ -0,0 +1,50 @@ +package bc1.gream.domain.gifticon.service.query; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + +import bc1.gream.domain.gifticon.entity.Gifticon; +import bc1.gream.domain.gifticon.repository.GifticonRepository; +import bc1.gream.domain.user.entity.User; +import bc1.gream.test.GifticonTest; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class GifticonQueryServiceTest implements GifticonTest { + + @Mock + GifticonRepository gifticonRepository; + @InjectMocks + private GifticonQueryService gifticonQueryService; + + @Test + void 판매자_기준_판매가_완료된_기프티콘_전체_조회하는_서비스_기능_성공_테스트() { + // given + List gifticonList = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + gifticonList.add(TEST_GIFTICON); + } + + given(gifticonRepository.findAllSoldBySeller(any(User.class))).willReturn(gifticonList); + + // when + List resultList = gifticonQueryService.findAllSoldBySeller(TEST_USER); + + // then + assertThat(resultList.get(0)).isEqualTo(gifticonList.get(0)); + assertThat(resultList.get(1)).isEqualTo(gifticonList.get(1)); + assertThat(resultList.get(2)).isEqualTo(gifticonList.get(2)); + assertThat(resultList.get(3)).isEqualTo(gifticonList.get(3)); + } + + @Test + void getBoughtOrder() { + } +} \ No newline at end of file From afa02b8db49ba3e3803a51438acc77edde81d827 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:44:54 +0900 Subject: [PATCH 21/29] =?UTF-8?q?[#256]test:=20=EA=B5=AC=EB=A7=A4=EC=9E=90?= =?UTF-8?q?=20=EA=B8=B0=EC=A4=80=20=EA=B1=B0=EB=9E=98=EA=B0=80=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=EB=90=9C=20=EA=B8=B0=ED=94=84=ED=8B=B0=EC=BD=98=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query/GifticonQueryServiceTest.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java b/src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java index e2b83f69..817c7d65 100644 --- a/src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/gifticon/service/query/GifticonQueryServiceTest.java @@ -4,6 +4,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import bc1.gream.domain.buy.dto.response.BuyCheckOrderResponseDto; import bc1.gream.domain.gifticon.entity.Gifticon; import bc1.gream.domain.gifticon.repository.GifticonRepository; import bc1.gream.domain.user.entity.User; @@ -25,7 +26,7 @@ class GifticonQueryServiceTest implements GifticonTest { private GifticonQueryService gifticonQueryService; @Test - void 판매자_기준_판매가_완료된_기프티콘_전체_조회하는_서비스_기능_성공_테스트() { + void 판매자_기준_거래가_완료된_기프티콘_전체_조회하는_서비스_기능_성공_테스트() { // given List gifticonList = new ArrayList<>(); for (int i = 0; i < 5; i++) { @@ -45,6 +46,26 @@ class GifticonQueryServiceTest implements GifticonTest { } @Test - void getBoughtOrder() { + void 구매자_기준_거래가_완료된_기프티콘_전체_조회하는_서비스_기능_성공_테스트() { + // given + List gifticonList = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + Gifticon gifticon = Gifticon.builder() + .gifticonUrl(TEST_GIFTICON_URL) + .order(TEST_ORDER) + .build(); + gifticonList.add(gifticon); + } + + given(gifticonRepository.findAllBoughtByBuyer(any(User.class))).willReturn(gifticonList); + + // when + List resultList = gifticonQueryService.getBoughtOrder(TEST_USER); + + // then + assertThat(resultList.get(0).gifticonUrl()).isEqualTo(TEST_GIFTICON_URL); + assertThat(resultList.get(1).gifticonUrl()).isEqualTo(TEST_GIFTICON_URL); + assertThat(resultList.get(2).gifticonUrl()).isEqualTo(TEST_GIFTICON_URL); + assertThat(resultList.get(3).gifticonUrl()).isEqualTo(TEST_GIFTICON_URL); } } \ No newline at end of file From d0faeb0592bb413fa5a7fc3e8c27be6c27e23cec Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:54:10 +0900 Subject: [PATCH 22/29] =?UTF-8?q?[#258]test:=20=ED=8C=90=EB=A7=A4=EC=9E=90?= =?UTF-8?q?=20=EA=B8=B0=EC=A4=80=20=EC=A3=BC=EB=AC=B8=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EC=84=9C=EB=AF=B8?= =?UTF-8?q?=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1=EA=B3=B5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/query/OrderQueryServiceTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/bc1/gream/domain/order/service/query/OrderQueryServiceTest.java b/src/test/java/bc1/gream/domain/order/service/query/OrderQueryServiceTest.java index 7b9f6e9f..a11843d0 100644 --- a/src/test/java/bc1/gream/domain/order/service/query/OrderQueryServiceTest.java +++ b/src/test/java/bc1/gream/domain/order/service/query/OrderQueryServiceTest.java @@ -1,14 +1,19 @@ package bc1.gream.domain.order.service.query; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import bc1.gream.domain.order.entity.Order; import bc1.gream.domain.order.repository.OrderRepository; import bc1.gream.domain.product.entity.Product; +import bc1.gream.domain.user.entity.User; import bc1.gream.test.OrderTest; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -50,4 +55,34 @@ class OrderQueryServiceTest implements OrderTest { assertEquals(recentOrder, trades.get(0)); assertEquals(pastOrder, trades.get(1)); } + + @Test + void 판매자_기준_주문_전체_조회하는_서비스_기능_성공_테스트() { + // given + List orderList = new ArrayList<>(); + + for (int i = 0; i < 5; i++) { + Order order = Order.builder() + .buyer(TEST_BUYER) + .seller(TEST_SELLER) + .product(TEST_PRODUCT) + .finalPrice(1000L * i) + .expectedPrice(1000L * i) + .build(); + + orderList.add(order); + } + + given(orderRepository.findAllBySellerOrderByCreatedAtDesc(any(User.class))).willReturn(orderList); + // when + List resultList = orderQueryService.findAllOrderBySeller(TEST_SELLER); + + // then + assertThat(resultList.get(0).getExpectedPrice()).isEqualTo(orderList.get(0).getExpectedPrice()); + assertThat(resultList.get(1).getExpectedPrice()).isEqualTo(orderList.get(1).getExpectedPrice()); + assertThat(resultList.get(2).getExpectedPrice()).isEqualTo(orderList.get(2).getExpectedPrice()); + assertThat(resultList.get(3).getExpectedPrice()).isEqualTo(orderList.get(3).getExpectedPrice()); + assertThat(resultList.get(4).getExpectedPrice()).isEqualTo(orderList.get(4).getExpectedPrice()); + + } } \ No newline at end of file From 6390fb8f32dbe3c5de3b1ab2d8ffbb943f88b41a Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:00:24 +0900 Subject: [PATCH 23/29] =?UTF-8?q?[#258]test:=20=EA=B5=AC=EB=A7=A4=EB=A1=9C?= =?UTF-8?q?=20=EC=9D=B8=ED=95=98=EC=97=AC=20=EC=83=88=EB=A1=9C=EC=9A=B4=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9D=B4=20=EC=83=9D=EA=B8=B0=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/OrderCommandServiceTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java diff --git a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java new file mode 100644 index 00000000..40c720ae --- /dev/null +++ b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java @@ -0,0 +1,46 @@ +package bc1.gream.domain.order.service.command; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import bc1.gream.domain.order.entity.Order; +import bc1.gream.domain.order.repository.OrderRepository; +import bc1.gream.test.BuyTest; +import bc1.gream.test.CouponTest; +import bc1.gream.test.OrderTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { + + @InjectMocks + private OrderCommandService orderCommandService; + @Mock + private OrderRepository orderRepository; + + @Test + void 구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트() { + // given - when + orderCommandService.saveOrderOfBuy(TEST_BUY_COUPON, TEST_SELLER, TEST_COUPON_FIX); + + // then + verify(orderRepository, times(1)).save(any(Order.class)); + } + + @Test + void saveOrderOfBuyNotCoupon() { + } + + @Test + void saveOrderOfSell() { + } + + @Test + void saveOrderOfSellNotCoupon() { + } +} \ No newline at end of file From d01d20bc6572fd395fd9228eb614da04d8cddf8a Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:01:19 +0900 Subject: [PATCH 24/29] =?UTF-8?q?[#258]test:=20=EA=B5=AC=EB=A7=A4=EB=A1=9C?= =?UTF-8?q?=20=EC=9D=B8=ED=95=98=EC=97=AC=20=EC=83=88=EB=A1=9C=EC=9A=B4=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9D=B4=20=EC=83=9D=EA=B8=B0=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/order/service/command/OrderCommandServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java index 40c720ae..cbc57d21 100644 --- a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java +++ b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java @@ -24,7 +24,7 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { private OrderRepository orderRepository; @Test - void 구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트() { + void 구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_있을떄() { // given - when orderCommandService.saveOrderOfBuy(TEST_BUY_COUPON, TEST_SELLER, TEST_COUPON_FIX); From 3b46bc3cb07d40a7f44c3dc5ab5961b17f79f68d Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:02:22 +0900 Subject: [PATCH 25/29] =?UTF-8?q?[#258]test:=20=EA=B5=AC=EB=A7=A4=EB=A1=9C?= =?UTF-8?q?=20=EC=9D=B8=ED=95=98=EC=97=AC=20=EC=83=88=EB=A1=9C=EC=9A=B4=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9D=B4=20=EC=83=9D=EA=B8=B0=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BF=A0=ED=8F=B0?= =?UTF-8?q?=EC=9D=B4=20=EC=97=86=EC=9D=84=20=EB=95=8C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/command/OrderCommandServiceTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java index cbc57d21..f50649b0 100644 --- a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java +++ b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java @@ -33,7 +33,12 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { } @Test - void saveOrderOfBuyNotCoupon() { + void 구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_없을때() { + // given - when + orderCommandService.saveOrderOfBuyNotCoupon(TEST_BUY, TEST_SELLER); + + // then + verify(orderRepository, times(1)).save(any(Order.class)); } @Test From 5b4fa50071764f9696a563c58e715c04240bd700 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:02:51 +0900 Subject: [PATCH 26/29] =?UTF-8?q?[#258]test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EB=AA=85=ED=99=95=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/command/OrderCommandServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java index f50649b0..f75b872b 100644 --- a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java +++ b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java @@ -24,7 +24,7 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { private OrderRepository orderRepository; @Test - void 구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_있을떄() { + void 즉시구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_있을떄() { // given - when orderCommandService.saveOrderOfBuy(TEST_BUY_COUPON, TEST_SELLER, TEST_COUPON_FIX); @@ -33,7 +33,7 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { } @Test - void 구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_없을때() { + void 즉시구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_없을때() { // given - when orderCommandService.saveOrderOfBuyNotCoupon(TEST_BUY, TEST_SELLER); @@ -42,7 +42,7 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { } @Test - void saveOrderOfSell() { + void () { } @Test From db9f0fd382d335336e9ef95bbb2422473ce5a93e Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:06:54 +0900 Subject: [PATCH 27/29] =?UTF-8?q?[#258]test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A6=89=EC=8B=9C=20=EA=B5=AC=EB=A7=A4=20=EC=BF=A0=ED=8F=B0=20?= =?UTF-8?q?=EC=9E=88=EC=9D=84=20=EB=95=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/command/OrderCommandServiceTest.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java index f75b872b..28ada1f2 100644 --- a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java +++ b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java @@ -9,6 +9,7 @@ import bc1.gream.test.BuyTest; import bc1.gream.test.CouponTest; import bc1.gream.test.OrderTest; +import bc1.gream.test.SellTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -16,7 +17,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { +class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest, SellTest { @InjectMocks private OrderCommandService orderCommandService; @@ -24,7 +25,7 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { private OrderRepository orderRepository; @Test - void 즉시구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_있을떄() { + void 즉시판매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_있을떄() { // given - when orderCommandService.saveOrderOfBuy(TEST_BUY_COUPON, TEST_SELLER, TEST_COUPON_FIX); @@ -33,7 +34,7 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { } @Test - void 즉시구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_없을때() { + void 즉시판매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_없을때() { // given - when orderCommandService.saveOrderOfBuyNotCoupon(TEST_BUY, TEST_SELLER); @@ -42,10 +43,11 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest { } @Test - void () { - } + void 즉시구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_있을때() { + // given - when + orderCommandService.saveOrderOfSell(TEST_SELL, TEST_BUYER, TEST_COUPON_FIX); - @Test - void saveOrderOfSellNotCoupon() { + // then + verify(orderRepository, times(1)).save(any(Order.class)); } } \ No newline at end of file From 747713a3e65dd101c7f3c14cc8e928af9df2bb3b Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:07:31 +0900 Subject: [PATCH 28/29] =?UTF-8?q?[#258]test:=20=EC=A6=89=EC=8B=9C=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=EB=A1=9C=20=EC=9D=B8=ED=95=B4=20=EC=83=88=EB=A1=9C?= =?UTF-8?q?=EC=9A=B4=20=EC=A3=BC=EB=AC=B8=20=EC=83=9D=EA=B8=B0=EB=8A=94=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BF=A0=ED=8F=B0?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EB=95=8C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/command/OrderCommandServiceTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java index 28ada1f2..109cb23e 100644 --- a/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java +++ b/src/test/java/bc1/gream/domain/order/service/command/OrderCommandServiceTest.java @@ -50,4 +50,13 @@ class OrderCommandServiceTest implements OrderTest, BuyTest, CouponTest, SellTes // then verify(orderRepository, times(1)).save(any(Order.class)); } + + @Test + void 즉시구매로_인하여_새로운_주문이_생기는_서비스_기능_성공_테스트_쿠폰이_없을때() { + // given - when + orderCommandService.saveOrderOfSellNotCoupon(TEST_SELL, TEST_BUYER); + + // then + verify(orderRepository, times(1)).save(any(Order.class)); + } } \ No newline at end of file From c08ac13b6e2b30d7c83f4e754483f2135a501d13 Mon Sep 17 00:00:00 2001 From: Mayst <48579987+Mayst1232@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:10:50 +0900 Subject: [PATCH 29/29] =?UTF-8?q?[#255]test:=20=ED=99=98=EA=B8=89=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20response=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=20=EB=B6=80=EB=B6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gream/domain/admin/controller/AdminControllerTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java index beb38553..4a36d260 100644 --- a/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java +++ b/src/test/java/bc1/gream/domain/admin/controller/AdminControllerTest.java @@ -88,7 +88,12 @@ void setUp() { .andExpectAll( status().isOk(), jsonPath("$.code").value(0), - jsonPath("$.message").value("정상 처리 되었습니다") + jsonPath("$.message").value("정상 처리 되었습니다"), + jsonPath("$.data[0].refundBank").value("농협은행"), + jsonPath("$.data[1].refundBank").value("농협은행"), + jsonPath("$.data[2].refundBank").value("농협은행"), + jsonPath("$.data[3].refundBank").value("농협은행"), + jsonPath("$.data[4].refundBank").value("농협은행") ); }