|
|
@@ -1,18 +1,15 @@
|
|
|
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
|
|
import { testClient } from 'hono/testing';
|
|
|
import { DataSource } from 'typeorm';
|
|
|
-import { File } from '@/server/modules/files/file.entity';
|
|
|
import { FileService } from '@/server/modules/files/file.service';
|
|
|
import { authMiddleware } from '@/server/middleware/auth.middleware';
|
|
|
import { fileApiRoutes } from '@/server/api';
|
|
|
|
|
|
vi.mock('@/server/modules/files/file.service');
|
|
|
-// vi.mock('@/server/modules/files/minio.service');
|
|
|
vi.mock('@/server/middleware/auth.middleware');
|
|
|
|
|
|
describe('File API Integration Tests', () => {
|
|
|
let client: ReturnType<typeof testClient<typeof fileApiRoutes>>['api']['v1'];
|
|
|
- // let mockFileService: FileService;
|
|
|
let mockDataSource: DataSource;
|
|
|
const user1 = {
|
|
|
id: 1,
|
|
|
@@ -91,8 +88,9 @@ describe('File API Integration Tests', () => {
|
|
|
};
|
|
|
|
|
|
|
|
|
+ const mockCreateFile = vi.fn().mockResolvedValue(mockResponse);
|
|
|
vi.mocked(FileService).mockImplementation(() => ({
|
|
|
- createFile: vi.fn().mockResolvedValue(mockResponse)
|
|
|
+ createFile: mockCreateFile
|
|
|
} as unknown as FileService));
|
|
|
const response = await client.files['upload-policy'].$post({
|
|
|
json: mockFileData
|
|
|
@@ -111,7 +109,11 @@ describe('File API Integration Tests', () => {
|
|
|
expect(response.status).toBe(200);
|
|
|
const result = await response.json();
|
|
|
expect(result).toEqual(mockResponse);
|
|
|
- // expect(mockFileService.createFile).toHaveBeenCalledWith(mockFileData);
|
|
|
+ expect(mockCreateFile).toHaveBeenCalledWith({
|
|
|
+ ...mockFileData,
|
|
|
+ uploadTime: expect.any(Date),
|
|
|
+ uploadUserId: 1
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
// it('should return 400 for invalid request data', async () => {
|