import { describe, it, expect } from 'vitest';
import { samplePathReducer } from './reducer';
import { initialSamplePathMachine } from './states';

describe('samplePathReducer §6', () => {
  it('V1: a full URL fails immediately, without entering Verifying', () => {
    const m = samplePathReducer(initialSamplePathMachine, { type: 'PASTE_PATH', path: 'https://x/y.dcm' });
    expect(m.state).toBe('VerifyFailed');
    expect(m.context.error?.code).toBe('PATH_NOT_BUCKET_RELATIVE');
  });

  it('a bucket-relative path enters Verifying, then VERIFY_OK -> Verified with a preview', () => {
    let m = samplePathReducer(initialSamplePathMachine, { type: 'PASTE_PATH', path: 'bucket/a.dcm' });
    expect(m.state).toBe('Verifying');
    m = samplePathReducer(m, { type: 'VERIFY_OK', preview: { note: 'ok' } });
    expect(m.state).toBe('Verified');
    expect(m.context.preview?.note).toBe('ok');
  });

  it('VERIFY_FAIL -> VerifyFailed; RESET -> Idle', () => {
    let m = samplePathReducer(initialSamplePathMachine, { type: 'PASTE_PATH', path: 'bucket/a.dcm' });
    m = samplePathReducer(m, { type: 'VERIFY_FAIL', error: { code: 'PATH_NOT_BUCKET_RELATIVE', message: 'denied' } });
    expect(m.state).toBe('VerifyFailed');
    m = samplePathReducer(m, { type: 'RESET' });
    expect(m.state).toBe('Idle');
  });
});
