|
|
@@ -201,44 +201,50 @@ describe('File API Integration Tests', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- // describe('GET /api/v1/files/{id}/download', () => {
|
|
|
- // it('should generate file download URL successfully', async () => {
|
|
|
- // const mockDownloadInfo = {
|
|
|
- // url: 'https://minio.example.com/download-url',
|
|
|
- // filename: 'test.txt'
|
|
|
- // };
|
|
|
- // vi.mocked(mockFileService.getFileDownloadUrl).mockResolvedValue(mockDownloadInfo);
|
|
|
+ describe('GET /api/v1/files/{id}/download', () => {
|
|
|
+ it('should generate file download URL successfully', async () => {
|
|
|
+ const mockDownloadInfo = {
|
|
|
+ url: 'https://minio.example.com/download-url',
|
|
|
+ filename: 'test.txt'
|
|
|
+ };
|
|
|
+ const mockGetFileDownloadUrl = vi.fn().mockResolvedValue(mockDownloadInfo);
|
|
|
+ vi.mocked(FileService).mockImplementation(() => ({
|
|
|
+ getFileDownloadUrl: mockGetFileDownloadUrl
|
|
|
+ } as unknown as FileService));
|
|
|
|
|
|
- // const response = await client.files[':id']['download'].$get({
|
|
|
- // param: { id: 1 }
|
|
|
- // },
|
|
|
- // {
|
|
|
- // headers: {
|
|
|
- // 'Authorization': 'Bearer test-token'
|
|
|
- // }
|
|
|
- // });
|
|
|
+ const response = await client.files[':id']['download'].$get({
|
|
|
+ param: { id: 1 }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': 'Bearer test-token'
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // expect(response.status).toBe(200);
|
|
|
- // const result = await response.json();
|
|
|
- // expect(result).toEqual(mockDownloadInfo);
|
|
|
- // expect(mockFileService.getFileDownloadUrl).toHaveBeenCalledWith(1);
|
|
|
- // });
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+ const result = await response.json();
|
|
|
+ expect(result).toEqual(mockDownloadInfo);
|
|
|
+ expect(mockGetFileDownloadUrl).toHaveBeenCalledWith(1);
|
|
|
+ });
|
|
|
|
|
|
- // it('should return 404 when file not found for download', async () => {
|
|
|
- // vi.mocked(mockFileService.getFileDownloadUrl).mockRejectedValue(new Error('文件不存在'));
|
|
|
+ it('should return 404 when file not found for download', async () => {
|
|
|
+ const mockGetFileDownloadUrl = vi.fn().mockRejectedValue(new Error('文件不存在'));
|
|
|
+ vi.mocked(FileService).mockImplementation(() => ({
|
|
|
+ getFileDownloadUrl: mockGetFileDownloadUrl
|
|
|
+ } as unknown as FileService));
|
|
|
|
|
|
- // const response = await client.files[':id']['download'].$get({
|
|
|
- // param: { id: 999 }
|
|
|
- // },
|
|
|
- // {
|
|
|
- // headers: {
|
|
|
- // 'Authorization': 'Bearer test-token'
|
|
|
- // }
|
|
|
- // });
|
|
|
+ const response = await client.files[':id']['download'].$get({
|
|
|
+ param: { id: 999 }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': 'Bearer test-token'
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // expect(response.status).toBe(404);
|
|
|
- // });
|
|
|
- // });
|
|
|
+ expect(response.status).toBe(404);
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
// describe('DELETE /api/v1/files/{id}', () => {
|
|
|
// it('should delete file successfully', async () => {
|