|
|
@@ -4,6 +4,7 @@ import {
|
|
|
IntegrationTestDatabase,
|
|
|
TestDataFactory
|
|
|
} from '../../../__test_utils__/integration-test-db';
|
|
|
+import { UserEntity } from '../../../modules/users/user.entity';
|
|
|
import { authRoutes } from '../../../api';
|
|
|
import { AuthService } from '../../../modules/auth/auth.service';
|
|
|
import { UserService } from '../../../modules/users/user.service';
|
|
|
@@ -40,7 +41,10 @@ describe('认证API集成测试 (使用hono/testing)', () => {
|
|
|
userService = new UserService(dataSource);
|
|
|
authService = new AuthService(userService);
|
|
|
|
|
|
- // 创建测试用户
|
|
|
+ // 创建测试用户前先删除可能存在的重复用户
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
+ await userRepository.delete({ username: 'testuser' });
|
|
|
+
|
|
|
testUser = await TestDataFactory.createTestUser(dataSource, {
|
|
|
username: 'testuser',
|
|
|
password: 'TestPassword123!',
|
|
|
@@ -113,6 +117,10 @@ describe('认证API集成测试 (使用hono/testing)', () => {
|
|
|
const dataSource = IntegrationTestDatabase.getDataSource();
|
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
|
|
|
|
+ // 先删除可能存在的重复用户
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
+ await userRepository.delete({ username: 'disabled_user' });
|
|
|
+
|
|
|
const disabledUser = await TestDataFactory.createTestUser(dataSource, {
|
|
|
username: 'disabled_user',
|
|
|
password: 'TestPassword123!',
|
|
|
@@ -292,6 +300,10 @@ describe('认证API集成测试 (使用hono/testing)', () => {
|
|
|
const dataSource = IntegrationTestDatabase.getDataSource();
|
|
|
if (!dataSource) throw new Error('Database not initialized');
|
|
|
|
|
|
+ // 先删除可能存在的重复用户
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
+ await userRepository.delete({ username: 'regular_user' });
|
|
|
+
|
|
|
const regularUser = await TestDataFactory.createTestUser(dataSource, {
|
|
|
username: 'regular_user',
|
|
|
password: 'TestPassword123!',
|