test(firstleg): lock internal declaration endpoints

This commit is contained in:
2026-09-02 10:45:09 +08:00
parent bb9fb9ffe6
commit 6acb5297e5
2 changed files with 37 additions and 0 deletions
@@ -8,6 +8,7 @@ import com.baiyue.firstleg.service.InboundCartonLabelService;
import com.baiyue.firstleg.service.UnifiedInboundQueryService;
import com.baiyue.firstleg.service.OrderDeclarationSyncService;
import com.baiyue.firstleg.dto.UnifiedInboundQuery;
import com.baiyue.firstleg.dto.OrderDeclarationSync;
import com.baiyue.common.core.api.PageResult;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
@@ -16,6 +17,7 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.util.List;
import java.time.LocalDateTime;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -88,6 +90,26 @@ class InternalInboundOrderReferenceControllerTest {
verify(cartonLabels).getOrCreate(10001L, 88L);
}
@Test
void exposesExactOrderChannelValidationContract() {
var request = new OrderDeclarationSync.ChannelChangeValidationRequest(10001L, 77L, 4L, "MATSON_NEW");
var result = new OrderDeclarationSync.ChannelChangeValidationResponse(77L, 4L, "MATSON_NEW", "WAIT_SPLIT");
when(declarationSync.validateChannelChange(request)).thenReturn(result);
assertThat(controller.validateOrderChannelChange("internal-token", request).data()).isEqualTo(result);
verify(declarationSync).validateChannelChange(request);
}
@Test
void exposesExactDeclarationEventConsumerContract() {
var event = new OrderDeclarationSync.UpdatedEvent(1, "event-4", 10001L, 77L, "FL-77", "RK-77",
4, 9L, LocalDateTime.of(2026, 9, 2, 10, 0), null, null, "MATSON_NEW", "新渠道",
true, List.of(), List.of());
assertThat(controller.updateOrderDeclaration("internal-token", event).successful()).isTrue();
verify(declarationSync).consume(event);
}
private static OrderApprovedInboundCommand approvedCommand(String inboundCode, Long carrierId) {
return new OrderApprovedInboundCommand(
10001L, 77L, "FL-77", inboundCode, 7L, "测试客户", 9L, "义乌仓",
@@ -3,6 +3,9 @@ package com.baiyue.firstleg.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,4 +23,16 @@ class OrderDeclarationSyncMapperContractTest {
.doesNotContain("actual_net_weight", "actual_volume", "fee_status", "SET inbound_code",
"pallet", "box_code", "process_status");
}
@Test
void sqlBaselineKeepsCurrentSnapshotAndPermanentEventLedgerSeparate() throws Exception {
String sql = new ClassPathResource("db/phase2-inbound-schema.sql")
.getContentAsString(StandardCharsets.UTF_8);
assertThat(sql)
.contains("CREATE TABLE IF NOT EXISTS fl_order_declaration_snapshot")
.contains("CREATE TABLE IF NOT EXISTS fl_order_declaration_event")
.contains("PRIMARY KEY (tenant_id, event_id)")
.contains("不覆盖实测事实");
}
}