You've already forked FrameTour-BE
feat(pricing): 新增照片打印SKU及价格计算逻辑
- 添加 PHOTO_PRINT_MU 和 PHOTO_PRINT_FX 枚举类型定义 - 实现手机照片打印和特效照片打印的基础价格计算(单价×数量) - 支持景区特定配置的价格计算逻辑 - 验证新SKU与现有 PHOTO_PRINT 的行为一致性 - 添加相关单元测试确保价格计算准确性
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.ycwl.basic.pricing.entity;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ycwl.basic.pricing.dto.BundleProductItem;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 验证PriceBundleConfig新数据结构的测试
|
||||
*/
|
||||
class PriceBundleConfigStructureTest {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void testNewDataStructure() throws JsonProcessingException {
|
||||
// 创建测试数据
|
||||
BundleProductItem includedItem = new BundleProductItem();
|
||||
includedItem.setType("PHOTO_PRINT");
|
||||
includedItem.setSubType("6寸照片");
|
||||
includedItem.setQuantity(20);
|
||||
|
||||
BundleProductItem excludedItem = new BundleProductItem();
|
||||
excludedItem.setType("VLOG_VIDEO");
|
||||
excludedItem.setProductId("video_001");
|
||||
excludedItem.setQuantity(1);
|
||||
|
||||
List<BundleProductItem> includedProducts = List.of(includedItem);
|
||||
List<BundleProductItem> excludedProducts = List.of(excludedItem);
|
||||
|
||||
// 创建实体
|
||||
PriceBundleConfig config = new PriceBundleConfig();
|
||||
config.setBundleName("全家福套餐");
|
||||
config.setBundlePrice(new BigDecimal("99.00"));
|
||||
config.setIncludedProducts(includedProducts);
|
||||
config.setExcludedProducts(excludedProducts);
|
||||
config.setDescription("包含20张6寸照片打印");
|
||||
config.setIsActive(true);
|
||||
|
||||
// 验证数据结构
|
||||
assertNotNull(config.getIncludedProducts());
|
||||
assertNotNull(config.getExcludedProducts());
|
||||
assertEquals(1, config.getIncludedProducts().size());
|
||||
assertEquals(1, config.getExcludedProducts().size());
|
||||
|
||||
// 验证包含商品
|
||||
BundleProductItem included = config.getIncludedProducts().get(0);
|
||||
assertEquals("PHOTO_PRINT", included.getType());
|
||||
assertEquals("6寸照片", included.getSubType());
|
||||
assertEquals(20, included.getQuantity());
|
||||
|
||||
// 验证排除商品
|
||||
BundleProductItem excluded = config.getExcludedProducts().get(0);
|
||||
assertEquals("VLOG_VIDEO", excluded.getType());
|
||||
assertEquals("video_001", excluded.getProductId());
|
||||
assertEquals(1, excluded.getQuantity());
|
||||
|
||||
// 验证JSON序列化
|
||||
String includedJson = objectMapper.writeValueAsString(config.getIncludedProducts());
|
||||
String excludedJson = objectMapper.writeValueAsString(config.getExcludedProducts());
|
||||
|
||||
System.out.println("Included Products JSON: " + includedJson);
|
||||
System.out.println("Excluded Products JSON: " + excludedJson);
|
||||
|
||||
// 验证能正确反序列化
|
||||
List<BundleProductItem> deserializedIncluded = objectMapper.readValue(includedJson,
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, BundleProductItem.class));
|
||||
assertEquals(1, deserializedIncluded.size());
|
||||
assertEquals("PHOTO_PRINT", deserializedIncluded.get(0).getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFrontendExpectedFormat() throws JsonProcessingException {
|
||||
// 测试前端期望的JSON格式
|
||||
String expectedJson = "[{\"type\":\"PHOTO_PRINT\",\"subType\":\"6寸照片\",\"quantity\":20}]";
|
||||
|
||||
List<BundleProductItem> items = objectMapper.readValue(expectedJson,
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, BundleProductItem.class));
|
||||
|
||||
assertEquals(1, items.size());
|
||||
assertEquals("PHOTO_PRINT", items.get(0).getType());
|
||||
assertEquals("6寸照片", items.get(0).getSubType());
|
||||
assertEquals(20, items.get(0).getQuantity());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user