测试: 补充上传文件删除接口控制器契约
This commit is contained in:
@@ -163,4 +163,15 @@ public class CcdiFileUploadController extends BaseController {
|
|||||||
CcdiFileUploadRecord record = fileUploadService.getById(id);
|
CcdiFileUploadRecord record = fileUploadService.getById(id);
|
||||||
return AjaxResult.success(record);
|
return AjaxResult.success(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除上传记录
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
@Operation(summary = "删除上传文件", description = "按上传记录ID删除文件并清理流水")
|
||||||
|
public AjaxResult deleteFile(@PathVariable Long id) {
|
||||||
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
String message = fileUploadService.deleteFileUploadRecord(id, userId);
|
||||||
|
return AjaxResult.success(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ public interface ICcdiFileUploadService {
|
|||||||
Long userId,
|
Long userId,
|
||||||
String username);
|
String username);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除上传记录并清理关联数据
|
||||||
|
*
|
||||||
|
* @param id 上传记录ID
|
||||||
|
* @param operatorUserId 当前操作用户ID
|
||||||
|
* @return 删除结果
|
||||||
|
*/
|
||||||
|
String deleteFileUploadRecord(Long id, Long operatorUserId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询上传记录列表
|
* 查询上传记录列表
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -207,6 +207,11 @@ public class CcdiFileUploadServiceImpl implements ICcdiFileUploadService {
|
|||||||
return batchId;
|
return batchId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String deleteFileUploadRecord(Long id, Long operatorUserId) {
|
||||||
|
throw new UnsupportedOperationException("暂未实现删除上传记录");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<CcdiFileUploadRecord> selectPage(Page<CcdiFileUploadRecord> page,
|
public Page<CcdiFileUploadRecord> selectPage(Page<CcdiFileUploadRecord> page,
|
||||||
CcdiFileUploadQueryDTO queryDTO) {
|
CcdiFileUploadQueryDTO queryDTO) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.mockStatic;
|
import static org.mockito.Mockito.mockStatic;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -64,4 +65,19 @@ class CcdiFileUploadControllerTest {
|
|||||||
assertEquals(200, result.get("code"));
|
assertEquals(200, result.get("code"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteFile_shouldUseCurrentLoginUserId() {
|
||||||
|
try (MockedStatic<SecurityUtils> mocked = mockStatic(SecurityUtils.class)) {
|
||||||
|
mocked.when(SecurityUtils::getUserId).thenReturn(9527L);
|
||||||
|
when(fileUploadService.deleteFileUploadRecord(123L, 9527L))
|
||||||
|
.thenReturn("删除成功");
|
||||||
|
|
||||||
|
AjaxResult result = controller.deleteFile(123L);
|
||||||
|
|
||||||
|
assertEquals(200, result.get("code"));
|
||||||
|
assertEquals("删除成功", result.get("msg"));
|
||||||
|
verify(fileUploadService).deleteFileUploadRecord(123L, 9527L);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user