docs(zulip): 完善Zulip业务模块功能文档

范围: src/business/zulip/README.md
- 补充对外提供的接口章节(14个公共方法)
- 添加使用的项目内部依赖说明(7个依赖)
- 完善核心特性描述(5个特性)
- 添加潜在风险评估(4个风险及缓解措施)
- 优化文档结构和内容完整性
This commit is contained in:
moyin
2026-01-15 10:53:04 +08:00
parent 30a4a2813d
commit ed04b8c92d
32 changed files with 622 additions and 8886 deletions

View File

@@ -7,27 +7,33 @@
* - 测试真实的网络请求和响应处理
*
* 测试范围:
* - WebSocket → ZulipService → ZulipClientPool → ZulipClient → Zulip API
* - WebSocket → ChatService → ZulipClientPool → ZulipClient → Zulip API
*
* 更新记录:
* - 2026-01-14: 重构后更新 - 使用新的四层架构模块
* - ChatService 替代 ZulipService
* - ChatSessionService 替代 SessionManagerService
*
* @author moyin
* @version 1.0.0
* @version 2.0.0
* @since 2026-01-10
* @lastModified 2026-01-14
*/
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { ZulipService } from '../../src/business/zulip/zulip.service';
import { ChatService } from '../../src/business/chat/chat.service';
import { ChatSessionService } from '../../src/business/chat/services/chat_session.service';
import { ZulipClientPoolService } from '../../src/core/zulip_core/services/zulip_client_pool.service';
import { ZulipClientService, ZulipClientInstance } from '../../src/core/zulip_core/services/zulip_client.service';
import { SessionManagerService } from '../../src/business/zulip/services/session_manager.service';
import { AppModule } from '../../src/app.module';
describe('ChatMessage E2E Integration', () => {
let app: INestApplication;
let zulipService: ZulipService;
let chatService: ChatService;
let zulipClientPool: ZulipClientPoolService;
let zulipClient: ZulipClientService;
let sessionManager: SessionManagerService;
let sessionManager: ChatSessionService;
// 模拟的Zulip客户端
let mockZulipSdkClient: any;
@@ -48,11 +54,11 @@ describe('ChatMessage E2E Integration', () => {
app = moduleFixture.createNestApplication();
// 获取服务实例
zulipService = moduleFixture.get<ZulipService>(ZulipService);
// 获取服务实例(使用新的四层架构模块)
chatService = moduleFixture.get<ChatService>(ChatService);
zulipClientPool = moduleFixture.get<ZulipClientPoolService>(ZulipClientPoolService);
zulipClient = moduleFixture.get<ZulipClientService>(ZulipClientService);
sessionManager = moduleFixture.get<SessionManagerService>(SessionManagerService);
sessionManager = moduleFixture.get<ChatSessionService>(ChatSessionService);
await app.init();
});
@@ -110,7 +116,7 @@ describe('ChatMessage E2E Integration', () => {
describe('完整的聊天消息流程', () => {
it('应该成功处理从登录到消息发送的完整流程', async () => {
// 1. 模拟用户登录
const loginResult = await zulipService.handlePlayerLogin({
const loginResult = await chatService.handlePlayerLogin({
socketId: testSocketId,
token: 'valid-jwt-token', // 这里需要有效的JWT token
});
@@ -121,7 +127,7 @@ describe('ChatMessage E2E Integration', () => {
expect(loginResult.sessionId).toBeDefined();
// 2. 发送聊天消息
const chatResult = await zulipService.sendChatMessage({
const chatResult = await chatService.sendChatMessage({
socketId: testSocketId,
content: 'Hello from E2E test!',
scope: 'local',
@@ -153,7 +159,7 @@ describe('ChatMessage E2E Integration', () => {
);
// 发送消息
const chatResult = await zulipService.sendChatMessage({
const chatResult = await chatService.sendChatMessage({
socketId: testSocketId,
content: 'Hello from E2E test with mock session!',
scope: 'local',
@@ -175,7 +181,7 @@ describe('ChatMessage E2E Integration', () => {
);
// 测试本地消息
const localResult = await zulipService.sendChatMessage({
const localResult = await chatService.sendChatMessage({
socketId: testSocketId,
content: 'Local message test',
scope: 'local',
@@ -191,7 +197,7 @@ describe('ChatMessage E2E Integration', () => {
expect(localCall[0].to).toBe('Whale Port'); // 应该路由到地图对应的Stream
// 测试全局消息
const globalResult = await zulipService.sendChatMessage({
const globalResult = await chatService.sendChatMessage({
socketId: testSocketId,
content: 'Global message test',
scope: 'global',
@@ -218,7 +224,7 @@ describe('ChatMessage E2E Integration', () => {
);
// 测试正常消息
const normalResult = await zulipService.sendChatMessage({
const normalResult = await chatService.sendChatMessage({
socketId: testSocketId,
content: 'This is a normal message',
scope: 'local',
@@ -226,7 +232,7 @@ describe('ChatMessage E2E Integration', () => {
expect(normalResult.success).toBe(true);
// 测试空消息
const emptyResult = await zulipService.sendChatMessage({
const emptyResult = await chatService.sendChatMessage({
socketId: testSocketId,
content: '',
scope: 'local',
@@ -235,7 +241,7 @@ describe('ChatMessage E2E Integration', () => {
// 测试过长消息
const longMessage = 'A'.repeat(2000); // 假设限制是1000字符
const longResult = await zulipService.sendChatMessage({
const longResult = await chatService.sendChatMessage({
socketId: testSocketId,
content: longMessage,
scope: 'local',
@@ -262,7 +268,7 @@ describe('ChatMessage E2E Integration', () => {
code: 'STREAM_NOT_FOUND',
});
const result = await zulipService.sendChatMessage({
const result = await chatService.sendChatMessage({
socketId: testSocketId,
content: 'This message will fail',
scope: 'local',
@@ -286,7 +292,7 @@ describe('ChatMessage E2E Integration', () => {
// 模拟网络异常
mockZulipSdkClient.messages.send.mockRejectedValueOnce(new Error('Network timeout'));
const result = await zulipService.sendChatMessage({
const result = await chatService.sendChatMessage({
socketId: testSocketId,
content: 'This will timeout',
scope: 'local',
@@ -423,7 +429,7 @@ describe('ChatMessage E2E Integration', () => {
// 发送大量消息
const promises = Array.from({ length: messageCount }, (_, i) =>
zulipService.sendChatMessage({
chatService.sendChatMessage({
socketId: testSocketId,
content: `Performance test message ${i}`,
scope: 'local',
@@ -445,4 +451,4 @@ describe('ChatMessage E2E Integration', () => {
expect(avgTimePerMessage).toBeLessThan(100);
}, 30000);
});
});
});