优化
This commit is contained in:
@@ -2,6 +2,7 @@ package com.baiyue.order.service;
|
||||
|
||||
import com.baiyue.common.core.api.ApiResponse;
|
||||
import com.baiyue.order.client.FirstlegInboundClient;
|
||||
import com.baiyue.order.client.FirstlegPricingClient;
|
||||
import com.baiyue.order.entity.OutboxEventEntity;
|
||||
import com.baiyue.order.repository.OrderRepository;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -130,7 +131,7 @@ class OrderInboundOutboxPublisherTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void declarationUpdateEventIsDeliveredByVersionedContract() {
|
||||
void ordinaryDeclarationUpdateDoesNotInvalidatePricing() {
|
||||
String payload = "{\"schemaVersion\":1,\"eventId\":\"evt-1\",\"tenantId\":11,"
|
||||
+ "\"orderId\":21,\"orderNo\":\"ORD-21\",\"inboundCode\":\"RK-21\","
|
||||
+ "\"version\":4,\"operatorId\":7,\"channelCode\":\"SEA\","
|
||||
@@ -145,6 +146,29 @@ class OrderInboundOutboxPublisherTest {
|
||||
&& "SEA".equals(command.channelCode()) && "RK-21".equals(command.inboundCode())));
|
||||
verify(fixture.repository).markOutboxPublished(eq(11L), eq(41L), any(LocalDateTime.class));
|
||||
verify(fixture.client, never()).create(any(), any());
|
||||
verify(fixture.pricingClient, never()).applyOrderChannelChange(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void channelChangeAppliesPricingInvalidationBySameOrderVersionBeforeDelivery() {
|
||||
String payload = "{\"schemaVersion\":1,\"eventId\":\"evt-2\",\"tenantId\":11,"
|
||||
+ "\"orderId\":21,\"orderNo\":\"ORD-21\",\"inboundCode\":\"RK-21\","
|
||||
+ "\"version\":4,\"operatorId\":7,\"channelCode\":\"SEA\","
|
||||
+ "\"channelName\":\"海运\",\"channelChanged\":true,\"cargoes\":[],"
|
||||
+ "\"changes\":[{\"field\":\"channelCode\",\"beforeValue\":\"OLD\",\"afterValue\":\"SEA\"}]}";
|
||||
Fixture fixture = fixture(event("ORDER_DECLARATION_UPDATED_V1", 11L, 21L, payload));
|
||||
when(fixture.pricingClient.applyOrderChannelChange(eq("internal-token"), any())).thenReturn(ApiResponse.success(
|
||||
new FirstlegPricingClient.OrderChannelChangeResponse(
|
||||
51L, 21L, 4L, "SEA", 61L, "UNPRICED", true, 71L)));
|
||||
when(fixture.client.updateDeclaration(eq("internal-token"), any())).thenReturn(ApiResponse.success(null));
|
||||
|
||||
fixture.publisher.publishApprovedOrders();
|
||||
|
||||
verify(fixture.pricingClient).applyOrderChannelChange(eq("internal-token"),
|
||||
org.mockito.ArgumentMatchers.argThat(command -> command.orderVersion() == 4L
|
||||
&& command.orderId() == 21L && "SEA".equals(command.channelCode())));
|
||||
verify(fixture.client).updateDeclaration(eq("internal-token"), any());
|
||||
verify(fixture.repository).markOutboxPublished(eq(11L), eq(41L), any(LocalDateTime.class));
|
||||
}
|
||||
|
||||
private Fixture fixture(OutboxEventEntity event) {
|
||||
@@ -154,6 +178,7 @@ class OrderInboundOutboxPublisherTest {
|
||||
private Fixture fixture(OutboxEventEntity event, String authoritativeTaxMode) {
|
||||
OrderRepository repository = mock(OrderRepository.class);
|
||||
FirstlegInboundClient client = mock(FirstlegInboundClient.class);
|
||||
FirstlegPricingClient pricingClient = mock(FirstlegPricingClient.class);
|
||||
when(repository.pendingInboundEvents(50)).thenReturn(List.of(event));
|
||||
if (event.getTenantId() != null && event.getAggregateId() != null) {
|
||||
var order = new com.baiyue.order.entity.OrderEntity();
|
||||
@@ -165,6 +190,8 @@ class OrderInboundOutboxPublisherTest {
|
||||
order.setReceivingWarehouseId(31L);
|
||||
order.setReceivingWarehouseName("测试仓");
|
||||
order.setDestinationType("OVERSEAS");
|
||||
order.setDestinationWarehouseId(41L);
|
||||
order.setAmazonWarehouseCode("ONT8");
|
||||
order.setTransportMode("SEA");
|
||||
order.setTaxMode(authoritativeTaxMode);
|
||||
order.setPricingTaxMode("TAX_EXCLUDED");
|
||||
@@ -179,9 +206,10 @@ class OrderInboundOutboxPublisherTest {
|
||||
OrderInboundOutboxPublisher publisher = new OrderInboundOutboxPublisher();
|
||||
ReflectionTestUtils.setField(publisher, "repository", repository);
|
||||
ReflectionTestUtils.setField(publisher, "client", client);
|
||||
ReflectionTestUtils.setField(publisher, "pricingClient", pricingClient);
|
||||
ReflectionTestUtils.setField(publisher, "json", new ObjectMapper());
|
||||
ReflectionTestUtils.setField(publisher, "internalToken", "internal-token");
|
||||
return new Fixture(publisher, repository, client);
|
||||
return new Fixture(publisher, repository, client, pricingClient);
|
||||
}
|
||||
|
||||
private OutboxEventEntity event(String eventType, Long tenantId, Long aggregateId, String payload) {
|
||||
@@ -209,6 +237,6 @@ class OrderInboundOutboxPublisherTest {
|
||||
}
|
||||
|
||||
private record Fixture(OrderInboundOutboxPublisher publisher, OrderRepository repository,
|
||||
FirstlegInboundClient client) {
|
||||
FirstlegInboundClient client, FirstlegPricingClient pricingClient) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user