feat: add self-operated analytics and enforce Lastleg module boundaries
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
package com.baiyue.lastleg.delivery.fleet;
|
||||
|
||||
import com.baiyue.lastleg.delivery.mapper.DeliverySourceEvidenceMapper;
|
||||
import com.baiyue.lastleg.delivery.model.SourceDeliveryCompletionPolicy.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class FleetPoolDeliveryAdapterTest {
|
||||
private final DeliverySourceEvidenceMapper evidence=mock(DeliverySourceEvidenceMapper.class);
|
||||
private final FleetPoolDeliveryAdapter adapter=new FleetPoolDeliveryAdapter(evidence);
|
||||
private final LocalDateTime signed=LocalDateTime.of(2026,10,12,12,0);
|
||||
private void shipment(int total,long signatures,List<Pick> picks,List<Returned> returns){
|
||||
when(evidence.dispatchIds("9",77)).thenReturn(List.of(70L));
|
||||
when(evidence.deliveries("9",70)).thenReturn(List.of(new Delivery(71,70,"CODE:ONT8",total,signatures,signed,signed.minusHours(1))));
|
||||
when(evidence.picks("9",70)).thenReturn(picks);when(evidence.returns("9",70)).thenReturn(returns);
|
||||
}
|
||||
private Pick pick(long id,long source,int quantity){return new Pick(id,70,"CODE:ONT8",source,quantity,id,null,null,null);}
|
||||
@Test void completeActualSourceIsSignedButPartialSignatureIsNot(){
|
||||
shipment(4,2,List.of(pick(1,77,4)),List.of());assertThat(adapter.fullySigned("9","WT-7",77,4)).isFalse();
|
||||
shipment(4,4,List.of(pick(1,77,4)),List.of());assertThat(adapter.fullySigned("9","WT-7",77,4)).isTrue();
|
||||
}
|
||||
@Test void anotherCoShippedSourceReturnDoesNotBlockThisFullySignedSource(){
|
||||
shipment(8,6,List.of(pick(1,77,4),pick(2,78,4)),List.of(new Returned(9,71,78,2,signed.minusMinutes(5))));
|
||||
assertThat(adapter.fullySigned("9","WT-7",77,4)).isTrue();
|
||||
}
|
||||
@Test void thisSourceReturnCannotBeCountedAsWholeSignature(){
|
||||
shipment(4,2,List.of(pick(1,77,4)),List.of(new Returned(9,71,77,2,signed.minusMinutes(5))));
|
||||
assertThat(adapter.fullySigned("9","WT-7",77,4)).isFalse();
|
||||
}
|
||||
@Test void missingOrDuplicatedDispatchEvidenceIsUnproved(){
|
||||
for(var ids:List.of(List.<Long>of(),List.of(70L,70L),List.of(0L))){
|
||||
when(evidence.dispatchIds("9",77)).thenReturn(ids);assertThat(adapter.fullySigned("9","WT-7",77,4)).isFalse();
|
||||
}
|
||||
verify(evidence,never()).deliveries(anyString(),anyLong());
|
||||
}
|
||||
@Test void missingPickOrReturnHistoryIsUnproved(){
|
||||
shipment(4,4,List.of(),List.of());assertThat(adapter.fullySigned("9","WT-7",77,4)).isFalse();
|
||||
shipment(4,4,List.of(pick(1,77,4)),null);assertThat(adapter.fullySigned("9","WT-7",77,4)).isFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user