|
|
@@ -1,4 +1,4 @@
|
|
|
-import { describe, it, expect, beforeEach } from 'vitest';
|
|
|
+import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
|
import { testClient } from 'hono/testing';
|
|
|
import {
|
|
|
IntegrationTestDatabase,
|
|
|
@@ -13,6 +13,35 @@ import { UserEntity, Role } from '@d8d/user-module';
|
|
|
import { TestDataFactory } from '../utils/integration-test-db';
|
|
|
import { AuthService } from '@d8d/auth-module';
|
|
|
import { UserService } from '@d8d/user-module';
|
|
|
+import { MinioService } from '../../src/services/minio.service';
|
|
|
+
|
|
|
+// Mock MinIO service to avoid real connections in tests
|
|
|
+vi.mock('../../src/services/minio.service', () => {
|
|
|
+ const MockMinioService = vi.fn(() => ({
|
|
|
+ bucketName: 'test-bucket',
|
|
|
+ ensureBucketExists: vi.fn().mockResolvedValue(true),
|
|
|
+ objectExists: vi.fn().mockResolvedValue(false), // Assume files don't exist in MinIO for tests
|
|
|
+ deleteObject: vi.fn().mockResolvedValue(undefined),
|
|
|
+ generateUploadPolicy: vi.fn().mockResolvedValue({
|
|
|
+ 'x-amz-algorithm': 'AWS4-HMAC-SHA256',
|
|
|
+ 'x-amz-credential': 'test-credential',
|
|
|
+ 'x-amz-date': '20230101T000000Z',
|
|
|
+ policy: 'test-policy',
|
|
|
+ 'x-amz-signature': 'test-signature',
|
|
|
+ host: 'http://localhost:9000',
|
|
|
+ key: 'test-key',
|
|
|
+ bucket: 'test-bucket'
|
|
|
+ }),
|
|
|
+ getPresignedFileUrl: vi.fn().mockResolvedValue('http://localhost:9000/test-bucket/test-file'),
|
|
|
+ getPresignedFileDownloadUrl: vi.fn().mockResolvedValue('http://localhost:9000/test-bucket/test-file?download=true'),
|
|
|
+ createMultipartUpload: vi.fn().mockResolvedValue('test-upload-id'),
|
|
|
+ generateMultipartUploadUrls: vi.fn().mockResolvedValue(['http://localhost:9000/part1', 'http://localhost:9000/part2']),
|
|
|
+ completeMultipartUpload: vi.fn().mockResolvedValue({ size: 1024 }),
|
|
|
+ createObject: vi.fn().mockResolvedValue('http://localhost:9000/test-bucket/test-file'),
|
|
|
+ getFileUrl: vi.fn().mockReturnValue('http://localhost:9000/test-bucket/test-file')
|
|
|
+ }));
|
|
|
+ return { MinioService: MockMinioService };
|
|
|
+});
|
|
|
|
|
|
// 设置集成测试钩子
|
|
|
setupIntegrationDatabaseHooksWithEntities([File, UserEntity, Role])
|