优化
This commit is contained in:
+13
@@ -3,6 +3,7 @@ package com.baiyue.warehouse.controller;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.warehouse.dto.PalletAllocationDtos;
|
||||
import com.baiyue.warehouse.dto.LocationDtos;
|
||||
import com.baiyue.warehouse.service.PalletLocationAllocationService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -65,6 +66,18 @@ class InternalPalletLocationControllerTest {
|
||||
verify(service).settle(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsOccupiedResourcesOnlyForInternalCaller() {
|
||||
List<LocationDtos.OccupiedResource> expected = List.of(new LocationDtos.OccupiedResource(
|
||||
101L, 201L, 0, 20L, 30L, 40L, "A-01", false, 5));
|
||||
when(service.occupiedResources(0L, "firstleg-service", 88L)).thenReturn(expected);
|
||||
|
||||
var response = controller.occupiedResources(INTERNAL_TOKEN, 0L, "firstleg-service", 88L);
|
||||
|
||||
assertThat(response.data()).isEqualTo(expected);
|
||||
verify(service).occupiedResources(0L, "firstleg-service", 88L);
|
||||
}
|
||||
|
||||
private static PalletAllocationDtos.TransferRequest request() {
|
||||
return new PalletAllocationDtos.TransferRequest(10001L, "FIRSTLEG", 88L, 89L,
|
||||
"RK-001-S1", "transfer-88-89", 9001L, List.of(new PalletAllocationDtos.TransferItem(40L, 5)));
|
||||
|
||||
@@ -49,6 +49,27 @@ class LocationResourceServiceTest {
|
||||
assertThat(service.findActiveResources(0L, "firstleg-service", 901L)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsOnlyCurrentOccupiedResourcesWithAllocatedPackageCounts() {
|
||||
LocationOccupancyEntity active = occupancy(201L, 101L, 9L, "A1", 501L);
|
||||
active.setTenantId(0L);
|
||||
active.setSourceService("firstleg-service");
|
||||
active.setBusinessId(901L);
|
||||
active.setAllocatedPackageCount(7);
|
||||
LocationOccupancyEntity released = occupancy(202L, 102L, 10L, "A2", 502L);
|
||||
released.setOccupancyStatus("RELEASED");
|
||||
when(repository.findOccupanciesByBusiness(0L, "firstleg-service", 901L))
|
||||
.thenReturn(List.of(released, active));
|
||||
|
||||
var result = service.findOccupiedResources(0L, "firstleg-service", 901L);
|
||||
|
||||
assertThat(result).singleElement().satisfies(item -> {
|
||||
assertThat(item.reservationId()).isEqualTo(101L);
|
||||
assertThat(item.occupancyId()).isEqualTo(201L);
|
||||
assertThat(item.allocatedPackageCount()).isEqualTo(7);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHandleCase01() {
|
||||
when(repository.findWarehouse(10001L, 88L)).thenReturn(warehouse());
|
||||
|
||||
+25
@@ -53,6 +53,26 @@ class OverseasStorageFeeServiceTest {
|
||||
verify(repository, never()).insertRule(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsVariableTierCountsEvenWhenTotalIsNine() {
|
||||
doAnswer(invocation -> {
|
||||
OverseasStorageFeeRuleEntity rule = invocation.getArgument(0);
|
||||
rule.setId(10L);
|
||||
return null;
|
||||
}).when(repository).insertRule(any());
|
||||
List<OverseasStorageFeeDtos.TierRequest> tiers = List.of(
|
||||
typedTier("STORAGE", "CBM", 1, 10), typedTier("STORAGE", "CBM", 11, 20),
|
||||
typedTier("STORAGE", "CBM", 21, 30), typedTier("STORAGE", "CBM", 31, null),
|
||||
typedTier("RETURN_STORAGE", "PALLET", 1, 10), typedTier("RETURN_STORAGE", "PALLET", 11, 20),
|
||||
typedTier("RETURN_STORAGE", "PALLET", 21, 30), typedTier("RETURN_STORAGE", "PALLET", 31, 40),
|
||||
typedTier("RETURN_STORAGE", "PALLET", 41, null));
|
||||
|
||||
Long id = service.create(new OverseasStorageFeeDtos.CreateRequest(10001L, "示例客户", "USD", tiers));
|
||||
|
||||
assertThat(id).isEqualTo(10L);
|
||||
verify(repository).insertTiers(org.mockito.ArgumentMatchers.argThat(list -> list.size() == 9));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsDuplicateCustomer() {
|
||||
when(repository.existsCustomer(10001L, null)).thenReturn(true);
|
||||
@@ -124,6 +144,11 @@ class OverseasStorageFeeServiceTest {
|
||||
return new OverseasStorageFeeDtos.TierRequest(start, end, new BigDecimal(price));
|
||||
}
|
||||
|
||||
private static OverseasStorageFeeDtos.TierRequest typedTier(String feeType, String billingUnit,
|
||||
int start, Integer end) {
|
||||
return new OverseasStorageFeeDtos.TierRequest(feeType, billingUnit, start, end, BigDecimal.ONE);
|
||||
}
|
||||
|
||||
private static OverseasStorageFeeRuleEntity rule() {
|
||||
OverseasStorageFeeRuleEntity rule = new OverseasStorageFeeRuleEntity();
|
||||
rule.setId(10L);
|
||||
|
||||
Reference in New Issue
Block a user