|
|
@@ -1,8 +1,9 @@
|
|
|
-import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
|
+import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
|
|
import { testClient } from 'hono/testing';
|
|
|
import { authRoutes } from '../../src/routes';
|
|
|
-import { AppDataSource } from '@d8d/shared-utils';
|
|
|
+import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '@d8d/shared-test-util';
|
|
|
import { UserEntity } from '@d8d/user-module';
|
|
|
+import { File } from '@d8d/file-module';
|
|
|
|
|
|
// Mock MiniAuthService 的 decryptPhoneNumber 方法
|
|
|
vi.mock('../../src/services/mini-auth.service', () => ({
|
|
|
@@ -32,10 +33,14 @@ vi.mock('@d8d/shared-utils', async (importOriginal) => {
|
|
|
...actual,
|
|
|
redisUtil: {
|
|
|
getSessionKey: vi.fn().mockResolvedValue('mock-session-key')
|
|
|
- }
|
|
|
+ },
|
|
|
+ ErrorSchema: actual.ErrorSchema // 确保ErrorSchema被正确导出
|
|
|
};
|
|
|
});
|
|
|
|
|
|
+// 设置集成测试钩子
|
|
|
+setupIntegrationDatabaseHooksWithEntities([UserEntity, File])
|
|
|
+
|
|
|
describe('手机号解密API集成测试', () => {
|
|
|
let client: ReturnType<typeof testClient<typeof authRoutes>>;
|
|
|
let testToken: string;
|
|
|
@@ -45,8 +50,11 @@ describe('手机号解密API集成测试', () => {
|
|
|
// 创建测试客户端
|
|
|
client = testClient(authRoutes);
|
|
|
|
|
|
+ // 获取数据源
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+
|
|
|
// 创建测试用户
|
|
|
- const userRepository = AppDataSource.getRepository(UserEntity);
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
testUser = userRepository.create({
|
|
|
username: `test_user_${Date.now()}`,
|
|
|
password: 'test_password',
|
|
|
@@ -91,7 +99,8 @@ describe('手机号解密API集成测试', () => {
|
|
|
}
|
|
|
|
|
|
// 验证数据库中的用户手机号已更新
|
|
|
- const userRepository = AppDataSource.getRepository(UserEntity);
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const userRepository = dataSource.getRepository(UserEntity);
|
|
|
const updatedUser = await userRepository.findOne({
|
|
|
where: { id: testUser.id }
|
|
|
});
|