import { validate } from 'class-validator';
import { UpdateProfileDto } from '../../presentation/dto/update-profile.dto';

describe('UpdateProfileDto', () => {
  it('accepts valid fullName only', async () => {
    const dto = new UpdateProfileDto();
    dto.fullName = 'Nguyen Van A';

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
  });

  it('accepts valid avatarUrl only', async () => {
    const dto = new UpdateProfileDto();
    dto.avatarUrl = 'https://cdn.example.com/avatar.jpg';

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
  });

  it('accepts valid email only', async () => {
    const dto = new UpdateProfileDto();
    dto.email = 'user@example.com';

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
  });

  it('accepts all fields together', async () => {
    const dto = new UpdateProfileDto();
    dto.fullName = 'Tran Van B';
    dto.avatarUrl = 'https://cdn.example.com/avatar.jpg';
    dto.email = 'user@example.com';

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
  });

  it('accepts empty dto (all optional)', async () => {
    const dto = new UpdateProfileDto();

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
  });

  it('rejects invalid email format', async () => {
    const dto = new UpdateProfileDto();
    dto.email = 'not-an-email';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'email')).toBe(true);
  });

  it('rejects invalid avatarUrl format', async () => {
    const dto = new UpdateProfileDto();
    dto.avatarUrl = 'not-a-url';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'avatarUrl')).toBe(true);
  });

  it('rejects empty fullName (minLength 1)', async () => {
    const dto = new UpdateProfileDto();
    dto.fullName = '';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'fullName')).toBe(true);
  });

  it('rejects non-string fullName', async () => {
    const dto = new UpdateProfileDto();
    (dto as any).fullName = 123;

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'fullName')).toBe(true);
  });
});
