优化
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
package com.baiyue.warehouse.controller;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class InternalSupplierControllerContractTest {
|
||||
@Test void validatesSupplierByActiveStatusAndCategoryWithoutBookingScope() {
|
||||
assertThat(InternalSupplierController.class.getAnnotation(RequestMapping.class).value())
|
||||
.containsExactly("/internal/warehouse/v1/suppliers");
|
||||
Method get = Arrays.stream(InternalSupplierController.class.getDeclaredMethods())
|
||||
.filter(method -> method.getName().equals("get"))
|
||||
.findFirst().orElseThrow();
|
||||
assertThat(Arrays.stream(get.getParameters()).map(parameter -> parameter.getName()))
|
||||
.containsExactly("token", "supplierId", "requireActive", "category");
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -8,17 +8,18 @@ import java.nio.file.Path;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class SupplierSqlContractTest {
|
||||
@Test void freezesPublicSupplierSchemaAndBookingScope() throws IOException {
|
||||
@Test void freezesPublicSupplierSchemaWithoutBookingScope() throws IOException {
|
||||
try (var stream = getClass().getResourceAsStream("/db/warehouse-supplier.sql")) {
|
||||
assertThat(stream).isNotNull();
|
||||
String sql = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
assertThat(sql).contains("CREATE TABLE IF NOT EXISTS wh_supplier", "tenant_id BIGINT UNSIGNED NOT NULL DEFAULT 0",
|
||||
"chk_wh_supplier_tenant CHECK (tenant_id = 0)",
|
||||
"category='BOOKING' AND scope IN ('DOMESTIC','INTERNATIONAL')", "license_file_id VARCHAR(128)",
|
||||
"license_file_id VARCHAR(128)",
|
||||
"MONTHLY_30','MONTHLY_45','MONTHLY_60','MONTHLY_90','PER_TRANSACTION','IMMEDIATE",
|
||||
"created_by BIGINT UNSIGNED", "updated_by BIGINT UNSIGNED",
|
||||
"supplier_add_column_if_missing", "uk_wh_supplier_name", "idx_wh_supplier_filter",
|
||||
"assert_supplier_schema");
|
||||
assertThat(sql).doesNotContain("scope VARCHAR", "chk_wh_supplier_scope", "DOMESTIC/INTERNATIONAL");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +28,8 @@ class SupplierSqlContractTest {
|
||||
assertThat(sql).contains("CREATE TABLE IF NOT EXISTS wh_supplier", "uk_wh_supplier_name",
|
||||
"idx_wh_supplier_filter", "platform:supplier:list", "platform:supplier:create",
|
||||
"platform:supplier:edit", "platform:supplier:status", "assert_platform_supplier_permissions");
|
||||
String supplierSection = sql.substring(sql.indexOf("-- 平台公共供应商业务档案及权限"));
|
||||
assertThat(supplierSection).doesNotContain("chk_wh_supplier_scope", "订舱分类范围");
|
||||
}
|
||||
|
||||
private static Path resolveUnifiedSql() {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.baiyue.warehouse.service;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.warehouse.dto.SupplierDtos.SaveRequest;
|
||||
import com.baiyue.warehouse.dto.SupplierDtos.PageQuery;
|
||||
import com.baiyue.warehouse.dto.SupplierDtos.StatusRequest;
|
||||
import com.baiyue.warehouse.entity.SupplierEntity;
|
||||
import com.baiyue.warehouse.repository.SupplierRepository;
|
||||
@@ -13,8 +12,8 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -26,7 +25,7 @@ class SupplierServiceTest {
|
||||
private SaveRequest booking;
|
||||
|
||||
@BeforeEach void setUp() {
|
||||
booking = new SaveRequest("测试供应商", "BOOKING", "DOMESTIC", "宁波", "法人", "联系人",
|
||||
booking = new SaveRequest("测试供应商", "BOOKING", "宁波", "法人", "联系人",
|
||||
"13800000000", "supplier@example.com", "地址", "91330000TEST", "192000000000000001",
|
||||
"ACTIVE", "MONTHLY_30", null);
|
||||
}
|
||||
@@ -37,24 +36,6 @@ class SupplierServiceTest {
|
||||
verify(repository).insert(any(SupplierEntity.class));
|
||||
}
|
||||
|
||||
@Test void rejectsScopeForNonBookingSupplier() {
|
||||
SaveRequest customs = new SaveRequest("报关供应商", "CUSTOMS", "DOMESTIC", "宁波", "法人", "联系人",
|
||||
"13800000000", null, null, null, null, "ACTIVE", "PER_TRANSACTION", null);
|
||||
assertThatThrownBy(() -> service.create(101L, customs)).isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("仅适用于订舱供应商");
|
||||
}
|
||||
|
||||
@Test void requiresScopeForBookingSupplier() {
|
||||
SaveRequest missingScope = new SaveRequest("订舱供应商", "BOOKING", null, "宁波", "法人", "联系人",
|
||||
"13800000000", null, null, null, null, "ACTIVE", "PER_TRANSACTION", null);
|
||||
assertThatThrownBy(() -> service.create(101L, missingScope)).isInstanceOf(BizException.class);
|
||||
}
|
||||
|
||||
@Test void rejectsScopeFilterWithoutBookingCategory() {
|
||||
assertThatThrownBy(() -> service.page(new PageQuery(1, 20, "CUSTOMS", "DOMESTIC", null, null, null)))
|
||||
.isInstanceOf(BizException.class).hasMessageContaining("scope仅适用于订舱供应商");
|
||||
}
|
||||
|
||||
@Test void repeatedStatusChangeIsIdempotent() {
|
||||
SupplierEntity entity = new SupplierEntity(); entity.setId(101L); entity.setTenantId(0L); entity.setStatus("ACTIVE");
|
||||
when(repository.find(0L, 101L)).thenReturn(entity);
|
||||
@@ -64,9 +45,23 @@ class SupplierServiceTest {
|
||||
|
||||
@Test void validatesInternalSupplierSnapshot() {
|
||||
SupplierEntity entity = new SupplierEntity(); entity.setId(101L); entity.setTenantId(0L); entity.setName("测试供应商");
|
||||
entity.setCategory("BOOKING"); entity.setScope("DOMESTIC"); entity.setStatus("ACTIVE");
|
||||
entity.setCategory("BOOKING"); entity.setStatus("ACTIVE");
|
||||
when(repository.find(0L, 101L)).thenReturn(entity);
|
||||
var snapshot = service.internalSnapshot(101L, true, "BOOKING", "DOMESTIC");
|
||||
var snapshot = service.internalSnapshot(101L, true, "BOOKING");
|
||||
org.assertj.core.api.Assertions.assertThat(snapshot.supplierId()).isEqualTo(101L);
|
||||
org.assertj.core.api.Assertions.assertThat(snapshot.category()).isEqualTo("BOOKING");
|
||||
org.assertj.core.api.Assertions.assertThat(snapshot.status()).isEqualTo("ACTIVE");
|
||||
}
|
||||
|
||||
@Test void internalSnapshotRequiresActiveSupplierAndMatchingCategory() {
|
||||
SupplierEntity inactive = new SupplierEntity(); inactive.setId(101L); inactive.setTenantId(0L);
|
||||
inactive.setName("停用订舱供应商"); inactive.setCategory("BOOKING"); inactive.setStatus("INACTIVE");
|
||||
when(repository.find(0L, 101L)).thenReturn(inactive);
|
||||
assertThatThrownBy(() -> service.internalSnapshot(101L, true, "BOOKING"))
|
||||
.isInstanceOf(BizException.class).hasMessageContaining("未启用");
|
||||
|
||||
inactive.setStatus("ACTIVE");
|
||||
assertThatThrownBy(() -> service.internalSnapshot(101L, true, "CUSTOMS"))
|
||||
.isInstanceOf(BizException.class).hasMessageContaining("类别不匹配");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user