Skip to content

Commit

Permalink
[test] RedisCartDao 테스트코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyeon-Uk committed Aug 22, 2024
1 parent 3735291 commit 99bae24
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/test/java/camp/woowak/lab/web/dao/cart/RedisCartDaoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package camp.woowak.lab.web.dao.cart;

import static org.assertj.core.api.Assertions.*;

import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import camp.woowak.lab.cart.domain.Cart;
import camp.woowak.lab.cart.repository.CartRepository;
import camp.woowak.lab.customer.domain.Customer;
import camp.woowak.lab.customer.repository.CustomerRepository;
import camp.woowak.lab.menu.domain.Menu;
import camp.woowak.lab.menu.domain.MenuCategory;
import camp.woowak.lab.menu.repository.MenuCategoryRepository;
import camp.woowak.lab.menu.repository.MenuRepository;
import camp.woowak.lab.order.repository.OrderRepository;
import camp.woowak.lab.payaccount.repository.PayAccountRepository;
import camp.woowak.lab.store.domain.Store;
import camp.woowak.lab.store.repository.StoreCategoryRepository;
import camp.woowak.lab.store.repository.StoreRepository;
import camp.woowak.lab.vendor.repository.VendorRepository;
import camp.woowak.lab.web.dao.store.StoreDummiesFixture;
import camp.woowak.lab.web.dto.response.CartResponse;

@SpringBootTest
class RedisCartDaoTest extends StoreDummiesFixture {
private final CartRepository cartRepository;
@Autowired
private RedisCartDao redisCartDao;

@Autowired
public RedisCartDaoTest(StoreRepository storeRepository,
StoreCategoryRepository storeCategoryRepository,
VendorRepository vendorRepository,
PayAccountRepository payAccountRepository,
OrderRepository orderRepository,
CustomerRepository customerRepository,
MenuRepository menuRepository,
MenuCategoryRepository menuCategoryRepository,
CartRepository cartRepository) {
super(storeRepository, storeCategoryRepository, vendorRepository, payAccountRepository, orderRepository,
customerRepository, menuRepository, menuCategoryRepository);
this.cartRepository = cartRepository;
}

private Customer customer;
private Store store;
private MenuCategory menuCategory;
private List<Menu> menus;

@BeforeEach
void setUp() {
customer = createDummyCustomers(1).get(0);
store = createDummyStores(1).get(0);
menuCategory = createDummyMenuCategories(store,1).get(0);
menus = createDummyMenus(store,menuCategory,5);
}

@Test
@DisplayName("findByCustomerId 메서드는 장바구니에 담긴 메뉴의 아이템을 가져온다.")
void findByCustomerIdTest(){
//given
Cart cart = new Cart(customer.getId().toString());
cartRepository.save(cart);
menus.stream()
.forEach(cart::addMenu);
Cart save = cartRepository.save(cart);

//when
CartResponse response = redisCartDao.findByCustomerId(customer.getId());

//then
assertThat(response.getStoreId()).isEqualTo(store.getId());
assertThat(response.getStoreName()).isEqualTo(store.getName());
assertThat(response.getMinOrderPrice()).isEqualTo(store.getMinOrderPrice());
}
}

0 comments on commit 99bae24

Please sign in to comment.