|
|
@@ -25,12 +25,14 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
|
+import com.ruoyi.system.domain.FoodSpecsValue;
|
|
|
import com.ruoyi.system.domain.PosFood;
|
|
|
import com.ruoyi.system.domain.PosOrder;
|
|
|
import com.ruoyi.system.domain.PosOrderPromotion;
|
|
|
import com.ruoyi.system.dto.PromotionCalcRequest;
|
|
|
import com.ruoyi.system.dto.PromotionCalcResponse;
|
|
|
import com.ruoyi.system.dto.PromotionCalcResponse.PromotionDetail;
|
|
|
+import com.ruoyi.system.mapper.FoodSpecsValueMapper;
|
|
|
import com.ruoyi.system.mapper.PosFoodMapper;
|
|
|
import com.ruoyi.system.mapper.PosOrderPromotionMapper;
|
|
|
import com.ruoyi.system.service.IPromotionCalcService;
|
|
|
@@ -58,6 +60,9 @@ class OrderPromotionHelperFreeDeliveryTest
|
|
|
@Mock
|
|
|
private PosFoodMapper posFoodMapper;
|
|
|
|
|
|
+ @Mock
|
|
|
+ private FoodSpecsValueMapper foodSpecsValueMapper;
|
|
|
+
|
|
|
@Mock
|
|
|
private FoodDeliveryPromotionQuoteService foodDeliveryPromotionQuoteService;
|
|
|
|
|
|
@@ -142,7 +147,15 @@ class OrderPromotionHelperFreeDeliveryTest
|
|
|
PromotionCalcRequest.CartItem item = new PromotionCalcRequest.CartItem();
|
|
|
item.setProductId(FOOD_ID);
|
|
|
item.setQuantity(2);
|
|
|
- item.setSpecValueIds(List.of(301L));
|
|
|
+ item.setSpecValueIds(List.of(301L, 302L));
|
|
|
+ FoodSpecsValue size = new FoodSpecsValue();
|
|
|
+ size.setId(301L);
|
|
|
+ size.setName("小");
|
|
|
+ FoodSpecsValue spice = new FoodSpecsValue();
|
|
|
+ spice.setId(302L);
|
|
|
+ spice.setName("中辣");
|
|
|
+ when(foodSpecsValueMapper.selectById(301L)).thenReturn(size);
|
|
|
+ when(foodSpecsValueMapper.selectById(302L)).thenReturn(spice);
|
|
|
|
|
|
String json = helper.buildServerFoodJson(List.of(item));
|
|
|
JSONArray foods = JSON.parseArray(json);
|
|
|
@@ -151,6 +164,16 @@ class OrderPromotionHelperFreeDeliveryTest
|
|
|
assertEquals(10, foods.getJSONObject(0).getIntValue("otherPrice"));
|
|
|
assertEquals(2, foods.getJSONObject(0).getIntValue("number"));
|
|
|
assertEquals("测试商品", foods.getJSONObject(0).getString("name"));
|
|
|
+ // 有加价的规格也要保留名称和 ID,供订单详情展示。
|
|
|
+ assertEquals(List.of("小", "中辣"), foods.getJSONObject(0).getJSONArray("ask").toJavaList(String.class));
|
|
|
+ assertEquals(List.of(301L, 302L), foods.getJSONObject(0).getJSONArray("specValueIds").toJavaList(Long.class));
|
|
|
+
|
|
|
+ when(foodDeliveryPromotionQuoteService.resolveSpecSurcharge(any(), any()))
|
|
|
+ .thenReturn(BigDecimal.ZERO);
|
|
|
+ JSONArray freeSpecFoods = JSON.parseArray(helper.buildServerFoodJson(List.of(item)));
|
|
|
+ assertEquals(0, freeSpecFoods.getJSONObject(0).getIntValue("otherPrice"));
|
|
|
+ // 零加价不代表未选择规格。
|
|
|
+ assertEquals(List.of("小", "中辣"), freeSpecFoods.getJSONObject(0).getJSONArray("ask").toJavaList(String.class));
|
|
|
}
|
|
|
|
|
|
@Test
|