test(chat): 修复测试文件Mock配置

范围: src/business/chat/
涉及文件:
- chat.module.spec.ts
- chat.service.spec.ts

主要改进:
- 添加缺失的ZulipAccountsService Mock配置
- 修复handlePlayerLogout测试,删除过时的deleteApiKey断言
- 删除不再需要的API Key清理失败测试用例
- 添加getUserClient Mock方法
- 设置默认Mock行为,提高测试稳定性
This commit is contained in:
moyin
2026-01-19 18:29:27 +08:00
parent 963e6ca90f
commit 1849415b11
2 changed files with 36 additions and 25 deletions

View File

@@ -7,9 +7,12 @@
* - 接口导出验证
*
* @author moyin
* @version 1.0.0
* @version 1.0.1
* @since 2026-01-14
* @lastModified 2026-01-14
* @lastModified 2026-01-19
*
* 修改记录:
* - 2026-01-19 moyin: Bug修复 - 添加缺失的ZulipAccountsService Mock配置
*/
import { Test, TestingModule } from '@nestjs/testing';
@@ -33,6 +36,7 @@ describe('ChatModule', () => {
createUserClient: jest.fn(),
destroyUserClient: jest.fn(),
sendMessage: jest.fn(),
getUserClient: jest.fn(),
};
const mockZulipConfigService = {
@@ -61,6 +65,10 @@ describe('ChatModule', () => {
verifyToken: jest.fn(),
};
const mockZulipAccountsService = {
findByGameUserId: jest.fn(),
};
beforeEach(async () => {
// 禁用日志输出
jest.spyOn(Logger.prototype, 'log').mockImplementation();
@@ -97,6 +105,10 @@ describe('ChatModule', () => {
provide: LoginCoreService,
useValue: mockLoginCoreService,
},
{
provide: 'ZulipAccountsService',
useValue: mockZulipAccountsService,
},
],
}).compile();