import { describe, it, expect } from 'vitest';
import { HashedPassword } from '../value-objects/hashed-password.vo';

describe('HashedPassword Value Object', () => {
  it('should hash and verify a password', async () => {
    const result = await HashedPassword.fromPlain('StrongPass123');
    expect(result.isOk).toBe(true);

    const hashed = result.unwrap();
    expect(hashed.value).toMatch(/^\$2[ab]\$/);

    const isValid = await hashed.compare('StrongPass123');
    expect(isValid).toBe(true);

    const isInvalid = await hashed.compare('WrongPassword');
    expect(isInvalid).toBe(false);
  });

  it('should reject short passwords', async () => {
    const result = await HashedPassword.fromPlain('short');
    expect(result.isErr).toBe(true);
    expect(result.unwrapErr()).toContain('ít nhất 8 ký tự');
  });

  it('should create from existing hash', () => {
    const hash = '$2b$12$mockHashValue';
    const hashed = HashedPassword.fromHash(hash);
    expect(hashed.value).toBe(hash);
  });
});
