import { describe, expect, it } from "vitest";
import { hashPassword, verifyPassword } from "./utils";

describe("Password Utils", () => {
  const password = "password";
  const hashedPassword = "$2a$12$LZsLq.9nkZlU0YDPx2aLNelnwD/nyavqbewLN.5.Q5h/UxRD8Ymcy";

  describe("hashPassword", () => {
    it("should hash a password", async () => {
      const hashedPassword = await hashPassword(password);

      expect(typeof hashedPassword).toBe("string");
      expect(hashedPassword).not.toBe(password);
      expect(hashedPassword.length).toBe(60);
    });

    it("should generate different hashes for the same password", async () => {
      const hash1 = await hashPassword(password);
      const hash2 = await hashPassword(password);

      expect(hash1).not.toBe(hash2);
    });
  });

  describe("verifyPassword", () => {
    it("should verify a correct password", async () => {
      const isValid = await verifyPassword(password, hashedPassword);

      expect(isValid).toBe(true);
    });

    it("should reject an incorrect password", async () => {
      const isValid = await verifyPassword("WrongPassword123!", hashedPassword);

      expect(isValid).toBe(false);
    });
  });
});
