import { describe, it, expect } from 'vitest';
import { validatePromptLength } from '../validators';

describe('validatePromptLength', () => {
  it('should reject empty prompts', () => {
    const result = validatePromptLength('');
    expect(result.valid).toBe(false);
    expect(result.error).toBe('Prompt cannot be empty');
  });

  it('should reject whitespace-only prompts', () => {
    const result = validatePromptLength('   ');
    expect(result.valid).toBe(false);
    expect(result.error).toBe('Prompt cannot be empty');
  });

  it('should accept valid prompt within max length', () => {
    const result = validatePromptLength('a sunset over the ocean', 2000);
    expect(result.valid).toBe(true);
    expect(result.error).toBeUndefined();
  });

  it('should reject prompts exceeding max length', () => {
    const longPrompt = 'a'.repeat(2001);
    const result = validatePromptLength(longPrompt, 2000);
    expect(result.valid).toBe(false);
    expect(result.error).toContain('exceeds maximum length');
    expect(result.error).toContain('2000');
  });

  it('should use custom max length', () => {
    const prompt = 'a'.repeat(150);
    const result = validatePromptLength(prompt, 100);
    expect(result.valid).toBe(false);
    expect(result.error).toContain('100');
  });

  it('should accept prompt at exact max length', () => {
    const prompt = 'a'.repeat(100);
    const result = validatePromptLength(prompt, 100);
    expect(result.valid).toBe(true);
  });
});
