fix: expose the selected container schedule for editing
This commit is contained in:
+38
@@ -4,6 +4,8 @@ import com.baiyue.firstleg.entity.ContainerBookingEntity;
|
||||
import com.baiyue.firstleg.mapper.ContainerBookingMapper;
|
||||
import com.baiyue.firstleg.portschedule.entity.PortScheduleEntity;
|
||||
import com.baiyue.firstleg.portschedule.mapper.PortScheduleMapper;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -32,6 +34,7 @@ class ContainerRepositoryLoadingTimeTest {
|
||||
ContainerBookingEntity result = repository.find(7L);
|
||||
|
||||
assertThat(result.getLoadingAt()).isEqualTo(completedAt);
|
||||
assertThat(result.getCurrentPortScheduleId()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,6 +61,7 @@ class ContainerRepositoryLoadingTimeTest {
|
||||
booking.setVesselName("OLD-VESSEL");
|
||||
booking.setVoyageNo("OLD-V01");
|
||||
PortScheduleEntity schedule = new PortScheduleEntity();
|
||||
schedule.setId(11L);
|
||||
schedule.setVesselName("NEW-VESSEL");
|
||||
schedule.setVoyageNo("NEW-V01");
|
||||
schedule.setEtdAt(LocalDateTime.of(2026, 10, 7, 8, 0));
|
||||
@@ -68,9 +72,43 @@ class ContainerRepositoryLoadingTimeTest {
|
||||
ContainerBookingEntity result = repository.find(8L);
|
||||
|
||||
assertThat(result.getContainerNo()).isEqualTo("TSTU0000001");
|
||||
assertThat(result.getCurrentPortScheduleId()).isEqualTo(11L);
|
||||
assertThat(result.getVesselName()).isEqualTo("NEW-VESSEL");
|
||||
assertThat(result.getVoyageNo()).isEqualTo("NEW-V01");
|
||||
assertThat(result.getEstimatedSailingAt()).isEqualTo(schedule.getEtdAt());
|
||||
assertThat(result.getEstimatedPortArrivalAt()).isEqualTo(schedule.getEtaAt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void leavesCurrentPortScheduleNullWhenNoScheduleMatches() {
|
||||
ContainerBookingEntity booking = new ContainerBookingEntity();
|
||||
booking.setId(8L);
|
||||
booking.setCustomerId(9L);
|
||||
booking.setOceanBookingId(10L);
|
||||
booking.setCurrentPortScheduleId(11L);
|
||||
booking.setVesselName("BOOKING-VESSEL");
|
||||
booking.setVoyageNo("BOOKING-V01");
|
||||
when(mapper.selectBooking(8L)).thenReturn(booking);
|
||||
when(schedules.latestForDispatch(9L, 10L, 8L)).thenReturn(null);
|
||||
|
||||
ContainerBookingEntity result = repository.find(8L);
|
||||
|
||||
assertThat(result.getCurrentPortScheduleId()).isNull();
|
||||
assertThat(result.getVesselName()).isEqualTo("BOOKING-VESSEL");
|
||||
assertThat(result.getVoyageNo()).isEqualTo("BOOKING-V01");
|
||||
}
|
||||
|
||||
@Test
|
||||
void currentPortScheduleIsNonPersistentAndSerializedReadOnly() throws Exception {
|
||||
var field = ContainerBookingEntity.class.getDeclaredField("currentPortScheduleId");
|
||||
assertThat(field.getAnnotation(TableField.class).exist()).isFalse();
|
||||
ObjectMapper json = new ObjectMapper();
|
||||
ContainerBookingEntity booking = new ContainerBookingEntity();
|
||||
booking.setCurrentPortScheduleId(11L);
|
||||
|
||||
assertThat(json.readTree(json.writeValueAsString(booking)).get("currentPortScheduleId").asLong())
|
||||
.isEqualTo(11L);
|
||||
assertThat(json.readValue("{\"currentPortScheduleId\":11}", ContainerBookingEntity.class)
|
||||
.getCurrentPortScheduleId()).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user