fix(firstleg): make PDA allocation settlement idempotent
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
package com.baiyue.firstleg.repository;
|
||||
|
||||
import com.baiyue.firstleg.entity.InboundPalletAllocationEntity;
|
||||
import com.baiyue.firstleg.mapper.InboundPalletAllocationMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class InboundPalletAllocationRepositoryTest {
|
||||
@Mock
|
||||
private InboundPalletAllocationMapper mapper;
|
||||
@InjectMocks
|
||||
private InboundPalletAllocationRepository repository;
|
||||
|
||||
@Test
|
||||
void acceptsReleasedSnapshotWhenRetryUpdateAffectsNoRows() {
|
||||
InboundPalletAllocationEntity current = allocation(1L, 91L, "RELEASED", 10, 10);
|
||||
when(mapper.markReleased(10001L, 31L, 91L)).thenReturn(0);
|
||||
when(mapper.selectOne(any())).thenReturn(current);
|
||||
|
||||
assertThatCode(() -> repository.markReleased(10001L, 31L, List.of(91L)))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsTransferredSnapshotWhenRetryUpdateAffectsNoRows() {
|
||||
InboundPalletAllocationEntity source = allocation(1L, 91L, "CONFIRMED", 10, 2);
|
||||
InboundPalletAllocationEntity current = allocation(1L, 91L, "TRANSFERRED", 10, 2);
|
||||
when(mapper.markTransferred(1L, 10001L, 31L)).thenReturn(0);
|
||||
when(mapper.selectOne(any())).thenReturn(current);
|
||||
|
||||
assertThatCode(() -> repository.markTransferred(10001L, 31L, List.of(source), List.of()))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
private static InboundPalletAllocationEntity allocation(long id, long reservationId, String status,
|
||||
int allocated, int picked) {
|
||||
InboundPalletAllocationEntity entity = new InboundPalletAllocationEntity();
|
||||
entity.setId(id);
|
||||
entity.setReservationId(reservationId);
|
||||
entity.setAllocationStatus(status);
|
||||
entity.setAllocatedPackageCount(allocated);
|
||||
entity.setPickedPackageCount(picked);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user