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

describe('UploadMediaViewModel', () => {
  it('creates instance with successful upload and media data', () => {
    const dto = {
      success: true,
      mediaId: 'media-123',
      url: 'https://example.com/uploaded.jpg',
    };

    const viewModel = new UploadMediaViewModel(dto);

    expect(viewModel.success).toBe(true);
    expect(viewModel.mediaId).toBe('media-123');
    expect(viewModel.url).toBe('https://example.com/uploaded.jpg');
    expect(viewModel.error).toBeUndefined();
  });

  it('creates instance with failed upload and error', () => {
    const dto = {
      success: false,
      error: 'Upload failed',
    };

    const viewModel = new UploadMediaViewModel(dto);

    expect(viewModel.success).toBe(false);
    expect(viewModel.mediaId).toBeUndefined();
    expect(viewModel.url).toBeUndefined();
    expect(viewModel.error).toBe('Upload failed');
  });

  it('isSuccessful reflects success flag', () => {
    const successVm = new UploadMediaViewModel({ success: true });
    const failureVm = new UploadMediaViewModel({ success: false });

    expect(successVm.isSuccessful).toBe(true);
    expect(failureVm.isSuccessful).toBe(false);
  });

  it('hasError reflects presence of error message', () => {
    const noErrorVm = new UploadMediaViewModel({ success: true });
    const errorVm = new UploadMediaViewModel({ success: false, error: 'Something went wrong' });

    expect(noErrorVm.hasError).toBe(false);
    expect(errorVm.hasError).toBe(true);
  });

  it('treats empty error string as no error', () => {
    const viewModel = new UploadMediaViewModel({ success: false, error: '' });

    expect(viewModel.hasError).toBe(false);
  });
});
