import { describe, expect, test, beforeAll } from 'bun:test';
import { CustomTemplatesService } from '../src/services/custom-templates';
describe('CustomTemplatesService', () => {
let service: CustomTemplatesService;
beforeAll(() => {
service = new CustomTemplatesService();
});
test('should load custom templates without errors', async () => {
const templates = await service.loadTemplates();
expect(templates).toBeDefined();
expect(Array.isArray(templates)).toBe(true);
// May be empty if no custom templates exist
});
test('should infer category correctly', async () => {
// Test internal method behavior by checking template categories
const templates = await service.loadTemplates();
for (const template of templates) {
expect(['agent', 'system', 'tool', 'reminder', 'skill']).toContain(template.category);
}
});
test('should reload templates', async () => {
const templates1 = await service.loadTemplates();
const templates2 = await service.reload();
expect(Array.isArray(templates1)).toBe(true);
expect(Array.isArray(templates2)).toBe(true);
});
test('should search templates by query', async () => {
const templates = await service.loadTemplates();
if (templates.length > 0) {
const firstTemplate = templates[0];
const results = await service.searchTemplates(firstTemplate.name);
expect(results.length).toBeGreaterThan(0);
}
});
test('should filter search by category', async () => {
const results = await service.searchTemplates('test', 'agent');
for (const template of results) {
expect(template.category).toBe('agent');
}
});
test('getTemplatesWithPriority should prefix custom templates', async () => {
const templates = await service.getTemplatesWithPriority();
for (const template of templates) {
expect(template.name.startsWith('[custom]')).toBe(true);
}
});
});