You've already forked FrameTour-BE
feat(pricing): 支持景区维度的价格配置和优惠策略控制
- 新增按景区ID查询商品配置和阶梯价格配置的方法 - 扩展价格计算服务以支持景区级别的优惠策略 - 更新优惠券和代金券提供者以使用景区维度配置 - 修改商品配置服务实现多级查询优先级(景区特定->景区默认->全局特定->全局默认) - 添加商品类型能力服务测试用例 - 增强价格计算逻辑的容错性和向后兼容性
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
package com.ycwl.basic.product.service;
|
||||
|
||||
import com.ycwl.basic.product.capability.DuplicateCheckStrategy;
|
||||
import com.ycwl.basic.product.capability.PricingMode;
|
||||
import com.ycwl.basic.product.capability.ProductTypeCapability;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 商品类型能力服务测试
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class ProductTypeCapabilityServiceTest {
|
||||
|
||||
@Autowired(required = false)
|
||||
private IProductTypeCapabilityService productTypeCapabilityService;
|
||||
|
||||
@Test
|
||||
public void testGetCapability_VLOG_VIDEO() {
|
||||
if (productTypeCapabilityService == null) {
|
||||
System.out.println("服务未注入,跳过测试(可能数据库未迁移)");
|
||||
return;
|
||||
}
|
||||
|
||||
ProductTypeCapability capability = productTypeCapabilityService.getCapability("VLOG_VIDEO");
|
||||
|
||||
assertNotNull(capability);
|
||||
assertEquals("VLOG_VIDEO", capability.getProductType());
|
||||
assertEquals("Vlog视频", capability.getDisplayName());
|
||||
assertEquals("VIDEO", capability.getCategory());
|
||||
assertEquals(PricingMode.FIXED, capability.getPricingModeEnum());
|
||||
assertEquals(false, capability.getAllowDuplicatePurchase());
|
||||
assertEquals(DuplicateCheckStrategy.CHECK_BY_VIDEO_ID, capability.getDuplicateCheckStrategyEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCapability_PHOTO_PRINT() {
|
||||
if (productTypeCapabilityService == null) {
|
||||
System.out.println("服务未注入,跳过测试(可能数据库未迁移)");
|
||||
return;
|
||||
}
|
||||
|
||||
ProductTypeCapability capability = productTypeCapabilityService.getCapability("PHOTO_PRINT");
|
||||
|
||||
assertNotNull(capability);
|
||||
assertEquals("PHOTO_PRINT", capability.getProductType());
|
||||
assertEquals("照片打印", capability.getDisplayName());
|
||||
assertEquals("PRINT", capability.getCategory());
|
||||
assertEquals(PricingMode.QUANTITY_BASED, capability.getPricingModeEnum());
|
||||
assertEquals(true, capability.getAllowDuplicatePurchase());
|
||||
assertEquals(DuplicateCheckStrategy.NO_CHECK, capability.getDuplicateCheckStrategyEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDisplayName() {
|
||||
if (productTypeCapabilityService == null) {
|
||||
System.out.println("服务未注入,跳过测试(可能数据库未迁移)");
|
||||
return;
|
||||
}
|
||||
|
||||
String displayName = productTypeCapabilityService.getDisplayName("RECORDING_SET");
|
||||
assertEquals("录像集", displayName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowDuplicatePurchase() {
|
||||
if (productTypeCapabilityService == null) {
|
||||
System.out.println("服务未注入,跳过测试(可能数据库未迁移)");
|
||||
return;
|
||||
}
|
||||
|
||||
// 视频类不允许重复购买
|
||||
assertFalse(productTypeCapabilityService.allowDuplicatePurchase("VLOG_VIDEO"));
|
||||
|
||||
// 打印类允许重复购买
|
||||
assertTrue(productTypeCapabilityService.allowDuplicatePurchase("PHOTO_PRINT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPricingMode() {
|
||||
if (productTypeCapabilityService == null) {
|
||||
System.out.println("服务未注入,跳过测试(可能数据库未迁移)");
|
||||
return;
|
||||
}
|
||||
|
||||
// 视频类固定价格
|
||||
assertEquals(PricingMode.FIXED, productTypeCapabilityService.getPricingMode("VLOG_VIDEO"));
|
||||
|
||||
// 打印类基于数量
|
||||
assertEquals(PricingMode.QUANTITY_BASED, productTypeCapabilityService.getPricingMode("PHOTO_PRINT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCapability_NotFound_ShouldReturnDefault() {
|
||||
if (productTypeCapabilityService == null) {
|
||||
System.out.println("服务未注入,跳过测试(可能数据库未迁移)");
|
||||
return;
|
||||
}
|
||||
|
||||
ProductTypeCapability capability = productTypeCapabilityService.getCapability("NOT_EXIST_TYPE");
|
||||
|
||||
// 应该返回默认配置而不是 null
|
||||
assertNotNull(capability);
|
||||
assertEquals("NOT_EXIST_TYPE", capability.getProductType());
|
||||
assertEquals("景区商品", capability.getDisplayName());
|
||||
assertEquals(PricingMode.FIXED, capability.getPricingModeEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCapability_NullOrEmpty_ShouldReturnDefault() {
|
||||
if (productTypeCapabilityService == null) {
|
||||
System.out.println("服务未注入,跳过测试(可能数据库未迁移)");
|
||||
return;
|
||||
}
|
||||
|
||||
ProductTypeCapability capability1 = productTypeCapabilityService.getCapability(null);
|
||||
assertNotNull(capability1);
|
||||
assertEquals("景区商品", capability1.getDisplayName());
|
||||
|
||||
ProductTypeCapability capability2 = productTypeCapabilityService.getCapability("");
|
||||
assertNotNull(capability2);
|
||||
assertEquals("景区商品", capability2.getDisplayName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user