import { describe, expect, it } from 'vitest'; import { DEMO_TEMPLATE_300x250 } from '@banner-studio/layout-engine'; import { routeNode } from '../src/ai-orchestration/route-node.js'; import { assemble } from '../src/ai-orchestration/assemble.js'; describe('assemble', () => { it('stamps version_id, generated_at, ai_reasoning, click_destinations and copy map', () => { const routed = routeNode({ template: DEMO_TEMPLATE_300x250, hero_image_url: 'https://cdn.example/hero.jpg' }); const { spec, copyMap } = assemble({ routed, copy: { headline: 'Test Headline', subheadline: 'Test sub.', cta_text: 'Shop now' }, rationale: { copy: 'tight benefit-led wording', asset: 'product hero with neutral background', variant: 'standard 300x250 variant', animation: 'fade-in cascade' }, campaign_id: 'camp-123', click_url: 'https://example.com/landing' }); expect(spec.campaign_id).toBe('camp-123'); expect(spec.version_id).toMatch(/^[-0-9a-f]{8,}/); expect(new Date(spec.generated_at).getTime()).not.toBeNaN(); expect(spec.ai_reasoning.copy_rationale).toBe('tight benefit-led wording'); expect(spec.ai_reasoning.asset_selection).toBe('product hero with neutral background'); expect(spec.ai_reasoning.variant_selection).toBe('standard 300x250 variant'); expect(spec.ai_reasoning.animation_rationale).toBe('fade-in cascade'); expect(spec.click_destinations).toEqual([ { id: 'cta', url: 'https://example.com/landing' } ]); expect(copyMap).toEqual({ headline: 'Test Headline', subheadline: 'Test sub.', cta: 'Shop now' }); }); it('omits subheadline and legal from the copy map when not provided', () => { const routed = routeNode({ template: DEMO_TEMPLATE_300x250, hero_image_url: 'https://cdn.example/hero.jpg' }); const { copyMap } = assemble({ routed, copy: { headline: 'Just headline and CTA', cta_text: 'Shop' }, rationale: { copy: '', asset: '', variant: '', animation: '' }, campaign_id: 'camp', click_url: 'https://example.com' }); expect(copyMap).toEqual({ headline: 'Just headline and CTA', cta: 'Shop' }); expect(copyMap.subheadline).toBeUndefined(); expect(copyMap.legal).toBeUndefined(); }); });