import { describe, expect, test } from 'bun:test';
import { listTemplates } from '../src/tools/list-templates';
describe('listTemplates tool', () => {
test('should list all templates', async () => {
const result = await listTemplates({});
expect(result).toBeDefined();
expect(result.total_count).toBeGreaterThan(0);
expect(result.by_category).toBeDefined();
expect(Array.isArray(result.templates)).toBe(true);
});
test('should filter by category', async () => {
const result = await listTemplates({ category: 'agent' });
expect(result).toBeDefined();
for (const template of result.templates) {
// Account for custom templates that might not match
if (!template.is_custom) {
expect(template.category).toBe('agent');
}
}
});
test('should search templates', async () => {
const result = await listTemplates({ search: 'code' });
expect(result).toBeDefined();
// Some templates should match 'code' search
expect(result.templates.length).toBeGreaterThanOrEqual(0);
});
test('should include custom templates by default', async () => {
const withCustom = await listTemplates({ include_custom: true });
const withoutCustom = await listTemplates({ include_custom: false });
// Without custom should have same or fewer templates
expect(withoutCustom.total_count).toBeLessThanOrEqual(withCustom.total_count);
});
test('each template should have required fields', async () => {
const result = await listTemplates({});
for (const template of result.templates.slice(0, 5)) {
expect(template.name).toBeDefined();
expect(template.category).toBeDefined();
expect(template.purpose).toBeDefined();
expect(template.complexity).toBeDefined();
expect(typeof template.is_custom).toBe('boolean');
}
});
});