fix(firstleg): make loading evidence upload replayable
This commit is contained in:
+36
@@ -14,11 +14,18 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -98,6 +105,35 @@ class CabinetLoadingEvidenceServiceTest {
|
||||
verify(mapper).insert(org.mockito.ArgumentMatchers.any(CabinetLoadingEvidenceEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipartReplayUsesContentHashBeforeUploadingAnotherFile() {
|
||||
var multipart = new MockMultipartFile("file", "photo.png", "image/png", new byte[] {1, 2, 3});
|
||||
var upload = new LoadingEvidenceFileClient.UploadResult(301L, "PLATFORM", 0L,
|
||||
"LOADING_PHOTO_STEP_1", "99", "photo.png", "image/png", 3L);
|
||||
var metadata = new LoadingEvidenceFileClient.FileMetadata(301L, "PLATFORM", 0L,
|
||||
"LOADING_PHOTO_STEP_1", "99", "photo.png", "image/png");
|
||||
when(files.upload(anyString(), anyLong(), anyLong(), anyString(), any()))
|
||||
.thenReturn(com.baiyue.common.core.api.ApiResponse.success(upload));
|
||||
when(files.validate(anyString(), anyLong(), anyString(), anyLong()))
|
||||
.thenReturn(com.baiyue.common.core.api.ApiResponse.success(metadata));
|
||||
when(mapper.byContainer(99L)).thenReturn(List.of());
|
||||
|
||||
service.upload(20L, 8L, "same-key", 0, "PHOTO_STEP_1", null, "remark",
|
||||
multipart, 9L, "operator");
|
||||
|
||||
ArgumentCaptor<CabinetLoadingEvidenceEntity> inserted =
|
||||
ArgumentCaptor.forClass(CabinetLoadingEvidenceEntity.class);
|
||||
verify(mapper).insert(inserted.capture());
|
||||
when(mapper.byOperation(20L, "same-key")).thenReturn(inserted.getValue());
|
||||
when(mapper.byContainer(99L)).thenReturn(List.of(inserted.getValue()));
|
||||
|
||||
var replay = service.upload(20L, 8L, "same-key", 0, "PHOTO_STEP_1", null, "remark",
|
||||
multipart, 9L, "operator");
|
||||
|
||||
assertThat(replay.evidences()).hasSize(1);
|
||||
verify(files, times(1)).upload(anyString(), anyLong(), anyLong(), anyString(), any());
|
||||
}
|
||||
|
||||
private static CabinetLoadingEvidenceEntity evidence(String type) {
|
||||
CabinetLoadingEvidenceEntity value = new CabinetLoadingEvidenceEntity();
|
||||
value.setEvidenceType(type); value.setStatus("ACTIVE"); value.setContainerBookingId(99L);
|
||||
|
||||
Reference in New Issue
Block a user