receipt-printer/tests/schema.test.ts

58 lines
1.6 KiB
TypeScript

import { describe, it, expect } from 'bun:test';
import { extractSchema } from '../src/engine/schema';
import type { Template } from '../src/types/template';
describe('Schema Extractor', () => {
it('should extract simple variables', () => {
const template: Template = {
id: 'test',
name: 'Test',
width: '80mm',
blocks: [
{ type: 'text', content: 'Hello {{name}}' },
{ type: 'text', content: 'Date: {{date}}' }
]
};
const { schema } = extractSchema(template);
expect(schema.properties.name).toEqual({ type: 'string', description: 'name' });
expect(schema.properties.date).toEqual({ type: 'string', description: 'date' });
});
it('should extract list variables', () => {
const template: Template = {
id: 'test',
name: 'Test',
width: '80mm',
blocks: [
{
type: 'list',
data: '{{items}}',
itemTemplate: [
{ type: 'text', content: '{{title}}' }
]
}
]
};
const { schema } = extractSchema(template);
expect(schema.properties.items).toEqual({ type: 'array', description: 'items list' });
expect(schema.properties.title).toEqual({ type: 'string', description: 'title' });
});
it('should generate example data', () => {
const template: Template = {
id: 'test',
name: 'Test',
width: '80mm',
blocks: [
{ type: 'text', content: '{{name}} - {{count}}' }
]
};
const { example } = extractSchema(template);
expect(example).toHaveProperty('name');
expect(example).toHaveProperty('count');
});
});