Skip to content

Commit 46ed549

Browse files
author
王允
committed
单测问题修复
1 parent 863c0b7 commit 46ed549

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

tests/channels/feishu.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ describe('FeishuChannel', () => {
4242
it('should include correct title with date', () => {
4343
const repositories: RepositoryInfo[] = [];
4444
const card = FeishuChannel.buildCard(repositories, []);
45+
const card2 = FeishuChannel.buildCard(repositories, [], 'daily');
46+
const card3 = FeishuChannel.buildCard(repositories, [], 'weekly');
4547

4648
const title = card.header?.title;
49+
const title2 = card2.header?.title;
50+
const title3 = card3.header?.title;
4751
expect(title).toBeDefined();
48-
expect(title?.content).toContain('GitHub 热榜推送');
52+
expect(title?.content).toContain('GitHub 本月热榜推送');
53+
expect(title2?.content).toContain('GitHub 今日热榜推送');
54+
expect(title3?.content).toContain('GitHub 本周热榜推送');
4955
});
5056

5157
it('should build card with both new and seen repositories', () => {
@@ -112,14 +118,16 @@ describe('FeishuChannel', () => {
112118
url: 'https://github.com/org/desc-repo',
113119
stars: 100,
114120
description: 'This is a detailed description with multiple lines. It contains important information about the repository. Lines 3 of description.',
121+
ai_summary: 'AI generated summary for this repository with important details about its features and usage.',
115122
language: 'Rust'
116123
}
117124
];
118125

119-
const card = FeishuChannel.buildCard(repositories, []);
126+
const card = FeishuChannel.buildCard(repositories, [], 'monthly');
120127
const cardContent = JSON.stringify(card);
121128

122-
expect(cardContent).toContain('This is a detailed description');
129+
// 新项目会显示 AI summary
130+
expect(cardContent).toContain('AI generated summary');
123131
});
124132

125133
it('should include language tag when available', () => {

tests/core/fetcher.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('GitHubFetcher', () => {
111111

112112
const repos = await fetcher.fetchTrending('daily');
113113

114-
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=daily', expect.any(Object));
114+
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=daily');
115115
expect(Array.isArray(repos)).toBe(true);
116116
});
117117

@@ -127,7 +127,7 @@ describe('GitHubFetcher', () => {
127127

128128
const repos = await fetcher.fetchTrending('weekly');
129129

130-
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=weekly', expect.any(Object));
130+
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=weekly');
131131
expect(Array.isArray(repos)).toBe(true);
132132
});
133133

@@ -143,7 +143,7 @@ describe('GitHubFetcher', () => {
143143

144144
const repos = await fetcher.fetchTrending('monthly');
145145

146-
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=monthly', expect.any(Object));
146+
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=monthly');
147147
expect(Array.isArray(repos)).toBe(true);
148148
});
149149

@@ -160,7 +160,7 @@ describe('GitHubFetcher', () => {
160160
});
161161

162162
await expect(fetcher.fetchTrending('daily')).rejects.toThrow('Failed to fetch trending page');
163-
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=daily', expect.any(Object));
163+
expect(mockInstance.get).toHaveBeenCalledWith('https://github.com/trending?since=daily');
164164
});
165165

166166
it('should throw error for network failure', async () => {

tests/tool.test.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ let currentHistoryData: HistoryData | null = null;
2121

2222
// Create the mock history manager - this will be called in beforeEach
2323
function createMockHistoryManager() {
24+
const mockData = {
25+
repositories: {},
26+
last_updated: new Date().toISOString()
27+
};
28+
2429
return {
30+
data: mockData,
2531
categorizeRepositories: jest.fn((repos: RepositoryInfo[], config: any) => {
2632
const newlySeen: RepositoryInfo[] = [];
2733
const shouldPush: RepositoryInfo[] = [];
@@ -52,10 +58,17 @@ function createMockHistoryManager() {
5258
}),
5359
importData: jest.fn((data: HistoryData) => {
5460
currentHistoryData = data;
61+
mockData.repositories = data.repositories;
5562
}),
5663
exportData: jest.fn(),
5764
updateAiSummary: jest.fn(),
58-
clear: jest.fn()
65+
clear: jest.fn(),
66+
getStats: jest.fn(() => ({
67+
total_repositories: 0,
68+
total_pushes: 0,
69+
oldest_entry: undefined,
70+
newest_entry: undefined
71+
}))
5972
};
6073
}
6174

@@ -101,7 +114,7 @@ describe('githubTrendingTool', () => {
101114

102115
describe('tool definition', () => {
103116
it('should have correct name', () => {
104-
expect(toolModule.githubTrendingTool.name).toBe('github-trending');
117+
expect(toolModule.githubTrendingTool.name).toBe('openclaw-github-trending');
105118
});
106119

107120
it('should have correct description', () => {
@@ -116,13 +129,14 @@ describe('githubTrendingTool', () => {
116129

117130
const props = params.properties as any;
118131
expect(props.since).toBeDefined();
119-
expect(props.channel).toBeDefined();
132+
expect(props.channels).toBeDefined();
120133

121134
// Verify since enum values
122135
expect(props.since.enum).toEqual(['daily', 'weekly', 'monthly']);
123136

124-
// Verify channel enum values
125-
expect(props.channel.enum).toEqual(['feishu', 'email']);
137+
// Verify channels array items
138+
expect(props.channels.type).toBe('array');
139+
expect(props.channels.items.enum).toEqual(['feishu', 'email']);
126140
});
127141
});
128142

tests/utils/logger.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Logger } from '../../src/utils/logger';
1+
import { Logger, LogLevel } from '../../src/utils/logger';
22

33
describe('Logger', () => {
44
let originalConsole: any;
@@ -21,7 +21,7 @@ describe('Logger', () => {
2121
describe('constructor', () => {
2222
it('should create logger with default prefix when none provided', () => {
2323
const logger = new Logger();
24-
expect(logger.getPrefix()).toBe('[Logger]');
24+
expect(logger.getPrefix()).toBe('[App]');
2525
});
2626

2727
it('should create logger with custom prefix', () => {
@@ -33,6 +33,7 @@ describe('Logger', () => {
3333
describe('debug', () => {
3434
it('should log debug message with prefix', () => {
3535
const logger = new Logger('Test');
36+
logger.setLogLevel(LogLevel.DEBUG); // Enable debug level
3637
const message = 'Debug message';
3738
logger.debug(message);
3839

@@ -42,6 +43,7 @@ describe('Logger', () => {
4243

4344
it('should log message with multiple arguments', () => {
4445
const logger = new Logger();
46+
logger.setLogLevel(LogLevel.DEBUG); // Enable debug level
4547
logger.debug('Object:', { key: 'value' }, 'Array:', [1, 2, 3]);
4648

4749
// Check that console.log was called with arguments containing the expected content
@@ -147,6 +149,10 @@ describe('Logger', () => {
147149
describe('static methods', () => {
148150
describe('Logger.debug', () => {
149151
it('should log static debug message', () => {
152+
// Static methods use 'App' logger, set its level to debug
153+
const appLogger = Logger.get('App');
154+
appLogger.setLogLevel(LogLevel.DEBUG);
155+
150156
Logger.debug('Static debug message');
151157

152158
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('[DEBUG]'));

0 commit comments

Comments
 (0)