import { validate } from 'class-validator';
import { describe, it, expect } from 'vitest';
import { LoginDto } from '../dto/login.dto';

describe('LoginDto', () => {
  it('accepts valid login data', async () => {
    const dto = new LoginDto();
    dto.phone = '0901234567';
    dto.password = 'P@ssw0rd!';

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

  it('rejects missing phone', async () => {
    const dto = new LoginDto();
    dto.password = 'P@ssw0rd!';

    const errors = await validate(dto);
    expect(errors.length).toBeGreaterThan(0);
    expect(errors.some((e) => e.property === 'phone')).toBe(true);
  });

  it('rejects missing password', async () => {
    const dto = new LoginDto();
    dto.phone = '0901234567';

    const errors = await validate(dto);
    expect(errors.length).toBeGreaterThan(0);
    expect(errors.some((e) => e.property === 'password')).toBe(true);
  });

  it('rejects non-string phone', async () => {
    const dto = new LoginDto();
    (dto as any).phone = 12345;
    dto.password = 'P@ssw0rd!';

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