import { describe, expect, test, beforeAll } from 'bun:test';
import { TemplateLoader } from '../src/services/template-loader';
describe('TemplateLoader', () => {
let loader: TemplateLoader;
beforeAll(() => {
loader = new TemplateLoader();
});
test('should load templates from repository', async () => {
const templates = await loader.loadTemplates();
expect(templates).toBeDefined();
expect(Array.isArray(templates)).toBe(true);
expect(templates.length).toBeGreaterThan(0);
});
test('each template should have required properties', async () => {
const templates = await loader.loadTemplates();
for (const template of templates.slice(0, 5)) {
expect(template.name).toBeDefined();
expect(typeof template.name).toBe('string');
expect(template.content).toBeDefined();
expect(typeof template.content).toBe('string');
expect(template.category).toBeDefined();
expect(['agent', 'system', 'tool', 'reminder', 'skill']).toContain(template.category);
}
});
test('should filter templates by category', async () => {
const agentTemplates = await loader.getTemplatesByCategory('agent');
expect(agentTemplates).toBeDefined();
for (const template of agentTemplates) {
expect(template.category).toBe('agent');
}
});
test('should return all templates when category is "any"', async () => {
const allTemplates = await loader.loadTemplates();
const anyTemplates = await loader.getTemplatesByCategory('any');
expect(anyTemplates.length).toBe(allTemplates.length);
});
test('should get template by name', async () => {
const templates = await loader.loadTemplates();
const firstTemplate = templates[0];
const found = await loader.getTemplateByName(firstTemplate.name);
expect(found).toBeDefined();
expect(found?.name).toBe(firstTemplate.name);
});
test('should return undefined for non-existent template', async () => {
const found = await loader.getTemplateByName('non-existent-template-xyz');
expect(found).toBeUndefined();
});
test('should return template counts by category', async () => {
const counts = await loader.getTemplateCounts();
expect(counts).toBeDefined();
expect(typeof counts).toBe('object');
// Should have at least some categories
const categoryCount = Object.keys(counts).length;
expect(categoryCount).toBeGreaterThan(0);
// Each count should be a positive number
for (const count of Object.values(counts)) {
expect(typeof count).toBe('number');
expect(count).toBeGreaterThan(0);
}
});
});