import { describe, expect, it } from 'vitest';
import { getApiValidationMessage, ApiError } from '../apiError';

describe('getApiValidationMessage', () => {
  it('prefers validation errors when present', () => {
    const error = new ApiError('Fallback', 422, undefined, {
      errors: {
        event_date: ['Das Event-Datum darf nicht in der Vergangenheit liegen.'],
      },
    });

    expect(getApiValidationMessage(error, 'Fallback')).toBe('Das Event-Datum darf nicht in der Vergangenheit liegen.');
  });

  it('falls back to the error message when no validation errors exist', () => {
    const error = new ApiError('Server error');

    expect(getApiValidationMessage(error, 'Fallback')).toBe('Server error');
  });
});
