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

describe('UpdateAvatarViewModel', () => {
  it('creates instance with success true and no error', () => {
    const dto = { success: true };

    const viewModel = new UpdateAvatarViewModel(dto);

    expect(viewModel.success).toBe(true);
    expect(viewModel.error).toBeUndefined();
  });

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

    const viewModel = new UpdateAvatarViewModel(dto);

    expect(viewModel.success).toBe(false);
    expect(viewModel.error).toBe('Update failed');
  });

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

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

  it('hasError reflects presence of error message', () => {
    const noErrorVm = new UpdateAvatarViewModel({ success: true });
    const errorVm = new UpdateAvatarViewModel({ 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 UpdateAvatarViewModel({ success: false, error: '' });

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