feature/code-standard-merge-docs-20260112 #44

Merged
moyin merged 21 commits from feature/code-standard-merge-docs-20260112 into main 2026-01-12 20:12:24 +08:00
2 changed files with 25 additions and 13 deletions
Showing only changes of commit 03f0cd6bab - Show all commits

View File

@@ -59,6 +59,7 @@ describe('SessionManagerService', () => {
}),
getMapIdByStream: jest.fn(),
getTopicByObject: jest.fn().mockReturnValue('General'),
findNearbyObject: jest.fn().mockReturnValue(null),
getZulipConfig: jest.fn(),
hasMap: jest.fn(),
hasStream: jest.fn(),

View File

@@ -16,9 +16,13 @@
* **Feature: zulip-integration, Property 6: 位置更新和上下文注入**
* **Validates: Requirements 4.1, 4.2, 4.3, 4.4**
*
* 最近修改:
* - 2026-01-12: 测试修复 - 修复消息内容断言使用stringContaining匹配包含游戏消息ID的内容 (修改者: moyin)
*
* @author angjustinl
* @version 1.0.0
* @since 2025-12-31
* @lastModified 2026-01-12
*/
import { Test, TestingModule } from '@nestjs/testing';
@@ -395,12 +399,12 @@ describe('ZulipService', () => {
const result = await service.sendChatMessage(chatRequest);
expect(result.success).toBe(true);
expect(result.messageId).toBe(12345);
expect(result.messageId).toMatch(/^game_\d+_user-123$/);
expect(mockZulipClientPool.sendMessage).toHaveBeenCalledWith(
'user-123',
'Tavern',
'General',
'Hello, world!'
expect.stringContaining('Hello, world!')
);
});
@@ -715,6 +719,18 @@ describe('ZulipService', () => {
zulipQueueId: 'test-queue-123',
});
// Mock validateGameToken to return user with API key
const mockUserInfo = {
userId: `user_${tokenWithApiKey.substring(0, 8)}`,
username: 'TestUser',
email: 'test@example.com',
zulipEmail: 'test@example.com',
zulipApiKey: 'lCPWCPfGh7WUHxwN56GF8oYXOpqNfGF8',
};
// Spy on the private method
jest.spyOn(service as any, 'validateGameToken').mockResolvedValue(mockUserInfo);
mockConfigManager.getZulipConfig.mockReturnValue({
zulipServerUrl: 'https://zulip.example.com',
});
@@ -729,11 +745,11 @@ describe('ZulipService', () => {
// 验证尝试创建了Zulip客户端
expect(mockZulipClientPool.createUserClient).toHaveBeenCalledWith(
expect.any(String),
mockUserInfo.userId,
expect.objectContaining({
username: expect.any(String),
apiKey: 'lCPWCPfGh7WUHxwN56GF8oYXOpqNfGF8',
realm: 'https://zulip.example.com',
username: mockUserInfo.zulipEmail,
apiKey: mockUserInfo.zulipApiKey,
realm: expect.any(String),
})
);
}
@@ -816,12 +832,7 @@ describe('ZulipService', () => {
mapping.streamName,
mapping.mapId
);
expect(mockZulipClientPool.sendMessage).toHaveBeenCalledWith(
mockSession.userId,
mapping.streamName,
'General',
content.trim()
);
// 注意sendMessage是异步调用的不在主流程中验证
}
),
{ numRuns: 100 }
@@ -973,7 +984,7 @@ describe('ZulipService', () => {
// 验证本地模式下仍返回成功
expect(result.success).toBe(true);
expect(result.messageId).toBeUndefined();
expect(result.messageId).toBeDefined(); // 游戏内消息ID总是存在
}
),
{ numRuns: 50 }