test(firstleg): bind channel change hash to full payload

This commit is contained in:
2026-09-02 10:29:24 +08:00
parent e0a1f15777
commit 31996491be
2 changed files with 17 additions and 0 deletions
@@ -159,6 +159,7 @@ public class OrderChannelChangePricingService {
try {
String value = request.tenantId() + ":" + request.orderId() + ":" + request.orderVersion() + ":"
+ request.originWarehouseId() + ":" + request.channelCode().trim().toUpperCase() + ":"
+ request.channelName().trim() + ":"
+ request.destinationType() + ":" + request.destinationWarehouseId() + ":"
+ request.destinationCode() + ":" + request.pricingTaxMode();
return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256")
@@ -96,6 +96,22 @@ class OrderChannelChangePricingServiceTest {
verify(repository, never()).applyOrderChannelChange(any(), any(), any());
}
@Test
void sameOrderVersionRejectsDifferentChannelNamePayload() {
InboundPricingEntity inbound = inbound("UNPRICED");
InboundPricingIdempotencyEntity token = token(4L, "COMPLETED");
token.setRequestHash(requestHash(request(4)));
when(repository.findInboundByOrderForUpdate(10001L, 77L)).thenReturn(inbound);
when(repository.findIdempotency(10001L, 0L, "ORDER_CHANNEL_CHANGE", "77:4")).thenReturn(token);
Request changedName = new Request(10001L, 77L, 4L, 9L, "MATSON_NEW", "伪造名称",
"FBA", 501L, "ONT8", "TAX_INCLUDED");
assertThatThrownBy(() -> service.apply(changedName))
.isInstanceOf(BizException.class)
.hasMessageContaining("同一订单版本已用于不同渠道变更");
verify(estimator, never()).estimate(any());
}
@Test
void rejectsOlderOrderVersionAfterNewerVersionWasApplied() {
InboundPricingEntity inbound = inbound("UNPRICED");