fix(firstleg): persist pricing conversion metadata

This commit is contained in:
2026-08-29 11:48:19 +08:00
parent 66816d5341
commit 0605c32829
10 changed files with 77 additions and 20 deletions
@@ -85,6 +85,23 @@ class FbaPricingContractTest {
.doesNotContain("format: int64");
}
@Test
@DisplayName("费用快照强制返回实际换算与计费量舍入参数")
void requiresActualConversionAndRoundingMetadata() throws Exception {
String source = new ClassPathResource("openapi/fba-pricing-v1.yaml")
.getContentAsString(StandardCharsets.UTF_8);
Map<String, Object> schemas = map(map(new Yaml().load(source)).get("components"));
Map<String, Object> fee = map(map(schemas.get("schemas")).get("FeeSnapshotResponse"));
assertThat(list(fee.get("required"))).contains(
"conversionFactor", "roundingScale", "roundingMode");
Map<String, Object> properties = map(fee.get("properties"));
assertThat(map(properties.get("conversionFactor")).get("description").toString())
.contains("167", "363");
assertThat(list(map(properties.get("roundingScale")).get("enum"))).containsExactly(6);
assertThat(list(map(properties.get("roundingMode")).get("enum"))).containsExactly("HALF_UP");
}
@Test
@DisplayName("客户规则列表响应锁定数组包络和实体核心字段")
void freezesCustomerRuleVersionListResponse() throws Exception {
@@ -22,15 +22,21 @@ class FbaWarehouseRateEstimatorTest {
assertThat(estimate.unitPrice()).isEqualByComparingTo("12.50");
assertThat(estimate.amount()).isEqualByComparingTo("417.50");
assertThat(estimate.currency()).isEqualTo("CNY");
assertThat(estimate.conversionFactor()).isEqualByComparingTo("167");
assertThat(estimate.roundingScale()).isEqualTo(6);
assertThat(estimate.roundingMode()).isEqualTo("HALF_UP");
}
@Test
void shouldUseGreaterOfVolumeAndWeightConversionForCbmRate() {
var estimate = estimator.estimate(rate("CBM", "880"),
new BigDecimal("363"), new BigDecimal("0.50"));
new BigDecimal("37"), new BigDecimal("0.05"));
assertThat(estimate.quantity()).isEqualByComparingTo("1.000000");
assertThat(estimate.amount()).isEqualByComparingTo("880.00");
assertThat(estimate.quantity()).isEqualByComparingTo("0.101928");
assertThat(estimate.amount()).isEqualByComparingTo("89.70");
assertThat(estimate.conversionFactor()).isEqualByComparingTo("363");
assertThat(estimate.roundingScale()).isEqualTo(6);
assertThat(estimate.roundingMode()).isEqualTo("HALF_UP");
}
@Test
@@ -33,6 +33,9 @@ class RegionWeightTierEstimatorTest {
assertThat(estimate.quantity()).isEqualByComparingTo("101.870000");
assertThat(estimate.unitPrice()).isEqualByComparingTo("11");
assertThat(estimate.amount()).isEqualByComparingTo("1120.57");
assertThat(estimate.conversionFactor()).isEqualByComparingTo("167");
assertThat(estimate.roundingScale()).isEqualTo(6);
assertThat(estimate.roundingMode()).isEqualTo("HALF_UP");
}
@Test
@@ -84,6 +84,9 @@ class FbaPricingServiceTest {
assertThat(response.totalAmount()).isEqualByComparingTo("401.77");
assertThat(response.priceBookVersionId()).isEqualTo(701L);
assertThat(response.pricingTaxMode()).isEqualTo("TAX_INCLUDED");
assertThat(response.conversionFactor()).isEqualByComparingTo("167");
assertThat(response.roundingScale()).isEqualTo(6);
assertThat(response.roundingMode()).isEqualTo("HALF_UP");
assertThat(response.nextProcessStatus()).isEqualTo("FEE_CONFIRMING");
ArgumentCaptor<InboundFeeEntity> fee = ArgumentCaptor.forClass(InboundFeeEntity.class);
verify(repository).insertFee(fee.capture());
@@ -92,6 +95,9 @@ class FbaPricingServiceTest {
assertThat(fee.getValue().getChargeRuleId()).isNull();
assertThat(fee.getValue().getCarrierId()).isNull();
assertThat(fee.getValue().getCustomerId()).isEqualTo(11L);
assertThat(fee.getValue().getConversionFactor()).isEqualByComparingTo("167");
assertThat(fee.getValue().getRoundingScale()).isEqualTo(6);
assertThat(fee.getValue().getRoundingMode()).isEqualTo("HALF_UP");
}
@Test
@@ -125,6 +131,9 @@ class FbaPricingServiceTest {
assertThat(response.convertedQuantity()).isEqualByComparingTo("1.0001");
assertThat(response.chargeableQuantity()).isEqualByComparingTo("1.0001");
assertThat(response.totalAmount()).isEqualByComparingTo("100.01");
assertThat(response.conversionFactor()).isEqualByComparingTo("363");
assertThat(response.roundingScale()).isEqualTo(6);
assertThat(response.roundingMode()).isEqualTo("HALF_UP");
}
@Test
@@ -464,7 +473,8 @@ class FbaPricingServiceTest {
rate.setAdditionalFee(new BigDecimal(additional)); rate.setEffectiveFrom(NOW.minusDays(1));
return new ActivePriceBookEstimator.Estimate(701L, "MATSON_TRUCK", PriceModel.FBA_WAREHOUSE_RATE,
PricingTaxMode.TAX_INCLUDED, rate, new BigDecimal(quantity), unit,
new BigDecimal(price), new BigDecimal(amount), "USD");
new BigDecimal(price), new BigDecimal(amount), "USD",
"KG".equals(unit) ? new BigDecimal("167") : new BigDecimal("363"), 6, "HALF_UP");
}
private InboundPricingIdempotencyEntity completed(String operation, long feeId) {