import { describe, it, expect } from 'vitest';
import { runSubmit } from './submit';

describe('runSubmit', () => {
  it('folds a resolved call into ok(value)', async () => {
    const r = await runSubmit(async () => 'BIG-123', 'fallback');
    expect(r).toEqual({ ok: true, value: 'BIG-123' });
  });

  it('maps a ProblemDetails rejection to err(detail)', async () => {
    const r = await runSubmit(async () => {
      throw { detail: 'Aanvraag afgewezen.' };
    }, 'fallback');
    expect(r).toEqual({ ok: false, error: 'Aanvraag afgewezen.' });
  });

  it('falls back when the rejection has no detail', async () => {
    const r = await runSubmit(async () => {
      throw new Error('network');
    }, 'fallback');
    expect(r).toEqual({ ok: false, error: 'fallback' });
  });
});
