54 lines
2.2 KiB
Java
54 lines
2.2 KiB
Java
|
|
package com.linhelp.order;
|
||
|
|
|
||
|
|
import com.linhelp.common.enums.DeliveryMethod;
|
||
|
|
import com.linhelp.common.enums.GoodsOrderStatus;
|
||
|
|
import com.linhelp.product.ProductService;
|
||
|
|
import com.linhelp.product.ProductSkuResponse;
|
||
|
|
import org.junit.jupiter.api.Test;
|
||
|
|
|
||
|
|
import java.util.Collections;
|
||
|
|
|
||
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
||
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||
|
|
|
||
|
|
class GoodsOrderServiceTests {
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void cannotCreateGoodsOrderWhenSkuStockIsInsufficient() {
|
||
|
|
ProductService productService = new ProductService();
|
||
|
|
ProductSkuResponse sku = productService.createDemoSku(1L, 1L, 1L, "500g", 990, 2);
|
||
|
|
GoodsOrderService goodsOrderService = new GoodsOrderService(productService);
|
||
|
|
|
||
|
|
CreateGoodsOrderRequest request = new CreateGoodsOrderRequest();
|
||
|
|
request.setTenantId(1L);
|
||
|
|
request.setCommunityId(1L);
|
||
|
|
request.setMerchantId(1L);
|
||
|
|
request.setAddressId(1L);
|
||
|
|
request.setDeliveryMethod(DeliveryMethod.IMMEDIATE);
|
||
|
|
request.setItems(Collections.singletonList(new CreateGoodsOrderItemRequest(1L, sku.getId(), 99)));
|
||
|
|
|
||
|
|
assertThatThrownBy(() -> goodsOrderService.create(1L, request))
|
||
|
|
.hasMessageContaining("库存不足");
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
void selfPickupOrderMovesToPendingPickupAfterPreparing() {
|
||
|
|
ProductService productService = new ProductService();
|
||
|
|
ProductSkuResponse sku = productService.createDemoSku(1L, 1L, 1L, "500g", 990, 5);
|
||
|
|
GoodsOrderService goodsOrderService = new GoodsOrderService(productService);
|
||
|
|
|
||
|
|
CreateGoodsOrderRequest request = new CreateGoodsOrderRequest();
|
||
|
|
request.setTenantId(1L);
|
||
|
|
request.setCommunityId(1L);
|
||
|
|
request.setMerchantId(1L);
|
||
|
|
request.setDeliveryMethod(DeliveryMethod.SELF_PICKUP);
|
||
|
|
request.setItems(Collections.singletonList(new CreateGoodsOrderItemRequest(1L, sku.getId(), 1)));
|
||
|
|
GoodsOrderResponse order = goodsOrderService.create(1L, request);
|
||
|
|
|
||
|
|
goodsOrderService.confirm(order.getId());
|
||
|
|
goodsOrderService.markPrepared(order.getId());
|
||
|
|
|
||
|
|
assertThat(goodsOrderService.detail(order.getId()).getStatus()).isEqualTo(GoodsOrderStatus.PENDING_PICKUP);
|
||
|
|
}
|
||
|
|
}
|