/**
 * Verifies the user-edited prompt (customPrompt) reaches the actual AI request:
 * buildLandingPageWebsitePrompt must inject it as an AUTHORITATIVE block in the
 * userPrompt when present, and leave the prompt unchanged when it is absent —
 * without dropping the structural brief (sections, JSON-only instruction).
 */
import { buildLandingPageWebsitePrompt, type LandingPageWebsiteInputs } from '../landingPageWebsitePrompts';

function inputs(overrides: Partial<LandingPageWebsiteInputs> = {}): LandingPageWebsiteInputs {
  return { pageName: 'Test Page', pageType: 'saas', primaryGoal: 'lead-generation', ...overrides };
}

describe('buildLandingPageWebsitePrompt — customPrompt injection', () => {
  it('injects the edited prompt authoritatively into the userPrompt', () => {
    const edited = 'Create a SaaS landing page for an AI healthcare platform. IMPORTANT TEST: fitness management.';
    const { userPrompt } = buildLandingPageWebsitePrompt(inputs({ customPrompt: edited }));
    expect(userPrompt).toContain('USER-EDITED PROMPT (AUTHORITATIVE');
    expect(userPrompt).toContain(edited);
    // Structural brief is still present — we augment, not replace.
    expect(userPrompt).toContain('SECTIONS');
    expect(userPrompt).toContain('Return ONLY JSON');
  });

  it('does NOT add the override block when no customPrompt is provided', () => {
    const { userPrompt } = buildLandingPageWebsitePrompt(inputs());
    expect(userPrompt).not.toContain('USER-EDITED PROMPT (AUTHORITATIVE');
    expect(userPrompt).toContain('SECTIONS');
  });

  it('trims and ignores a whitespace-only customPrompt', () => {
    const { userPrompt } = buildLandingPageWebsitePrompt(inputs({ customPrompt: '   \n  ' }));
    expect(userPrompt).not.toContain('USER-EDITED PROMPT (AUTHORITATIVE');
  });

  it('preserves the regeneration instruction alongside an edited prompt', () => {
    const { userPrompt } = buildLandingPageWebsitePrompt(
      inputs({ customPrompt: 'Edited brief for a fitness SaaS', regenerateInstruction: 'Make the hero blue' }),
    );
    expect(userPrompt).toContain('USER-EDITED PROMPT (AUTHORITATIVE');
    expect(userPrompt).toContain('Make the hero blue');
  });
});
