import { describe, expect, it } from '@jest/globals';
import { validatePayPalConfig } from '../../../config/paypalValidation';

describe('validatePayPalConfig', () => {
  it('accepts resolved database-backed credentials when environment credentials are absent', () => {
    const result = validatePayPalConfig(() => ({
      clientId: 'db-client',
      clientSecret: 'db-secret',
      webhookId: 'db-webhook',
      mode: 'live',
    }));

    expect(result).toEqual({ ok: true, missing: [], warnings: [], mode: 'live' });
  });

  it('reports incomplete resolved credentials without throwing', () => {
    const result = validatePayPalConfig(() => {
      throw new Error('PayPal credentials are incomplete');
    });

    expect(result.ok).toBe(false);
    expect(result.missing).toEqual(['paypalCredentials']);
  });
});
