|
|
@@ -1,4 +1,4 @@
|
|
|
-import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
|
|
|
+import { describe, it, expect, beforeEach, afterEach, beforeAll } from 'vitest';
|
|
|
import { DataSource } from 'typeorm';
|
|
|
import { UserService } from '../../src/services/user.service';
|
|
|
import { RoleService } from '../../src/services/role.service';
|
|
|
@@ -6,15 +6,24 @@ import { UserEntity } from '../../src/entities/user.entity';
|
|
|
import { Role } from '../../src/entities/role.entity';
|
|
|
import { AppDataSource, initializeDataSource } from '@d8d/shared-utils';
|
|
|
|
|
|
+// 确保测试环境变量被设置
|
|
|
+process.env.NODE_ENV = 'test';
|
|
|
+
|
|
|
describe('User Integration Tests', () => {
|
|
|
let dataSource: DataSource;
|
|
|
let userService: UserService;
|
|
|
let roleService: RoleService;
|
|
|
|
|
|
- beforeEach(async () => {
|
|
|
+ beforeAll(() => {
|
|
|
+ // 使用预先配置的数据源
|
|
|
initializeDataSource([UserEntity, Role])
|
|
|
dataSource = AppDataSource;
|
|
|
- await dataSource.initialize();
|
|
|
+ })
|
|
|
+
|
|
|
+ beforeEach(async () => {
|
|
|
+ if (!dataSource.isInitialized) {
|
|
|
+ await dataSource.initialize();
|
|
|
+ }
|
|
|
userService = new UserService(dataSource);
|
|
|
roleService = new RoleService(dataSource);
|
|
|
});
|