import { formatTemplateContent } from '../templateformatter.js';
describe('formatTemplateContent', () => {
it('should return an error when content is missing', () => {
expect(formatTemplateContent()).toEqual({
error: 'Content is required and must be a string.',
code: 400,
});
});
it('should return an error when content is not a string', () => {
expect(formatTemplateContent({ foo: 'bar' })).toEqual({
error: 'Content is required and must be a string.',
code: 400,
});
});
it('should return empty content unchanged', () => {
expect(formatTemplateContent('')).toEqual({ content: '' });
expect(formatTemplateContent(' ')).toEqual({ content: '' });
});
it('should format custom XML tags', () => {
const input = 'Hello';
const result = formatTemplateContent(input);
expect(result.content).toBe(`
Hello
`);
});
it('should format XML while preserving EJS blocks', () => {
const input =
'Hello<% if (name) { %><%= name %><% } %>';
const result = formatTemplateContent(input);
expect(result.content).toContain('');
expect(result.content).toContain('<% if (name) { %>');
expect(result.content).toContain('<%= name %>');
expect(result.content).toContain('<% } %>');
expect(result.content).toContain('');
});
it('should leave EJS comments unchanged', () => {
const input = '<%# comment %>';
const result = formatTemplateContent(input);
expect(result.content).toContain('<%# comment %>');
});
});