Merge remote-tracking branch 'origin/test' into dev
# Conflicts: # AGENTS.md # firstleg/AGENTS.md # scripts/agents-index-contract.ps1
This commit is contained in:
@@ -13,6 +13,8 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -34,13 +36,14 @@ class MerchantBatchImportServiceTest {
|
||||
ReflectionTestUtils.setField(service, "addresses", addresses);
|
||||
ReflectionTestUtils.setField(service, "warehouses", warehouses);
|
||||
ReflectionTestUtils.setField(service, "pricing", pricing);
|
||||
ReflectionTestUtils.setField(service, "json", new ObjectMapper());
|
||||
ReflectionTestUtils.setField(service, "json", new ObjectMapper().findAndRegisterModules());
|
||||
when(addresses.list(88L, "PICKUP")).thenReturn(List.of(address(11L, "工厂", "PICKUP")));
|
||||
when(addresses.list(88L, "PRIVATE_DESTINATION")).thenReturn(List.of(address(12L, "美国门店", "PRIVATE_DESTINATION")));
|
||||
var domestic = new MerchantWarehouseCatalogClient.Warehouse(21L, "CN-YW", "义乌收货仓", "DOMESTIC", "CN", "ACTIVE");
|
||||
var overseas = new MerchantWarehouseCatalogClient.Warehouse(22L, "US-LAX", "洛杉矶海外仓", "OVERSEAS", "US", "ACTIVE");
|
||||
var fba = new MerchantWarehouseCatalogClient.Warehouse(22L, "ATL6", "ATL6", "FBA", "US", "ACTIVE");
|
||||
var overseas = new MerchantWarehouseCatalogClient.Warehouse(23L, "US-LAX", "洛杉矶海外仓", "OVERSEAS", "US", "ACTIVE");
|
||||
when(warehouses.page("Bearer test", 1, 200, "ACTIVE"))
|
||||
.thenReturn(ApiResponse.success(new PageResult<>(List.of(domestic, overseas), 1, 200, 2, 1)));
|
||||
.thenReturn(ApiResponse.success(new PageResult<>(List.of(domestic, fba, overseas), 1, 200, 3, 1)));
|
||||
when(pricing.channels("Bearer test", 21L)).thenReturn(ApiResponse.success(List.of(
|
||||
new MerchantPricingCatalogClient.Channel("US-SEA", "美森海运"))));
|
||||
}
|
||||
@@ -50,14 +53,27 @@ class MerchantBatchImportServiceTest {
|
||||
byte[] content = service.template(88L, "Bearer test");
|
||||
try (var workbook = new XSSFWorkbook(new ByteArrayInputStream(content))) {
|
||||
var sheet = workbook.getSheet("订单导入");
|
||||
assertThat(sheet.getRow(0).getCell(0).getStringCellValue()).isEqualTo("客户行号");
|
||||
assertThat(sheet.getRow(0).getCell(10).getStringCellValue()).isEqualTo("取货地址");
|
||||
assertThat(sheet.getRow(0).getCell(11).getStringCellValue()).isEqualTo("国内收货仓");
|
||||
assertThat(sheet.getRow(0).getCell(29).getStringCellValue()).isEqualTo("是否木制品");
|
||||
assertThat((Object) sheet.getRow(1)).isNull();
|
||||
assertThat(sheet.getRow(0).getCell(0).getStringCellValue()).isEqualTo("订单基础");
|
||||
assertThat(sheet.getRow(0).getCell(6).getStringCellValue()).isEqualTo("目的地与仓库");
|
||||
assertThat(sheet.getRow(1).getCell(0).getStringCellValue()).isEqualTo("客户行号 *");
|
||||
assertThat(sheet.getRow(1).getCell(6).getStringCellValue()).isEqualTo("目的类型 *");
|
||||
assertThat(sheet.getRow(1).getCell(7).getStringCellValue()).isEqualTo("FBA目的仓");
|
||||
assertThat(sheet.getRow(1).getCell(8).getStringCellValue()).isEqualTo("海外仓目的仓");
|
||||
assertThat(sheet.getRow(1).getLastCellNum()).isEqualTo((short) 34);
|
||||
assertThat(rowValues(sheet.getRow(1))).doesNotContain("目的国家代码", "目的仓库名称", "亚马逊仓库代码");
|
||||
assertThat(sheet.getRow(2).getCell(0).getStringCellValue()).isEmpty();
|
||||
assertThat(sheet.getRow(51).getCell(0).getStringCellValue()).isEmpty();
|
||||
assertThat(sheet.getRow(2).getCell(4).getCellStyle().getDataFormatString()).isEqualTo("yyyy-mm-dd");
|
||||
assertThat(sheet.getRow(2).getCell(11).getCellStyle().getDataFormatString()).isEqualTo("yyyy-mm-dd hh:mm:ss");
|
||||
assertThat(sheet.getPaneInformation().isFreezePane()).isTrue();
|
||||
assertThat(sheet.getMergedRegions()).hasSize(6);
|
||||
assertThat(sheet.getCTWorksheet().isSetAutoFilter()).isTrue();
|
||||
assertThat(sheet.getRow(1).getCell(0).getCellComment()).isNotNull();
|
||||
assertThat(sheet.getDataValidations()).hasSizeGreaterThanOrEqualTo(10);
|
||||
assertThat(workbook.getSheet("填写说明")).isNotNull();
|
||||
assertThat(workbook.isSheetHidden(workbook.getSheetIndex("选项数据"))).isTrue();
|
||||
assertThat(hasCellValue(workbook.getSheet("选项数据"), "ATL6")).isTrue();
|
||||
assertThat(hasCellValue(workbook.getSheet("选项数据"), "洛杉矶海外仓|US-LAX")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,16 +81,18 @@ class MerchantBatchImportServiceTest {
|
||||
void importMapsChineseAndBusinessLabelsToCodesAndAuthoritativeIds() throws Exception {
|
||||
byte[] content = service.template(88L, "Bearer test");
|
||||
try (var workbook = new XSSFWorkbook(new ByteArrayInputStream(content)); var out = new ByteArrayOutputStream()) {
|
||||
var row = workbook.getSheet("订单导入").createRow(1);
|
||||
var row = workbook.getSheet("订单导入").getRow(2);
|
||||
row.createCell(0).setCellValue("第1行"); row.createCell(1).setCellValue("测试客户");
|
||||
row.createCell(2).setCellValue("海运"); row.createCell(8).setCellValue("平台上门提货");
|
||||
row.createCell(10).setCellValue("工厂|张三|深圳|科技园1号");
|
||||
row.createCell(11).setCellValue("义乌收货仓|CN-YW"); row.createCell(12).setCellValue("美森海运|US-SEA");
|
||||
row.createCell(13).setCellValue("买单报关"); row.createCell(14).setCellValue("不包税");
|
||||
row.createCell(17).setCellValue("私人地址"); row.createCell(18).setCellValue("美国门店|张三|深圳|科技园1号");
|
||||
row.createCell(23).setCellValue("蓝牙音箱"); row.createCell(24).setCellValue("纸箱");
|
||||
row.createCell(25).setCellValue("1"); row.createCell(26).setCellValue("1.2"); row.createCell(27).setCellValue("0.1");
|
||||
row.createCell(29).setCellValue("否"); row.createCell(30).setCellValue("是");
|
||||
row.createCell(2).setCellValue("海运"); row.getCell(4).setCellValue(LocalDate.of(2026, 9, 20));
|
||||
row.createCell(6).setCellValue("亚马逊FBA"); row.createCell(7).setCellValue("ATL6");
|
||||
row.createCell(10).setCellValue("平台上门提货");
|
||||
row.getCell(11).setCellValue(LocalDateTime.of(2026, 9, 10, 14, 30, 0));
|
||||
row.createCell(12).setCellValue("工厂|张三|深圳|科技园1号");
|
||||
row.createCell(13).setCellValue("义乌收货仓|CN-YW"); row.createCell(14).setCellValue("美森海运|US-SEA");
|
||||
row.createCell(15).setCellValue("买单报关"); row.createCell(16).setCellValue("不包税");
|
||||
row.createCell(22).setCellValue("蓝牙音箱"); row.createCell(23).setCellValue("纸箱");
|
||||
row.createCell(24).setCellValue("1"); row.createCell(25).setCellValue("1.2"); row.createCell(26).setCellValue("0.1");
|
||||
row.createCell(28).setCellValue("否"); row.createCell(29).setCellValue("是");
|
||||
workbook.write(out);
|
||||
var item = service.parse(88L, "Bearer test", out.toByteArray()).get(0);
|
||||
assertThat(item.parseError()).isNull();
|
||||
@@ -84,11 +102,31 @@ class MerchantBatchImportServiceTest {
|
||||
assertThat(item.draft().receivingWarehouseId()).isEqualTo(21L);
|
||||
assertThat(item.draft().channelCode()).isEqualTo("US-SEA");
|
||||
assertThat(item.draft().taxMode()).isEqualTo("BUY_DECLARATION");
|
||||
assertThat(item.draft().destinationWarehouseId()).isEqualTo(22L);
|
||||
assertThat(item.draft().destinationWarehouseName()).isEqualTo("ATL6");
|
||||
assertThat(item.draft().destinationCountryCode()).isEqualTo("US");
|
||||
assertThat(item.draft().amazonWarehouseCode()).isEqualTo("ATL6");
|
||||
assertThat(item.draft().expectedShipDate()).isEqualTo(LocalDate.of(2026, 9, 20));
|
||||
assertThat(item.draft().requestedPickupAt()).isEqualTo(LocalDateTime.of(2026, 9, 10, 14, 30, 0));
|
||||
assertThat(item.draft().cargoes().get(0).packageType()).isEqualTo("CARTON");
|
||||
assertThat(item.draft().cargoes().get(0).dangerousGoods()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void importRejectsOverseasWarehouseWhenDestinationTypeIsFba() throws Exception {
|
||||
byte[] content = service.template(88L, "Bearer test");
|
||||
try (var workbook = new XSSFWorkbook(new ByteArrayInputStream(content)); var out = new ByteArrayOutputStream()) {
|
||||
var row = workbook.getSheet("订单导入").getRow(2);
|
||||
row.createCell(0).setCellValue("第1行"); row.createCell(6).setCellValue("亚马逊FBA");
|
||||
row.createCell(8).setCellValue("洛杉矶海外仓|US-LAX");
|
||||
workbook.write(out);
|
||||
var item = service.parse(88L, "Bearer test", out.toByteArray()).get(0);
|
||||
assertThat(item.draft()).isNull();
|
||||
assertThat(item.parseError()).isEqualTo("亚马逊FBA订单必须且只能选择FBA目的仓");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateReadsEveryActiveWarehousePageWithoutApplyingBusinessLimit() throws Exception {
|
||||
List<MerchantWarehouseCatalogClient.Warehouse> firstPage = new ArrayList<>();
|
||||
@@ -135,6 +173,12 @@ class MerchantBatchImportServiceTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<String> rowValues(org.apache.poi.ss.usermodel.Row row) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (var cell : row) values.add(cell.getStringCellValue());
|
||||
return values;
|
||||
}
|
||||
|
||||
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