测试: 补齐上传文件删除校验与失败保护
This commit is contained in:
@@ -890,6 +890,18 @@ public class CcdiFileUploadServiceImpl implements ICcdiFileUploadService {
|
||||
if (record == null) {
|
||||
throw new RuntimeException("上传记录不存在");
|
||||
}
|
||||
if (!"parsed_success".equals(record.getFileStatus())) {
|
||||
if ("deleted".equals(record.getFileStatus())) {
|
||||
throw new RuntimeException("文件已删除,请勿重复操作");
|
||||
}
|
||||
throw new RuntimeException("仅支持删除解析成功文件");
|
||||
}
|
||||
if (record.getLsfxProjectId() == null) {
|
||||
throw new RuntimeException("缺少流水分析项目ID");
|
||||
}
|
||||
if (record.getLogId() == null) {
|
||||
throw new RuntimeException("缺少文件logId");
|
||||
}
|
||||
}
|
||||
|
||||
private Integer toUploadUserId(Long userId) {
|
||||
|
||||
@@ -50,6 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -283,6 +284,35 @@ class CcdiFileUploadServiceImplTest {
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteFileUploadRecord_shouldRejectNonParsedSuccessStatus() {
|
||||
CcdiFileUploadRecord record = buildRecord();
|
||||
record.setFileStatus("parsed_failed");
|
||||
when(recordMapper.selectById(RECORD_ID)).thenReturn(record);
|
||||
|
||||
RuntimeException exception = assertThrows(RuntimeException.class,
|
||||
() -> service.deleteFileUploadRecord(RECORD_ID, 9527L));
|
||||
|
||||
assertTrue(exception.getMessage().contains("仅支持删除解析成功文件"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteFileUploadRecord_shouldStopWhenLsfxDeleteFails() {
|
||||
CcdiFileUploadRecord record = buildRecord();
|
||||
record.setFileStatus("parsed_success");
|
||||
record.setLogId(LOG_ID);
|
||||
record.setLsfxProjectId(LSFX_PROJECT_ID);
|
||||
when(recordMapper.selectById(RECORD_ID)).thenReturn(record);
|
||||
when(lsfxClient.deleteFiles(any())).thenThrow(new RuntimeException("lsfx delete failed"));
|
||||
|
||||
assertThrows(RuntimeException.class, () -> service.deleteFileUploadRecord(RECORD_ID, 9527L));
|
||||
|
||||
verify(bankStatementMapper, never()).deleteByProjectIdAndBatchId(any(), any());
|
||||
verify(recordMapper, never()).updateById(org.mockito.ArgumentMatchers.<CcdiFileUploadRecord>argThat(item ->
|
||||
"deleted".equals(item.getFileStatus())
|
||||
));
|
||||
}
|
||||
|
||||
// @Test
|
||||
// void processPullBankInfoAsync_shouldMarkParsedFailedWhenFetchInnerFlowThrows() {
|
||||
// when(lsfxClient.fetchInnerFlow(any())).thenThrow(new RuntimeException("fetch inner flow failed"));
|
||||
|
||||
Reference in New Issue
Block a user