/**
* Token 认证测试
* 测试 Token 的获取、验证、更新等流程
*/
/// <reference path="../global.d.ts" />
describe('create_task Tool', () => {
beforeEach(() => {
global.testCache.clear();
});
test('should create new task successfully', async () => {
const newTask = {
name: generateTestName('测试任务'),
project: 2,
assignedTo: 's000001',
pri: 1,
estimate: 8
};
const result = await createTask(global.testClient, global.testCache, newTask);
expect(result).toBeDefined();
expect(result.isError).toBeFalsy();
const text = result.content[0].text;
expect(text).toContain('任务创建成功');
// 清理
const idMatch = text.match(/ID: (\d+)/);
if (idMatch) {
const taskId = parseInt(idMatch[1]);
try {
await global.testClient.delete(\`/api.php/v1/tasks/\${taskId}\`);
} catch (error) {}
}
console.log(`✅ Created task successfully`);
});
test('should validate required fields', async () => {
const result = await createTask(global.testClient, global.testCache, {
name: generateTestName('缺少项目')
} as any);
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain('必填');
console.log(`✅ Required field validation working`);
});
test('should clear cache after creation', async () => {
global.testCache.set('tasks:{"projectId":2}', 'data', 5 * 60 * 1000);
const result = await createTask(global.testClient, global.testCache, {
name: generateTestName('缓存测试任务'),
project: 2,
assignedTo: 's000001'
});
if (!result.isError) {
expect(global.testCache.get('tasks:{"projectId":2}')).toBeUndefined();
}
console.log(`✅ Cache cleared after task creation`);
});
});