51 lines
3.0 KiB
Java
51 lines
3.0 KiB
Java
package com.baiyue.firstleg.customerstatistics;
|
|
|
|
import com.baiyue.firstleg.customerstatistics.controller.PlatformCustomerTransitStatisticsController;
|
|
import com.baiyue.firstleg.customerstatistics.mapper.CustomerTransitStatisticsMapper;
|
|
import com.baiyue.firstleg.customerstatistics.service.CustomerTransitStatisticsService;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.Arrays;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
class CustomerTransitStatisticsContractTest {
|
|
@Test void exposesPlatformCustomerSummaryWithStablePermission() throws Exception {
|
|
assertThat(PlatformCustomerTransitStatisticsController.class.getAnnotation(RequestMapping.class).value())
|
|
.containsExactly("/api/platform/v1/customers");
|
|
var method = PlatformCustomerTransitStatisticsController.class.getDeclaredMethod(
|
|
"summary", com.baiyue.common.security.AuthenticatedUser.class, long.class);
|
|
assertThat(method.getAnnotation(GetMapping.class).value()).containsExactly("/{customerId}/container-transit-summary");
|
|
assertThat(method.getAnnotation(PreAuthorize.class).value())
|
|
.isEqualTo("hasAuthority('platform:firstleg:container:list')");
|
|
}
|
|
|
|
@Test void queryEnforcesTransitScopeOwnershipDedupAndTeuRules() throws Exception {
|
|
var sql = Arrays.stream(CustomerTransitStatisticsMapper.class.getDeclaredMethods())
|
|
.findFirst().orElseThrow().getAnnotation(org.apache.ibatis.annotations.Select.class).value();
|
|
var statement = String.join("\n", sql);
|
|
assertThat(statement).contains("actual_sailing_at IS NOT NULL", "actual_warehouse_arrival_at IS NULL",
|
|
"status NOT IN ('CANCELLED', 'FAILED')", "DISTINCT x.customer_id, x.container_booking_id",
|
|
"b.customer_id", "i.account_id", "i.deleted = 0", "NOT EXISTS",
|
|
"x.customer_id = #{customerId}", "LIKE '20%'", "THEN 1.0",
|
|
"LIKE '40%'", "THEN 2.0", "LIKE '45%'", "THEN 2.25", "ELSE NULL");
|
|
}
|
|
|
|
@Test void schemaAddsTransitSummaryIndexAndDefinition() throws Exception {
|
|
var schema = new ClassPathResource("db/phase3-smart-loading-schema.sql")
|
|
.getContentAsString(StandardCharsets.UTF_8);
|
|
assertThat(schema).contains("idx_container_booking_transit_summary");
|
|
var openApi = new ClassPathResource("openapi/customer-statistics-v1.yaml")
|
|
.getContentAsString(StandardCharsets.UTF_8);
|
|
assertThat(openApi).contains("containerCount:", "format: int64", "totalTeu:",
|
|
"multipleOf: 0.01", "unknownContainerCount:", "format: date-time", "definition:");
|
|
var service = CustomerTransitStatisticsService.class;
|
|
assertThat(service.getDeclaredFields()).anyMatch(f -> f.getName().equals("DEFINITION"));
|
|
}
|
|
}
|