|
|
@@ -1,36 +1,6 @@
|
|
|
import { DataSource } from 'typeorm';
|
|
|
-import { beforeEach, afterEach } from 'vitest';
|
|
|
import { UserEntity } from '../../src/entities/user.entity';
|
|
|
import { Role } from '../../src/entities/role.entity';
|
|
|
-import { AppDataSource, initializeDataSource } from '@d8d/shared-utils';
|
|
|
-
|
|
|
-/**
|
|
|
- * 集成测试数据库工具类 - 使用真实PostgreSQL数据库
|
|
|
- */
|
|
|
-export class IntegrationTestDatabase {
|
|
|
- /**
|
|
|
- * 清理集成测试数据库
|
|
|
- */
|
|
|
- static async cleanup(): Promise<void> {
|
|
|
- if (AppDataSource.isInitialized) {
|
|
|
- await AppDataSource.destroy();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取当前数据源
|
|
|
- */
|
|
|
- static async getDataSource(): Promise<DataSource> {
|
|
|
- if (!AppDataSource) {
|
|
|
- initializeDataSource([UserEntity, Role]);
|
|
|
- }
|
|
|
-
|
|
|
- if (!AppDataSource.isInitialized) {
|
|
|
- await AppDataSource.initialize();
|
|
|
- }
|
|
|
- return AppDataSource;
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
/**
|
|
|
* 测试数据工厂类
|
|
|
@@ -87,17 +57,4 @@ export class TestDataFactory {
|
|
|
const role = roleRepository.create(roleData);
|
|
|
return await roleRepository.save(role);
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 集成测试数据库生命周期钩子
|
|
|
- */
|
|
|
-export function setupIntegrationDatabaseHooks() {
|
|
|
- beforeEach(async () => {
|
|
|
- await IntegrationTestDatabase.getDataSource();
|
|
|
- });
|
|
|
-
|
|
|
- afterEach(async () => {
|
|
|
- await IntegrationTestDatabase.cleanup();
|
|
|
- });
|
|
|
}
|