You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
6.8 KiB
173 lines
6.8 KiB
package common.ecommerce.edayun.adapter; |
|
|
|
import common.ecommerce.edayun.dto.EdayunInboundQueryDtos; |
|
import common.ecommerce.edayun.enums.EdayunInboundSkuStatus; |
|
import common.ecommerce.shared.support.Page; |
|
import common.ecommerce.warehouse.enums.InboundStatus; |
|
import common.ecommerce.warehouse.model.InboundOrder; |
|
import common.ecommerce.warehouse.model.InboundOrderLine; |
|
import org.junit.jupiter.api.Test; |
|
|
|
import java.util.Arrays; |
|
import java.util.Collections; |
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
import static org.junit.jupiter.api.Assertions.assertNull; |
|
import static org.junit.jupiter.api.Assertions.assertThrows; |
|
import static org.junit.jupiter.api.Assertions.assertTrue; |
|
|
|
/** |
|
* 入库明细查询({@code selectEntrySkuGoodsDetail})映射。 |
|
* |
|
* <p>重点:只认 entryCode、单头状态由 SKU 状态汇总、状态码表未确认时的中文名兜底。</p> |
|
*/ |
|
class EdayunInboundQueryTest { |
|
|
|
private static EdayunInboundQueryDtos.EntrySkuRow row(String sku, int forecast, |
|
int checked, int shelves, |
|
Integer status, String statusName) { |
|
EdayunInboundQueryDtos.EntrySkuRow row = new EdayunInboundQueryDtos.EntrySkuRow(); |
|
row.skuCode = sku; |
|
row.skuName = "候杰测试" + sku; |
|
row.forecastQuantity = forecast; |
|
row.actualCheckedQuantity = checked; |
|
row.shelvesQuantity = shelves; |
|
row.status = status; |
|
row.statusName = statusName; |
|
row.entryCode = "REV24050738176"; |
|
row.forecastWeight = 12100.0; |
|
row.firstWeight = 12.1; |
|
row.forecastCargoSize = "115.3*79.8*36"; |
|
return row; |
|
} |
|
|
|
// ------------------------------------------------------------ 请求 |
|
|
|
@Test |
|
void mapsEntryCodeAndPaging() { |
|
EdayunInboundQueryDtos.SelectEntrySkuRequest req = |
|
EdayunInboundQueryMapper.toRequest("REV24050738176", 1); |
|
|
|
assertEquals("REV24050738176", req.entryCode); |
|
assertEquals(Integer.valueOf(1), req.pageNum); |
|
assertEquals(Integer.valueOf(200), req.pageSize); |
|
} |
|
|
|
/** 接口只能按仓侧 entryCode 查,没有单号就别发。 */ |
|
@Test |
|
void blankEntryCodeIsRejected() { |
|
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, |
|
() -> EdayunInboundQueryMapper.toRequest(" ", 1)); |
|
|
|
assertTrue(ex.getMessage().contains("entryCode"), ex.getMessage()); |
|
} |
|
|
|
// ------------------------------------------------------------ 状态 |
|
|
|
/** 码 4 = 已上架(文档示例)。 */ |
|
@Test |
|
void code4IsCompleted() { |
|
assertEquals(InboundStatus.COMPLETED, |
|
EdayunInboundSkuStatus.toCore(4, "已上架")); |
|
} |
|
|
|
/** 码表未给的部分按中文名兜底。 */ |
|
@Test |
|
void unknownCodeFallsBackToChineseName() { |
|
assertEquals(InboundStatus.RECEIVING, EdayunInboundSkuStatus.toCore(99, "清点中")); |
|
assertEquals(InboundStatus.IN_TRANSIT, EdayunInboundSkuStatus.toCore(99, "在途")); |
|
assertEquals(InboundStatus.STORING, EdayunInboundSkuStatus.toCore(99, "上架中")); |
|
assertEquals(InboundStatus.CANCELLED, EdayunInboundSkuStatus.toCore(99, "已取消")); |
|
} |
|
|
|
/** 认不出就是 UNKNOWN,不猜。 */ |
|
@Test |
|
void unrecognizedStatusIsUnknown() { |
|
assertEquals(InboundStatus.UNKNOWN, EdayunInboundSkuStatus.toCore(77, null)); |
|
assertEquals(InboundStatus.UNKNOWN, EdayunInboundSkuStatus.toCore(null, "莫名其妙")); |
|
assertNull(EdayunInboundSkuStatus.UNKNOWN.rawCode()); |
|
} |
|
|
|
// ------------------------------------------------------------ 汇总 |
|
|
|
/** 还有 SKU 没上架,整单不算完成。 */ |
|
@Test |
|
void headStatusTakesLeastAdvancedSku() { |
|
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", Arrays.asList( |
|
row("SKU-A", 10, 10, 10, 4, "已上架"), |
|
row("SKU-B", 5, 5, 0, 99, "清点中")), "EDY-WH"); |
|
|
|
assertEquals(InboundStatus.RECEIVING, order.status()); |
|
assertEquals("已上架", order.rawStatus()); |
|
} |
|
|
|
/** 全部认不出 → UNKNOWN,不能当成完成。 */ |
|
@Test |
|
void allUnknownStatusStaysUnknown() { |
|
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", |
|
Collections.singletonList(row("SKU-A", 1, 1, 1, 77, null)), "EDY-WH"); |
|
|
|
assertEquals(InboundStatus.UNKNOWN, order.status()); |
|
} |
|
|
|
// ------------------------------------------------------------ 映射 |
|
|
|
@Test |
|
void mapsQuantitiesAndLines() { |
|
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", Arrays.asList( |
|
row("SKU-A", 10, 9, 8, 4, "已上架"), |
|
row("SKU-B", 5, 5, 5, 4, "已上架")), "EDY-WH"); |
|
|
|
assertEquals("REV1", order.inboundRequestNo()); |
|
assertEquals("REV1", order.providerInboundId()); |
|
assertEquals("EDY-WH", order.warehouseCode()); |
|
assertEquals(15, order.plannedQuantity()); |
|
assertEquals(13, order.receivedQuantity()); |
|
assertEquals(2, order.boxCount()); |
|
assertEquals(2, order.lines().size()); |
|
|
|
InboundOrderLine line = order.lines().get(0); |
|
assertEquals("SKU-A", line.providerSku()); |
|
assertEquals(10, line.plannedQuantity()); |
|
assertEquals(9, line.packedQuantity()); |
|
assertEquals(8, line.receivedQuantity()); |
|
assertTrue(!line.quantityMatchesPlan()); |
|
assertEquals("候杰测试SKU-A", line.productName()); |
|
} |
|
|
|
/** 没有 SKU 的行不计入明细,但数量照算——否则总数会悄悄变少。 */ |
|
@Test |
|
void rowsWithoutSkuAreSkippedButCounted() { |
|
InboundOrder order = EdayunInboundQueryMapper.toOrder("REV1", Arrays.asList( |
|
row(null, 3, 3, 3, 4, "已上架"), |
|
row("SKU-B", 5, 5, 5, 4, "已上架")), "EDY-WH"); |
|
|
|
assertEquals(1, order.lines().size()); |
|
assertEquals(8, order.plannedQuantity()); |
|
} |
|
|
|
// ------------------------------------------------------------ 分页 |
|
|
|
@Test |
|
void pageCarriesNextCursorWhenFull() { |
|
Page<InboundOrder> page = EdayunInboundQueryMapper.toPage("REV1", |
|
java.util.Collections.nCopies(200, row("SKU", 1, 1, 1, 4, "已上架")), |
|
"EDY-WH", 1, 200); |
|
|
|
assertEquals(1, page.size()); |
|
assertEquals("2", page.nextCursor()); |
|
assertTrue(page.hasMore()); |
|
} |
|
|
|
@Test |
|
void emptyRowsYieldEmptyPage() { |
|
assertTrue(EdayunInboundQueryMapper.toPage("REV1", null, "EDY-WH", 1, 200).items().isEmpty()); |
|
} |
|
|
|
@Test |
|
void cursorParsing() { |
|
assertEquals(1, EdayunInboundQueryMapper.pageNumber(null)); |
|
assertEquals(1, EdayunInboundQueryMapper.pageNumber("abc")); |
|
assertEquals(3, EdayunInboundQueryMapper.pageNumber("3")); |
|
} |
|
}
|
|
|