Skip to content

Commit

Permalink
test: 쿠폰 지갑 레포지토리 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
kmebin committed Nov 22, 2023
1 parent 25dc141 commit 60352bf
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.moabam.api.domain.coupon.repository;

import static com.moabam.support.fixture.CouponFixture.*;
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.moabam.api.domain.coupon.Coupon;
import com.moabam.api.domain.coupon.CouponWallet;
import com.moabam.support.annotation.QuerydslRepositoryTest;

@QuerydslRepositoryTest
class CouponWalletSearchRepositoryTest {

@Autowired
private CouponRepository couponRepository;

@Autowired
private CouponWalletRepository couponWalletRepository;

@Autowired
private CouponWalletSearchRepository couponWalletSearchRepository;

@DisplayName("회원의 특정 쿠폰 지갑을 조회한다.")
@Test
void find_by_id_and_member_id() {
// given
Long id = 1L;
Long memberId = 1L;
Coupon coupon = couponRepository.save(discount1000Coupon());
couponWalletRepository.save(couponWallet(memberId, coupon));

// when
CouponWallet actual = couponWalletSearchRepository.findByIdAndMemberId(id, memberId).orElseThrow();

// then
assertThat(actual.getCoupon()).isEqualTo(coupon);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import com.moabam.api.domain.coupon.repository.CouponWalletSearchRepository;
import com.moabam.api.domain.item.repository.InventorySearchRepository;
import com.moabam.api.domain.item.repository.ItemSearchRepository;
import com.moabam.api.domain.member.repository.MemberSearchRepository;
Expand Down Expand Up @@ -44,4 +45,9 @@ public CertificationsSearchRepository certificationsSearchRepository() {
public MemberSearchRepository memberSearchRepository() {
return new MemberSearchRepository(jpaQueryFactory());
}

@Bean
public CouponWalletSearchRepository couponWalletSearchRepository() {
return new CouponWalletSearchRepository(jpaQueryFactory());
}
}
8 changes: 8 additions & 0 deletions src/test/java/com/moabam/support/fixture/CouponFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.moabam.api.domain.coupon.Coupon;
import com.moabam.api.domain.coupon.CouponType;
import com.moabam.api.domain.coupon.CouponWallet;
import com.moabam.api.dto.coupon.CouponStatusRequest;
import com.moabam.api.dto.coupon.CreateCouponRequest;

Expand Down Expand Up @@ -64,6 +65,13 @@ public static Coupon discount10000Coupon() {
.build();
}

public static CouponWallet couponWallet(Long memberId, Coupon coupon) {
return CouponWallet.builder()
.memberId(memberId)
.coupon(coupon)
.build();
}

public static CreateCouponRequest createCouponRequest(String couponType, int startMonth, int endMonth) {
return CreateCouponRequest.builder()
.name("couponName")
Expand Down

0 comments on commit 60352bf

Please sign in to comment.