import { describe, it, expect } from 'vitest';
import type { CapabilityProvider, CapabilityRequest, ProviderResult } from '@insignia/iios-contracts';
import { certifyProvider } from './capability.certification';
import { SandboxProvider } from './sandbox.provider';

describe('adapter certification checklist (P9)', () => {
  it('SandboxProvider passes certification', async () => {
    const report = await certifyProvider(new SandboxProvider(['WEBHOOK']));
    expect(report.passed).toBe(true);
    expect(report.checks.every((c) => c.ok)).toBe(true);
  });

  it('a broken provider fails with the specific failing checks', async () => {
    const broken: CapabilityProvider = {
      name: 'broken',
      channelTypes: [], // no declared channels
      capabilities: { canSend: false },
      async send(_req: CapabilityRequest): Promise<ProviderResult> {
        throw new Error('kaboom'); // throws instead of returning FAILED
      },
    };
    const report = await certifyProvider(broken);
    expect(report.passed).toBe(false);
    expect(report.checks.find((c) => c.name === 'declares-capabilities')?.ok).toBe(false);
    expect(report.checks.find((c) => c.name === 'returns-providerRef-and-outcome')?.ok).toBe(false);
  });
});
