This commit is contained in:
2026-09-04 18:47:57 +08:00
parent 7c5ed85a36
commit 77817b4c94
20 changed files with 240 additions and 92 deletions
@@ -26,7 +26,7 @@ class InternalPendingReviewOrderControllerTest {
@Test
void acceptsOnlyTheConfiguredInternalServiceToken() {
var query = new PendingReviewOrderDtos.Query(List.of("SEA-US"), null, null, null, null, null,
List.of(101L), 1, 20);
null, null, List.of(101L), 1, 20);
var page = new PageResult<PendingReviewOrderDtos.Row>(List.of(), 1, 20, 0, 0);
when(service.page(query)).thenReturn(page);
@@ -16,8 +16,11 @@ class PendingReviewOrderOpenApiContractTest {
.contains("channelCodes")
.contains("createdStart")
.contains("createdEnd")
.contains("expectedArrivalStart")
.contains("expectedArrivalEnd")
.contains("excludedOrderIds")
.contains("PendingReviewOrderRow:")
.contains("expectedArrivalAt: {type: string, format: date-time, nullable: true}")
.contains("mainStatus: {type: string, enum: [PENDING_REVIEW]}")
.contains("orderId: {type: string, pattern: '^[1-9][0-9]*$'}")
.contains("warehouseId: {type: string, pattern: '^[1-9][0-9]*$'}");
@@ -39,6 +39,7 @@ class PendingReviewOrderRepositoryTest {
when(orderMapper.selectPage(any(Page.class), any(Wrapper.class))).thenReturn(new Page<>());
repository.pendingReviewPage(List.of("SEA-US", "AIR-US"), 11L, 22L, "RK-1",
LocalDateTime.of(2026, 9, 1, 0, 0), LocalDateTime.of(2026, 9, 4, 0, 0),
LocalDateTime.of(2026, 9, 5, 0, 0), LocalDateTime.of(2026, 9, 8, 0, 0),
List.of(101L, 102L), 3, 40);
ArgumentCaptor<Page<OrderEntity>> page = ArgumentCaptor.forClass(Page.class);
@@ -54,6 +55,8 @@ class PendingReviewOrderRepositoryTest {
.contains(".eq(OrderEntity::getStatus, OrderStatus.SUBMITTED)")
.contains(".in(channelCodes != null && !channelCodes.isEmpty(), OrderEntity::getChannelCode, channelCodes)")
.contains(".lt(createdBefore != null, OrderEntity::getCreatedAt, createdBefore)")
.contains(".ge(expectedArrivalFrom != null, OrderEntity::getExpectedArrivalAt, expectedArrivalFrom)")
.contains(".lt(expectedArrivalBefore != null, OrderEntity::getExpectedArrivalAt, expectedArrivalBefore)")
.contains(".notIn(excludedOrderIds != null && !excludedOrderIds.isEmpty(), OrderEntity::getId,")
.contains(".orderByDesc(OrderEntity::getCreatedAt)")
.contains(".orderByDesc(OrderEntity::getId)");
@@ -36,16 +36,19 @@ class PendingReviewOrderQueryServiceTest {
@Test
void convertsShanghaiNaturalDatesToClosedDayRangeAndNormalizesFilters() {
when(repository.pendingReviewPage(any(), any(), any(), any(), any(), any(), any(), anyLong(), anyLong()))
when(repository.pendingReviewPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), anyLong(), anyLong()))
.thenReturn(new PageResult<>(List.of(), 2, 20, 0, 0));
service.page(new PendingReviewOrderDtos.Query(List.of(" SEA-US ", "SEA-US"), 11L, 22L,
" RK-1 ", LocalDate.of(2026, 9, 1), LocalDate.of(2026, 9, 3), List.of(101L), 2, 20));
" RK-1 ", LocalDate.of(2026, 9, 1), LocalDate.of(2026, 9, 3),
LocalDate.of(2026, 9, 5), LocalDate.of(2026, 9, 7), List.of(101L), 2, 20));
@SuppressWarnings("unchecked") ArgumentCaptor<List<String>> channels = ArgumentCaptor.forClass(List.class);
verify(repository).pendingReviewPage(channels.capture(), eq(11L), eq(22L), eq("RK-1"),
eq(LocalDateTime.of(2026, 9, 1, 0, 0)),
eq(LocalDateTime.of(2026, 9, 4, 0, 0)), eq(List.of(101L)), eq(2L), eq(20L));
eq(LocalDateTime.of(2026, 9, 4, 0, 0)),
eq(LocalDateTime.of(2026, 9, 5, 0, 0)),
eq(LocalDateTime.of(2026, 9, 8, 0, 0)), eq(List.of(101L)), eq(2L), eq(20L));
assertThat(channels.getValue()).containsExactly("SEA-US");
}
@@ -56,19 +59,21 @@ class PendingReviewOrderQueryServiceTest {
order.setCustomerId(22L); order.setCustomerName("测试客户"); order.setReceivingWarehouseId(33L);
order.setChannelCode("SEA-US"); order.setChannelName("美线");
order.setCreatedAt(LocalDateTime.of(2026, 9, 3, 10, 30));
order.setExpectedArrivalAt(LocalDateTime.of(2026, 9, 8, 15, 0));
OrderCargoEntity first = cargo(101L, 2);
OrderCargoEntity second = cargo(101L, 3);
when(repository.pendingReviewPage(any(), any(), any(), any(), any(), any(), any(), anyLong(), anyLong()))
when(repository.pendingReviewPage(any(), any(), any(), any(), any(), any(), any(), any(), any(), anyLong(), anyLong()))
.thenReturn(new PageResult<>(List.of(order), 1, 20, 1, 1));
when(repository.findCargoByOrderIds(null, List.of(101L))).thenReturn(List.of(first, second));
var result = service.page(new PendingReviewOrderDtos.Query(null, null, null, " ", null, null,
List.of(), 1, 20));
null, null, List.of(), 1, 20));
assertThat(result.records()).singleElement().satisfies(row -> {
assertThat(row.orderId()).isEqualTo(101L);
assertThat(row.warehouseId()).isEqualTo(33L);
assertThat(row.totalPackageCount()).isEqualTo(5);
assertThat(row.expectedArrivalAt()).isEqualTo(LocalDateTime.of(2026, 9, 8, 15, 0));
assertThat(row.mainStatus()).isEqualTo("PENDING_REVIEW");
});
}
@@ -76,9 +81,13 @@ class PendingReviewOrderQueryServiceTest {
@Test
void rejectsReversedDatesAndBlankChannelValues() {
assertThatThrownBy(() -> service.page(new PendingReviewOrderDtos.Query(null, null, null, null,
LocalDate.of(2026, 9, 4), LocalDate.of(2026, 9, 3), List.of(), 1, 20))).isInstanceOf(BizException.class);
LocalDate.of(2026, 9, 4), LocalDate.of(2026, 9, 3), null, null,
List.of(), 1, 20))).isInstanceOf(BizException.class);
assertThatThrownBy(() -> service.page(new PendingReviewOrderDtos.Query(null, null, null, null,
null, null, LocalDate.of(2026, 9, 9), LocalDate.of(2026, 9, 8),
List.of(), 1, 20))).isInstanceOf(BizException.class);
assertThatThrownBy(() -> service.page(new PendingReviewOrderDtos.Query(List.of(" "), null, null,
null, null, null, List.of(), 1, 20))).isInstanceOf(BizException.class);
null, null, null, null, null, List.of(), 1, 20))).isInstanceOf(BizException.class);
}
private static OrderCargoEntity cargo(long orderId, int packageCount) {