|
|
@@ -161,41 +161,50 @@ describe('File API Integration Tests', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- // describe('GET /api/v1/files/{id}/url', () => {
|
|
|
- // it('should generate file access URL successfully', async () => {
|
|
|
- // const mockUrl = 'https://minio.example.com/presigned-url';
|
|
|
- // vi.mocked(mockFileService.getFileUrl).mockResolvedValue(mockUrl);
|
|
|
+ describe('GET /api/v1/files/{id}/url', () => {
|
|
|
+ it('should generate file access URL successfully', async () => {
|
|
|
+ const mockUrl = 'https://minio.example.com/presigned-url';
|
|
|
+ const mockGetFileUrl = vi.fn().mockResolvedValue(mockUrl);
|
|
|
+ vi.mocked(FileService).mockImplementation(() => ({
|
|
|
+ getFileUrl: mockGetFileUrl
|
|
|
+ } as unknown as FileService));
|
|
|
|
|
|
- // const response = await client.files[':id']['url'].$get({
|
|
|
- // param: { id: 1 }
|
|
|
- // },
|
|
|
- // {
|
|
|
- // headers: {
|
|
|
- // 'Authorization': 'Bearer test-token'
|
|
|
- // }
|
|
|
- // });
|
|
|
+ const response = await client.files[':id']['url'].$get({
|
|
|
+ param: { id: 1 }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': 'Bearer test-token'
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // expect(response.status).toBe(200);
|
|
|
- // const result = await response.json();
|
|
|
- // expect(result).toEqual({ url: mockUrl });
|
|
|
- // expect(mockFileService.getFileUrl).toHaveBeenCalledWith(1);
|
|
|
- // });
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+ const result = await response.json();
|
|
|
+ console.debug('Response result:', JSON.stringify(result));
|
|
|
+ expect(result).toEqual({ url: mockUrl });
|
|
|
+ });
|
|
|
|
|
|
- // it('should return 404 when file not found', async () => {
|
|
|
- // vi.mocked(mockFileService.getFileUrl).mockRejectedValue(new Error('文件不存在'));
|
|
|
+ it('should return 404 when file not found', async () => {
|
|
|
+ const mockGetFileUrl = vi.fn().mockRejectedValue(new Error('文件不存在'));
|
|
|
+ vi.mocked(FileService).mockImplementation(() => ({
|
|
|
+ getFileUrl: mockGetFileUrl
|
|
|
+ } as unknown as FileService));
|
|
|
|
|
|
- // const response = await client.files[':id']['url'].$get({
|
|
|
- // param: { id: 999 }
|
|
|
- // },
|
|
|
- // {
|
|
|
- // headers: {
|
|
|
- // 'Authorization': 'Bearer test-token'
|
|
|
- // }
|
|
|
- // });
|
|
|
+ const response = await client.files[':id']['url'].$get({
|
|
|
+ param: { id: 999 }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': 'Bearer test-token'
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // expect(response.status).toBe(404);
|
|
|
- // });
|
|
|
- // });
|
|
|
+ console.debug('Response status:', response.status);
|
|
|
+ const result = await response.json();
|
|
|
+ console.debug('Response result:', JSON.stringify(result));
|
|
|
+ expect(response.status).toBe(404);
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
// describe('GET /api/v1/files/{id}/download', () => {
|
|
|
// it('should generate file download URL successfully', async () => {
|