You've already forked FrameTour-BE
test(facebody): 更新人脸识别适配器集成测试
Some checks failed
ZhenTu-BE/pipeline/head There was a failure building this commit
Some checks failed
ZhenTu-BE/pipeline/head There was a failure building this commit
- 重命名 AliFaceBodyAdapterTest 为 AliFaceBodyAdapterIT - 重命名 BceFaceBodyAdapterTest 为 B
This commit is contained in:
@@ -10,7 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class AliFaceBodyAdapterTest {
|
public class AliFaceBodyAdapterIT {
|
||||||
private AliFaceBodyAdapter getAdapter() {
|
private AliFaceBodyAdapter getAdapter() {
|
||||||
AliFaceBodyAdapter adapter = new AliFaceBodyAdapter();
|
AliFaceBodyAdapter adapter = new AliFaceBodyAdapter();
|
||||||
AliFaceBodyConfig config = new AliFaceBodyConfig();
|
AliFaceBodyConfig config = new AliFaceBodyConfig();
|
||||||
@@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class BceFaceBodyAdapterTest {
|
public class BceFaceBodyAdapterIT {
|
||||||
@Autowired
|
@Autowired
|
||||||
private FaceSampleMapper faceSampleMapper;
|
private FaceSampleMapper faceSampleMapper;
|
||||||
|
|
||||||
@@ -87,7 +87,6 @@ class CouponServiceImplTest {
|
|||||||
PriceCouponConfig coupon = baseCoupon();
|
PriceCouponConfig coupon = baseCoupon();
|
||||||
coupon.setClaimedQuantity(9);
|
coupon.setClaimedQuantity(9);
|
||||||
when(couponConfigMapper.selectById(1L)).thenReturn(coupon);
|
when(couponConfigMapper.selectById(1L)).thenReturn(coupon);
|
||||||
when(couponClaimRecordMapper.countUserCouponClaims(10L, 1L)).thenReturn(0);
|
|
||||||
when(couponClaimRecordMapper.insert(any())).thenReturn(1);
|
when(couponClaimRecordMapper.insert(any())).thenReturn(1);
|
||||||
when(couponConfigMapper.incrementClaimedQuantityIfAvailable(1L)).thenReturn(0);
|
when(couponConfigMapper.incrementClaimedQuantityIfAvailable(1L)).thenReturn(0);
|
||||||
|
|
||||||
@@ -116,6 +115,7 @@ class CouponServiceImplTest {
|
|||||||
coupon.setValidUntil(new Date(now.getTime() + oneDayMillis));
|
coupon.setValidUntil(new Date(now.getTime() + oneDayMillis));
|
||||||
coupon.setTotalQuantity(100);
|
coupon.setTotalQuantity(100);
|
||||||
coupon.setClaimedQuantity(0);
|
coupon.setClaimedQuantity(0);
|
||||||
|
coupon.setDeleted(0);
|
||||||
return coupon;
|
return coupon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package com.ycwl.basic.pricing.service;
|
package com.ycwl.basic.pricing.service;
|
||||||
|
|
||||||
|
import com.ycwl.basic.pricing.dto.DiscountCombinationResult;
|
||||||
import com.ycwl.basic.pricing.dto.PriceCalculationRequest;
|
import com.ycwl.basic.pricing.dto.PriceCalculationRequest;
|
||||||
import com.ycwl.basic.pricing.dto.PriceCalculationResult;
|
import com.ycwl.basic.pricing.dto.PriceCalculationResult;
|
||||||
import com.ycwl.basic.pricing.dto.ProductItem;
|
import com.ycwl.basic.pricing.dto.ProductItem;
|
||||||
import com.ycwl.basic.pricing.dto.ProductPriceInfo;
|
|
||||||
import com.ycwl.basic.pricing.entity.PriceProductConfig;
|
import com.ycwl.basic.pricing.entity.PriceProductConfig;
|
||||||
import com.ycwl.basic.pricing.enums.ProductType;
|
import com.ycwl.basic.pricing.enums.ProductType;
|
||||||
import com.ycwl.basic.pricing.service.impl.PriceCalculationServiceImpl;
|
import com.ycwl.basic.pricing.service.impl.PriceCalculationServiceImpl;
|
||||||
|
import com.ycwl.basic.product.capability.PricingMode;
|
||||||
|
import com.ycwl.basic.product.capability.ProductTypeCapability;
|
||||||
|
import com.ycwl.basic.product.service.IProductTypeCapabilityService;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -50,12 +53,18 @@ class NewPhotoPrintSkuTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private IVoucherService voucherService;
|
private IVoucherService voucherService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private IProductTypeCapabilityService productTypeCapabilityService;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private PriceCalculationServiceImpl priceCalculationService;
|
private PriceCalculationServiceImpl priceCalculationService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
// 初始化设置(如有需要)
|
ProductTypeCapability capability = new ProductTypeCapability();
|
||||||
|
capability.setPricingModeEnum(PricingMode.QUANTITY_BASED);
|
||||||
|
lenient().when(productTypeCapabilityService.getCapability(anyString())).thenReturn(capability);
|
||||||
|
lenient().when(discountDetectionService.previewOptimalCombination(any())).thenReturn(buildEmptyDiscountResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,9 +107,9 @@ class NewPhotoPrintSkuTest {
|
|||||||
config.setOriginalPrice(originalPrice);
|
config.setOriginalPrice(originalPrice);
|
||||||
|
|
||||||
// Mock 服务行为
|
// Mock 服务行为
|
||||||
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt()))
|
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt(), isNull()))
|
||||||
.thenReturn(null); // 不使用阶梯定价
|
.thenReturn(null); // 不使用阶梯定价
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default"))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default", null))
|
||||||
.thenReturn(config);
|
.thenReturn(config);
|
||||||
|
|
||||||
// 构建请求
|
// 构建请求
|
||||||
@@ -124,7 +133,7 @@ class NewPhotoPrintSkuTest {
|
|||||||
|
|
||||||
// 验证服务调用
|
// 验证服务调用
|
||||||
verify(productConfigService, atLeastOnce())
|
verify(productConfigService, atLeastOnce())
|
||||||
.getProductConfig("PHOTO_PRINT_MU", "default");
|
.getProductConfig("PHOTO_PRINT_MU", "default", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,9 +154,9 @@ class NewPhotoPrintSkuTest {
|
|||||||
config.setOriginalPrice(originalPrice);
|
config.setOriginalPrice(originalPrice);
|
||||||
|
|
||||||
// Mock 服务行为
|
// Mock 服务行为
|
||||||
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt()))
|
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt(), isNull()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_FX", "default"))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_FX", "default", null))
|
||||||
.thenReturn(config);
|
.thenReturn(config);
|
||||||
|
|
||||||
// 构建请求
|
// 构建请求
|
||||||
@@ -170,7 +179,7 @@ class NewPhotoPrintSkuTest {
|
|||||||
.compareTo(result.getFinalAmount())); // 5.00 * 15 = 75.00
|
.compareTo(result.getFinalAmount())); // 5.00 * 15 = 75.00
|
||||||
|
|
||||||
verify(productConfigService, atLeastOnce())
|
verify(productConfigService, atLeastOnce())
|
||||||
.getProductConfig("PHOTO_PRINT_FX", "default");
|
.getProductConfig("PHOTO_PRINT_FX", "default", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,10 +196,11 @@ class NewPhotoPrintSkuTest {
|
|||||||
scenicConfig.setProductType("PHOTO_PRINT_MU");
|
scenicConfig.setProductType("PHOTO_PRINT_MU");
|
||||||
scenicConfig.setProductId(scenicId);
|
scenicConfig.setProductId(scenicId);
|
||||||
scenicConfig.setBasePrice(scenicPrice);
|
scenicConfig.setBasePrice(scenicPrice);
|
||||||
|
scenicConfig.setOriginalPrice(scenicPrice);
|
||||||
|
|
||||||
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt()))
|
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt(), isNull()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", scenicId))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", scenicId, null))
|
||||||
.thenReturn(scenicConfig);
|
.thenReturn(scenicConfig);
|
||||||
|
|
||||||
ProductItem item = new ProductItem();
|
ProductItem item = new ProductItem();
|
||||||
@@ -210,7 +220,7 @@ class NewPhotoPrintSkuTest {
|
|||||||
assertEquals(0, scenicPrice.multiply(BigDecimal.valueOf(quantity))
|
assertEquals(0, scenicPrice.multiply(BigDecimal.valueOf(quantity))
|
||||||
.compareTo(result.getFinalAmount()));
|
.compareTo(result.getFinalAmount()));
|
||||||
|
|
||||||
verify(productConfigService).getProductConfig("PHOTO_PRINT_MU", scenicId);
|
verify(productConfigService).getProductConfig("PHOTO_PRINT_MU", scenicId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,14 +237,15 @@ class NewPhotoPrintSkuTest {
|
|||||||
defaultConfig.setProductType("PHOTO_PRINT_MU");
|
defaultConfig.setProductType("PHOTO_PRINT_MU");
|
||||||
defaultConfig.setProductId("default");
|
defaultConfig.setProductId("default");
|
||||||
defaultConfig.setBasePrice(defaultPrice);
|
defaultConfig.setBasePrice(defaultPrice);
|
||||||
|
defaultConfig.setOriginalPrice(defaultPrice);
|
||||||
|
|
||||||
// 景区配置不存在,抛出异常
|
// 景区配置不存在,抛出异常
|
||||||
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt()))
|
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt(), isNull()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", scenicId))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", scenicId, null))
|
||||||
.thenThrow(new RuntimeException("Not found"));
|
.thenThrow(new RuntimeException("Not found"));
|
||||||
// 回退到 default 配置
|
// 回退到 default 配置
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default"))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default", null))
|
||||||
.thenReturn(defaultConfig);
|
.thenReturn(defaultConfig);
|
||||||
|
|
||||||
ProductItem item = new ProductItem();
|
ProductItem item = new ProductItem();
|
||||||
@@ -255,9 +266,9 @@ class NewPhotoPrintSkuTest {
|
|||||||
.compareTo(result.getFinalAmount()));
|
.compareTo(result.getFinalAmount()));
|
||||||
|
|
||||||
// 验证回退逻辑被调用
|
// 验证回退逻辑被调用
|
||||||
verify(productConfigService).getProductConfig("PHOTO_PRINT_MU", scenicId);
|
verify(productConfigService).getProductConfig("PHOTO_PRINT_MU", scenicId, null);
|
||||||
verify(productConfigService, atLeastOnce())
|
verify(productConfigService, atLeastOnce())
|
||||||
.getProductConfig("PHOTO_PRINT_MU", "default");
|
.getProductConfig("PHOTO_PRINT_MU", "default", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -275,13 +286,13 @@ class NewPhotoPrintSkuTest {
|
|||||||
PriceProductConfig photoPrintMuConfig = createConfig("PHOTO_PRINT_MU", unitPrice);
|
PriceProductConfig photoPrintMuConfig = createConfig("PHOTO_PRINT_MU", unitPrice);
|
||||||
PriceProductConfig photoPrintFxConfig = createConfig("PHOTO_PRINT_FX", unitPrice);
|
PriceProductConfig photoPrintFxConfig = createConfig("PHOTO_PRINT_FX", unitPrice);
|
||||||
|
|
||||||
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt()))
|
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt(), isNull()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT", "default"))
|
when(productConfigService.getProductConfig("PHOTO_PRINT", "default", null))
|
||||||
.thenReturn(photoPrintConfig);
|
.thenReturn(photoPrintConfig);
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default"))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default", null))
|
||||||
.thenReturn(photoPrintMuConfig);
|
.thenReturn(photoPrintMuConfig);
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_FX", "default"))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_FX", "default", null))
|
||||||
.thenReturn(photoPrintFxConfig);
|
.thenReturn(photoPrintFxConfig);
|
||||||
|
|
||||||
// 测试 PHOTO_PRINT
|
// 测试 PHOTO_PRINT
|
||||||
@@ -309,10 +320,11 @@ class NewPhotoPrintSkuTest {
|
|||||||
config.setProductType("PHOTO_PRINT_MU");
|
config.setProductType("PHOTO_PRINT_MU");
|
||||||
config.setProductId("default");
|
config.setProductId("default");
|
||||||
config.setBasePrice(unitPrice);
|
config.setBasePrice(unitPrice);
|
||||||
|
config.setOriginalPrice(unitPrice);
|
||||||
|
|
||||||
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt()))
|
when(productConfigService.getTierConfig(anyString(), anyString(), anyInt(), isNull()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default"))
|
when(productConfigService.getProductConfig("PHOTO_PRINT_MU", "default", null))
|
||||||
.thenReturn(config);
|
.thenReturn(config);
|
||||||
|
|
||||||
// 测试数量为0
|
// 测试数量为0
|
||||||
@@ -334,9 +346,19 @@ class NewPhotoPrintSkuTest {
|
|||||||
config.setProductType(productType);
|
config.setProductType(productType);
|
||||||
config.setProductId("default");
|
config.setProductId("default");
|
||||||
config.setBasePrice(basePrice);
|
config.setBasePrice(basePrice);
|
||||||
|
config.setOriginalPrice(basePrice);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DiscountCombinationResult buildEmptyDiscountResult() {
|
||||||
|
DiscountCombinationResult result = new DiscountCombinationResult();
|
||||||
|
result.setSuccess(true);
|
||||||
|
result.setDiscountDetails(Collections.emptyList());
|
||||||
|
result.setAppliedDiscounts(Collections.emptyList());
|
||||||
|
result.setAvailableDiscounts(Collections.emptyList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行价格计算的辅助方法
|
* 执行价格计算的辅助方法
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class ReusableVoucherServiceTest {
|
|||||||
// Then
|
// Then
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertFalse(result.getAvailable());
|
assertFalse(result.getAvailable());
|
||||||
assertEquals("券码已用完", result.getUnavailableReason());
|
assertEquals("券码使用次数已达上限", result.getUnavailableReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -5,14 +5,9 @@ import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReqV2;
|
|||||||
import com.ycwl.basic.pricing.entity.PriceVoucherBatchConfig;
|
import com.ycwl.basic.pricing.entity.PriceVoucherBatchConfig;
|
||||||
import com.ycwl.basic.pricing.enums.ProductType;
|
import com.ycwl.basic.pricing.enums.ProductType;
|
||||||
import com.ycwl.basic.pricing.enums.VoucherDiscountType;
|
import com.ycwl.basic.pricing.enums.VoucherDiscountType;
|
||||||
import com.ycwl.basic.pricing.service.impl.VoucherServiceImpl;
|
|
||||||
import com.ycwl.basic.pricing.service.impl.VoucherBatchServiceImpl;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -24,22 +19,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
/**
|
/**
|
||||||
* 券码时间范围功能单元测试
|
* 券码时间范围功能单元测试
|
||||||
*/
|
*/
|
||||||
@SpringBootTest
|
|
||||||
@ActiveProfiles("test")
|
|
||||||
@Transactional
|
|
||||||
public class VoucherTimeRangeTest {
|
public class VoucherTimeRangeTest {
|
||||||
|
|
||||||
private VoucherServiceImpl voucherService;
|
|
||||||
private VoucherBatchServiceImpl voucherBatchService;
|
|
||||||
|
|
||||||
private Long testScenicId = 1001L;
|
private Long testScenicId = 1001L;
|
||||||
private Long testBrokerId = 2001L;
|
private Long testBrokerId = 2001L;
|
||||||
private Long testFaceId = 3001L;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
// 这里应该注入真实的服务实例,或者使用Mock
|
|
||||||
// 为了演示,这里只是创建测试结构
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
package com.ycwl.basic.pricing.service.impl;
|
||||||
|
|
||||||
|
import com.ycwl.basic.order.service.IOrderService;
|
||||||
|
import com.ycwl.basic.pricing.dto.OnePriceInfo;
|
||||||
|
import com.ycwl.basic.pricing.dto.ProductItem;
|
||||||
|
import com.ycwl.basic.pricing.dto.UpgradeCheckRequest;
|
||||||
|
import com.ycwl.basic.pricing.dto.UpgradeCheckResult;
|
||||||
|
import com.ycwl.basic.pricing.entity.PriceBundleConfig;
|
||||||
|
import com.ycwl.basic.pricing.entity.PriceProductConfig;
|
||||||
|
import com.ycwl.basic.pricing.enums.ProductType;
|
||||||
|
import com.ycwl.basic.pricing.service.ICouponService;
|
||||||
|
import com.ycwl.basic.pricing.service.IDiscountDetectionService;
|
||||||
|
import com.ycwl.basic.pricing.service.IOnePricePurchaseService;
|
||||||
|
import com.ycwl.basic.pricing.service.IPriceBundleService;
|
||||||
|
import com.ycwl.basic.pricing.service.IProductConfigService;
|
||||||
|
import com.ycwl.basic.pricing.service.IVoucherService;
|
||||||
|
import com.ycwl.basic.product.service.IProductTypeCapabilityService;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class PriceCalculationServiceImplUpgradeCheckTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private IProductConfigService productConfigService;
|
||||||
|
@Mock
|
||||||
|
private ICouponService couponService;
|
||||||
|
@Mock
|
||||||
|
private IPriceBundleService bundleService;
|
||||||
|
@Mock
|
||||||
|
private IOnePricePurchaseService onePricePurchaseService;
|
||||||
|
@Mock
|
||||||
|
private IDiscountDetectionService discountDetectionService;
|
||||||
|
@Mock
|
||||||
|
private IVoucherService voucherService;
|
||||||
|
@Mock
|
||||||
|
private IProductTypeCapabilityService productTypeCapabilityService;
|
||||||
|
@Mock
|
||||||
|
private IOrderService orderService;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private PriceCalculationServiceImpl priceCalculationService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldSelectOnePriceWhenUpgradeTypeSpecified() {
|
||||||
|
mockProductConfig(new BigDecimal("100.00"));
|
||||||
|
when(onePricePurchaseService.getOnePriceInfo(eq(1L), any()))
|
||||||
|
.thenReturn(buildOnePriceInfo(new BigDecimal("80.00")));
|
||||||
|
when(bundleService.getCheapestBundleConfig(any()))
|
||||||
|
.thenReturn(buildBundleConfig(new BigDecimal("50.00")));
|
||||||
|
|
||||||
|
UpgradeCheckRequest request = buildRequest("ONE_PRICE");
|
||||||
|
UpgradeCheckResult result = priceCalculationService.checkUpgrade(request);
|
||||||
|
|
||||||
|
assertEquals("ONE_PRICE", result.getBestUpgradeType());
|
||||||
|
assertEquals(new BigDecimal("80.00"), result.getBestPayableAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldSelectCheapestBundleWhenUpgradeTypeMissing() {
|
||||||
|
mockProductConfig(new BigDecimal("100.00"));
|
||||||
|
when(onePricePurchaseService.getOnePriceInfo(eq(1L), any()))
|
||||||
|
.thenReturn(buildOnePriceInfo(new BigDecimal("80.00")));
|
||||||
|
when(bundleService.getCheapestBundleConfig(any()))
|
||||||
|
.thenReturn(buildBundleConfig(new BigDecimal("70.00")));
|
||||||
|
|
||||||
|
UpgradeCheckRequest request = buildRequest(null);
|
||||||
|
UpgradeCheckResult result = priceCalculationService.checkUpgrade(request);
|
||||||
|
|
||||||
|
assertEquals("BUNDLE_DISCOUNT", result.getBestUpgradeType());
|
||||||
|
assertEquals(new BigDecimal("70.00"), result.getBestPayableAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnNullBestWhenOnePriceNotApplicable() {
|
||||||
|
mockProductConfig(new BigDecimal("100.00"));
|
||||||
|
when(onePricePurchaseService.getOnePriceInfo(eq(1L), any()))
|
||||||
|
.thenReturn(buildOnePriceInfo(new BigDecimal("120.00")));
|
||||||
|
when(bundleService.getCheapestBundleConfig(any()))
|
||||||
|
.thenReturn(buildBundleConfig(new BigDecimal("70.00")));
|
||||||
|
|
||||||
|
UpgradeCheckRequest request = buildRequest("ONE_PRICE");
|
||||||
|
UpgradeCheckResult result = priceCalculationService.checkUpgrade(request);
|
||||||
|
|
||||||
|
assertNull(result.getBestUpgradeType());
|
||||||
|
assertNull(result.getBestPayableAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mockProductConfig(BigDecimal basePrice) {
|
||||||
|
PriceProductConfig config = new PriceProductConfig();
|
||||||
|
config.setProductType(ProductType.PHOTO_SET.getCode());
|
||||||
|
config.setProductId("p1");
|
||||||
|
config.setBasePrice(basePrice);
|
||||||
|
config.setOriginalPrice(basePrice);
|
||||||
|
config.setProductName("照片集");
|
||||||
|
|
||||||
|
when(productConfigService.getProductConfig(anyString(), anyString(), anyLong()))
|
||||||
|
.thenReturn(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UpgradeCheckRequest buildRequest(String upgradeType) {
|
||||||
|
UpgradeCheckRequest request = new UpgradeCheckRequest();
|
||||||
|
request.setScenicId(1L);
|
||||||
|
request.setFaceId(2L);
|
||||||
|
request.setMemberId(3L);
|
||||||
|
request.setPaidAmount(BigDecimal.ZERO);
|
||||||
|
request.setPurchasedProducts(List.of());
|
||||||
|
request.setIntendingProducts(List.of(buildProductItem()));
|
||||||
|
request.setUpgradeType(upgradeType);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProductItem buildProductItem() {
|
||||||
|
ProductItem item = new ProductItem();
|
||||||
|
item.setProductType(ProductType.PHOTO_SET);
|
||||||
|
item.setProductId("p1");
|
||||||
|
item.setQuantity(1);
|
||||||
|
item.setPurchaseCount(1);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OnePriceInfo buildOnePriceInfo(BigDecimal onePrice) {
|
||||||
|
OnePriceInfo info = new OnePriceInfo();
|
||||||
|
info.setConfigId(10L);
|
||||||
|
info.setConfigName("一口价");
|
||||||
|
info.setScenicId(1L);
|
||||||
|
info.setOnePrice(onePrice);
|
||||||
|
info.setOriginalPrice(onePrice);
|
||||||
|
info.setDescription("一口价测试");
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PriceBundleConfig buildBundleConfig(BigDecimal bundlePrice) {
|
||||||
|
PriceBundleConfig config = new PriceBundleConfig();
|
||||||
|
config.setId(20L);
|
||||||
|
config.setBundleName("打包购买");
|
||||||
|
config.setBundlePrice(bundlePrice);
|
||||||
|
config.setScenicId("1");
|
||||||
|
config.setDescription("打包购买测试");
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class CustomUploadTaskServiceTest {
|
class CustomUploadTaskServiceIT {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void handleAliyunMpsJobComplete() {
|
void handleAliyunMpsJobComplete() {
|
||||||
@@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class FaceCleanerTest {
|
public class FaceCleanerIT {
|
||||||
@Autowired
|
@Autowired
|
||||||
private FaceMapper faceMapper;
|
private FaceMapper faceMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -24,7 +24,7 @@ import java.util.List;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class ScenicStatsTaskTest {
|
public class ScenicStatsTaskIT {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ScenicStatsTask task;
|
private ScenicStatsTask task;
|
||||||
@Autowired
|
@Autowired
|
||||||
Reference in New Issue
Block a user