fix: support manual FBA quote fallback
This commit is contained in:
@@ -5,6 +5,7 @@ import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.firstleg.domain.PriceModel;
|
||||
import com.baiyue.firstleg.domain.PricingTaxMode;
|
||||
import com.baiyue.firstleg.dto.FbaPricingDtos.FeeSnapshotResponse;
|
||||
import com.baiyue.firstleg.dto.FbaPricingDtos.ManualQuoteRequest;
|
||||
import com.baiyue.firstleg.entity.CarrierFbaRateEntity;
|
||||
import com.baiyue.firstleg.entity.InboundFeeEntity;
|
||||
import com.baiyue.firstleg.entity.InboundFeeItemEntity;
|
||||
@@ -365,6 +366,56 @@ class FbaPricingServiceTest {
|
||||
verify(repository, never()).insertFee(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("FBA价格未命中时按人工单价生成零附加费头程费用")
|
||||
void createsManualQuoteWhenFbaRateIsMissing() {
|
||||
readyRepository();
|
||||
InboundPricingEntity inbound = inbound("62.500", "0.3840");
|
||||
InboundMeasurementEntity measurement = new InboundMeasurementEntity();
|
||||
measurement.setId(301L);
|
||||
InboundMeasurementItemEntity item = new InboundMeasurementItemEntity();
|
||||
when(repository.findInbound(TENANT, INBOUND)).thenReturn(inbound);
|
||||
when(measurementRepository.findLatestMeasurement(TENANT, INBOUND)).thenReturn(measurement);
|
||||
when(measurementRepository.listItems(TENANT, 301L)).thenReturn(List.of(item));
|
||||
when(priceBookEstimator.estimate(anyLong(), any())).thenThrow(
|
||||
new BizException(ResultCode.NOT_FOUND, "当前条件没有匹配价格"));
|
||||
|
||||
FeeSnapshotResponse result = service.manualQuote(TENANT, OPERATOR, INBOUND,
|
||||
new ManualQuoteRequest(new BigDecimal("62.500"), new BigDecimal("0.3840"),
|
||||
new BigDecimal("12.2000"), "FBA价格未维护"), "manual-1");
|
||||
|
||||
assertThat(result.rateCode()).isEqualTo("MANUAL_QUOTE");
|
||||
assertThat(result.unitPrice()).isEqualByComparingTo("12.2000");
|
||||
assertThat(result.chargeableQuantity()).isEqualByComparingTo("64.128000");
|
||||
assertThat(result.additionalAmount()).isEqualByComparingTo("0.00");
|
||||
assertThat(result.totalAmount()).isEqualByComparingTo("782.36");
|
||||
assertThat(result.carrierRateId()).isNull();
|
||||
ArgumentCaptor<InboundFeeItemEntity> feeItem = ArgumentCaptor.forClass(InboundFeeItemEntity.class);
|
||||
verify(repository).insertItem(feeItem.capture());
|
||||
assertThat(feeItem.getValue().getAutomaticFlag()).isFalse();
|
||||
assertThat(feeItem.getValue().getRemark()).isEqualTo("FBA价格未维护");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("已有匹配价格时拒绝绕过价格表创建人工报价")
|
||||
void rejectsManualQuoteWhenRateExists() {
|
||||
readyRepository();
|
||||
InboundPricingEntity inbound = inbound("62.500", "0.3840");
|
||||
InboundMeasurementEntity measurement = new InboundMeasurementEntity();
|
||||
measurement.setId(301L);
|
||||
when(repository.findInbound(TENANT, INBOUND)).thenReturn(inbound);
|
||||
when(measurementRepository.findLatestMeasurement(TENANT, INBOUND)).thenReturn(measurement);
|
||||
when(measurementRepository.listItems(TENANT, 301L)).thenReturn(List.of(new InboundMeasurementItemEntity()));
|
||||
when(priceBookEstimator.estimate(anyLong(), any())).thenReturn(
|
||||
estimate("KG", "64.128", "12.2", "782.36", "0"));
|
||||
|
||||
assertThatThrownBy(() -> service.manualQuote(TENANT, OPERATOR, INBOUND,
|
||||
new ManualQuoteRequest(new BigDecimal("62.500"), new BigDecimal("0.3840"),
|
||||
new BigDecimal("12.2000"), "人工价格"), "manual-existing"))
|
||||
.isInstanceOf(BizException.class).hasMessageContaining("已有匹配价格");
|
||||
verify(repository, never()).insertFee(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("同一幂等键重复试算直接返回原费用快照")
|
||||
void returnsOriginalSnapshotForRepeatedCalculation() {
|
||||
|
||||
Reference in New Issue
Block a user