Skip to content

Commit

Permalink
Merge pull request #624 from TeamObjects/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
minwoorich authored May 4, 2024
2 parents 3762af9 + 316e927 commit f23e0e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void create(CreateOrderDto createOrderDto) {
// 4. Product 의 stock 감소
order.stockDecrease();

// TODO : 장바구니가 아닌 바로구매로 물건을 구매했을 경우 에러 발생 할 수 있음. 해결 해야함.
// 5. 구매완료한 상품들 장바구니에서 제거하기
Long memberId = createOrderDto.getMemberId();
List<Long> deletedProductIds = createOrderDto.getProductValues().stream().map(CreateOrderDto.ProductDto::getProductId).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

Expand All @@ -24,6 +25,7 @@
@SpringBootTest
@ActiveProfiles("test")
@Slf4j
@Transactional
public class CreateOrderServiceTest {

@Autowired MemberRepository memberRepository;
Expand All @@ -42,20 +44,23 @@ void create_remove_cart_item() {
member.addAddress(address);

Product product1 = productRepository.save(Product.builder()
.id(1L)
.stock(999L)
.productNo("111111 - 111111")
.name("가방")
.price(20000L)
.build());

Product product2 = productRepository.save(Product.builder()
.id(2L)
.stock(999L)
.productNo("111111 - 111111")
.name("책")
.price(20000L)
.build());

Product product3 = productRepository.save(Product.builder()
.id(3L)
.stock(999L)
.productNo("111111 - 111111")
.name("신발")
Expand All @@ -67,27 +72,27 @@ void create_remove_cart_item() {
cartCommandRepository.save(Cart.builder().member(member).product(product3).build());

CreateOrderDto.ProductDto productDto1 = CreateOrderDto.ProductDto.builder()
.productId(1L)
.productId(product1.getId())
.price(20000L)
.quantity(1L)
.hasCouponUsed(false)
.build();
CreateOrderDto.ProductDto productDto2 = CreateOrderDto.ProductDto.builder()
.productId(2L)
.productId(product2.getId())
.price(20000L)
.quantity(1L)
.hasCouponUsed(false)
.build();
CreateOrderDto.ProductDto productDto3 = CreateOrderDto.ProductDto.builder()
.productId(3L)
.productId(product3.getId())
.price(20000L)
.quantity(1L)
.hasCouponUsed(false)
.build();

CreateOrderDto createOrderDto = CreateOrderDto.builder()
.tid("tid")
.memberId(1L)
.memberId(member.getId())
.addressId(1L)
.orderName("가방")
.orderNo("1111-2222-3333-4444")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.objects.marketbridge.common.exception.exceptions.ErrorCode;
import com.objects.marketbridge.common.utils.DateTimeHolder;
import com.objects.marketbridge.domains.cart.domain.Cart;
import com.objects.marketbridge.domains.cart.mock.BaseFakeCartRepository;
import com.objects.marketbridge.domains.cart.mock.FakeCartCommandRepository;
import com.objects.marketbridge.domains.cart.mock.FakeCartQueryRepository;
import com.objects.marketbridge.domains.cart.service.port.CartCommandRepository;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class CreateOrderServiceTestWithFake {
.build();

CreateOrderService createOrderService = CreateOrderService.builder()
.cartCommandRepository(cartCommandRepository)
.orderDetailCommandRepository(orderDetailCommandRepository)
.orderCommandRepository(orderCommandRepository)
.productRepository(productRepository)
Expand All @@ -72,6 +74,8 @@ public class CreateOrderServiceTestWithFake {
void clear() {
BaseFakeOrderRepository.getInstance().clear();
BaseFakeOrderDetailRepository.getInstance().clear();
BaseFakeCartRepository.getInstance().clear();
couponRepository.deleteAllInBatch();
productRepository.deleteAllInBatch();
memberRepository.deleteAllInBatch();
memberCouponRepository.deleteAllInBatch();
Expand Down Expand Up @@ -109,6 +113,8 @@ void create(){

productRepository.save(product);

cartCommandRepository.save(Cart.builder().member(member).product(product).build());

CreateOrderDto.ProductDto productDto = CreateOrderDto.ProductDto.builder()
.productId(1L)
.price(20000L)
Expand Down Expand Up @@ -180,6 +186,8 @@ void create_order_detail(){
.build();

productRepository.save(product);
cartCommandRepository.save(Cart.builder().member(member).product(product).build());


CreateOrderDto.ProductDto productDto = CreateOrderDto.ProductDto.builder()
.productId(1L)
Expand Down Expand Up @@ -263,6 +271,8 @@ void create_change_coupon_usage(){

productRepository.save(product);

cartCommandRepository.save(Cart.builder().member(member).product(product).build());

CreateOrderDto.ProductDto productDto = CreateOrderDto.ProductDto.builder()
.productId(1L)
.price(20000L)
Expand Down Expand Up @@ -328,6 +338,8 @@ void create_stock_decrease(){

productRepository.save(product);

cartCommandRepository.save(Cart.builder().member(member).product(product).build());

CreateOrderDto.ProductDto productDto = CreateOrderDto.ProductDto.builder()
.productId(1L)
.price(20000L)
Expand Down Expand Up @@ -464,6 +476,8 @@ void create_error_stock(){

productRepository.save(product);

cartCommandRepository.save(Cart.builder().member(member).product(product).build());

CreateOrderDto.ProductDto productDto = CreateOrderDto.ProductDto.builder()
.productId(1L)
.price(20000L)
Expand Down

0 comments on commit f23e0e2

Please sign in to comment.