import { describe, it, expect } from 'vitest';
import { hashPassword, verifyPassword } from '@/lib/auth';

// Pure-function bits of lib/auth.ts (no Prisma, no cookies).

describe('hashPassword / verifyPassword', () => {
  it('verifies a correct password', async () => {
    const hash = await hashPassword('correct horse battery staple');
    expect(await verifyPassword('correct horse battery staple', hash)).toBe(true);
  });

  it('rejects an incorrect password', async () => {
    const hash = await hashPassword('correct horse battery staple');
    expect(await verifyPassword('wrong horse', hash)).toBe(false);
  });

  it('produces different hashes for the same password (salt-randomness)', async () => {
    const a = await hashPassword('same input');
    const b = await hashPassword('same input');
    expect(a).not.toBe(b);
    expect(await verifyPassword('same input', a)).toBe(true);
    expect(await verifyPassword('same input', b)).toBe(true);
  });

  it('produces a bcrypt-format hash starting with $2', async () => {
    const hash = await hashPassword('whatever');
    expect(hash.startsWith('$2')).toBe(true);
  });
});
