Skip to content

Commit

Permalink
test: 테스트 커버리지 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hongdosan committed Nov 27, 2023
1 parent 6aa7272 commit c9238c3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,10 @@ void getByWalletIdAndMemberId_success() {
assertThat(actual.getCoupon().getName()).isEqualTo(couponWallet.getCoupon().getName());
}

@WithMember
@DisplayName("특정 회원이 쿠폰 지갑에 가지고 있는 특정 쿠폰을 성공적으로 사용한다. - Void")
@Test
void use_success() {
// Given
AuthMember authMember = AuthorizationThreadLocal.getAuthMember();
Member member = MemberFixture.member(BugFixture.zeroBug());
Coupon coupon = CouponFixture.coupon(CouponType.GOLDEN, 1000);
CouponWallet couponWallet = CouponWallet.create(1L, coupon);
Expand All @@ -332,43 +330,71 @@ void use_success() {
.willReturn(Optional.of(couponWallet));

// When
couponService.use(authMember.id(), 1L);
couponService.use(1L, 1L);

// Then
verify(couponWalletRepository).delete(any(CouponWallet.class));
}

@WithMember
@DisplayName("특정 회원이 쿠폰 지갑에 가지고 있는 할인 쿠폰을 사용한다. - BadRequestException")
@Test
void use_BadRequestException() {
// Given
AuthMember authMember = AuthorizationThreadLocal.getAuthMember();
Coupon coupon = CouponFixture.coupon(CouponType.DISCOUNT, 1000);
CouponWallet couponWallet = CouponWallet.create(authMember.id(), coupon);
CouponWallet couponWallet = CouponWallet.create(1L, coupon);

given(couponWalletSearchRepository.findByIdAndMemberId(any(Long.class), any(Long.class)))
.willReturn(Optional.of(couponWallet));

// When & Then
assertThatThrownBy(() -> couponService.use(authMember.id(), 1L))
assertThatThrownBy(() -> couponService.use(1L, 1L))
.isInstanceOf(BadRequestException.class)
.hasMessage(ErrorMessage.INVALID_DISCOUNT_COUPON.getMessage());
}

@WithMember
@DisplayName("특정 회원이 쿠폰 지갑에 가지고 있지 않은 쿠폰을 사용한다. - NotFoundException")
@Test
void use_NotFoundException() {
// Given
AuthMember authMember = AuthorizationThreadLocal.getAuthMember();

given(couponWalletSearchRepository.findByIdAndMemberId(any(Long.class), any(Long.class)))
.willReturn(Optional.empty());

// When & Then
assertThatThrownBy(() -> couponService.use(authMember.id(), 1L))
assertThatThrownBy(() -> couponService.use(1L, 1L))
.isInstanceOf(NotFoundException.class)
.hasMessage(ErrorMessage.NOT_FOUND_COUPON_WALLET.getMessage());
}

@DisplayName("결제할 때, 할인 쿠폰을 사용한다. - Void")
@Test
void discount_success() {
// Given
Coupon coupon = CouponFixture.coupon(CouponType.DISCOUNT, 1000);
CouponWallet couponWallet = CouponWallet.create(1L, coupon);

given(couponWalletSearchRepository.findByIdAndMemberId(any(Long.class), any(Long.class)))
.willReturn(Optional.of(couponWallet));

// When
couponService.discount(1L, 1L);

// Then
verify(couponWalletRepository).delete(couponWallet);
}

@DisplayName("결제할 때, 벌레 쿠폰을 사용한다. - BadRequestException")
@Test
void discount_BadRequestException() {
// Given
Coupon coupon = CouponFixture.coupon(CouponType.GOLDEN, 1000);
CouponWallet couponWallet = CouponWallet.create(1L, coupon);

given(couponWalletSearchRepository.findByIdAndMemberId(any(Long.class), any(Long.class)))
.willReturn(Optional.of(couponWallet));

// When & Then
assertThatThrownBy(() -> couponService.discount(1L, 1L))
.isInstanceOf(BadRequestException.class)
.hasMessage(ErrorMessage.INVALID_BUG_COUPON.getMessage());
}
}
21 changes: 21 additions & 0 deletions src/test/java/com/moabam/api/domain/coupon/CouponTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.moabam.api.domain.bug.BugType;
import com.moabam.global.error.exception.NotFoundException;
import com.moabam.global.error.model.ErrorMessage;

Expand All @@ -28,4 +29,24 @@ void from_NotFoundException() {
.isInstanceOf(NotFoundException.class)
.hasMessage(ErrorMessage.NOT_FOUND_COUPON_TYPE.getMessage());
}

@DisplayName("할인 쿠폰인 확인한다. - Boolean")
@Test
void isDiscount_true() {
// When
boolean actual = CouponType.DISCOUNT.isDiscount();

// Then
assertThat(actual).isTrue();
}

@DisplayName("벌레 타입을 반환한다. - CouponType")
@Test
void getBugType_success() {
// When
BugType actual = CouponType.GOLDEN.getBugType();

// Then
assertThat(actual).isEqualTo(BugType.GOLDEN);
}
}

0 comments on commit c9238c3

Please sign in to comment.