|
|
@@ -1,5 +1,6 @@
|
|
|
import { DataSource } from 'typeorm';
|
|
|
import { File } from '../../src/entities';
|
|
|
+import { UserEntity } from '@d8d/user-module';
|
|
|
|
|
|
/**
|
|
|
* 测试数据工厂类
|
|
|
@@ -22,6 +23,24 @@ export class TestDataFactory {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建测试用户数据
|
|
|
+ */
|
|
|
+ static createUserData(overrides: Partial<UserEntity> = {}): Partial<UserEntity> {
|
|
|
+ const timestamp = Date.now();
|
|
|
+ return {
|
|
|
+ username: `testuser_${timestamp}`,
|
|
|
+ password: 'TestPassword123!',
|
|
|
+ email: `test_${timestamp}@example.com`,
|
|
|
+ phone: `138${timestamp.toString().slice(-8)}`,
|
|
|
+ nickname: `Test User ${timestamp}`,
|
|
|
+ name: `Test Name ${timestamp}`,
|
|
|
+ isDisabled: 0,
|
|
|
+ isDeleted: 0,
|
|
|
+ ...overrides
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 在数据库中创建测试文件
|
|
|
*/
|
|
|
@@ -32,4 +51,15 @@ export class TestDataFactory {
|
|
|
const file = fileRepository.create(fileData);
|
|
|
return await fileRepository.save(file);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在数据库中创建测试用户
|
|
|
+ */
|
|
|
+ static async createTestUser(dataSource: DataSource, overrides: Partial<UserEntity> = {}): Promise<UserEntity> {
|
|
|
+ const userData = this.createUserData(overrides);
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
+
|
|
|
+ const user = userRepository.create(userData);
|
|
|
+ return await userRepository.save(user);
|
|
|
+ }
|
|
|
}
|