fix(order): load all warehouse template options
This commit is contained in:
@@ -13,10 +13,13 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class MerchantBatchImportServiceTest {
|
||||
@@ -86,6 +89,52 @@ class MerchantBatchImportServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateReadsEveryActiveWarehousePageWithoutApplyingBusinessLimit() throws Exception {
|
||||
List<MerchantWarehouseCatalogClient.Warehouse> firstPage = new ArrayList<>();
|
||||
for (long id = 1000; id < 1200; id++) {
|
||||
firstPage.add(new MerchantWarehouseCatalogClient.Warehouse(id, "US-" + id, "海外仓" + id,
|
||||
"OVERSEAS", "US", "ACTIVE"));
|
||||
}
|
||||
var lastWarehouse = new MerchantWarehouseCatalogClient.Warehouse(21L, "CN-YW", "义乌收货仓",
|
||||
"DOMESTIC", "CN", "ACTIVE");
|
||||
when(warehouses.page("Bearer test", 1, 200, "ACTIVE"))
|
||||
.thenReturn(ApiResponse.success(new PageResult<>(firstPage, 1, 200, 201, 2)));
|
||||
when(warehouses.page("Bearer test", 2, 200, "ACTIVE"))
|
||||
.thenReturn(ApiResponse.success(new PageResult<>(List.of(lastWarehouse), 2, 200, 201, 2)));
|
||||
|
||||
byte[] content = service.template(88L, "Bearer test");
|
||||
|
||||
try (var workbook = new XSSFWorkbook(new ByteArrayInputStream(content))) {
|
||||
var options = workbook.getSheet("选项数据");
|
||||
assertThat(hasCellValue(options, "海外仓1000|US-1000")).isTrue();
|
||||
assertThat(hasCellValue(options, "海外仓1199|US-1199")).isTrue();
|
||||
assertThat(hasCellValue(options, "义乌收货仓|CN-YW")).isTrue();
|
||||
}
|
||||
verify(warehouses).page("Bearer test", 2, 200, "ACTIVE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateFailsClosedWhenLaterWarehousePageCannotBeRead() {
|
||||
List<MerchantWarehouseCatalogClient.Warehouse> firstPage = new ArrayList<>();
|
||||
for (long id = 1000; id < 1200; id++) {
|
||||
firstPage.add(new MerchantWarehouseCatalogClient.Warehouse(id, "US-" + id, "海外仓" + id,
|
||||
"OVERSEAS", "US", "ACTIVE"));
|
||||
}
|
||||
when(warehouses.page("Bearer test", 1, 200, "ACTIVE"))
|
||||
.thenReturn(ApiResponse.success(new PageResult<>(firstPage, 1, 200, 201, 2)));
|
||||
when(warehouses.page("Bearer test", 2, 200, "ACTIVE")).thenReturn(null);
|
||||
|
||||
assertThatThrownBy(() -> service.template(88L, "Bearer test"))
|
||||
.isInstanceOf(com.baiyue.common.core.exception.BizException.class)
|
||||
.hasMessage("仓库选项第2页暂不可用");
|
||||
}
|
||||
|
||||
private static boolean hasCellValue(org.apache.poi.ss.usermodel.Sheet sheet, String expected) {
|
||||
for (var row : sheet) for (var cell : row) if (expected.equals(cell.getStringCellValue())) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static CustomerAddressDtos.Response address(long id, String name, String type) {
|
||||
return new CustomerAddressDtos.Response(id, type, name, "测试公司", "张三", "13800000000", null,
|
||||
"CN", "广东", "深圳", "南山", "科技园1号", "518000", true);
|
||||
|
||||
Reference in New Issue
Block a user