Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.4 KB
Raw Blame
import { describe, expect, it } from "vitest";

import { comparePasswordsAsync, hashPasswordAsync } from "../security";

describe("hashPassword should return a hash", () => {
  it("should return a hash", async () => {
    const password = "password";
    const result = await hashPasswordAsync(password);
    expect(result).toBeDefined();
    expect(result.length).toBeGreaterThan(55);
    expect(result).not.toEqual(password);
  });
  it("should return a different hash for the same password with different salts", async () => {
    const password = "password";

    const result1 = await hashPasswordAsync(password);
    const result2 = await hashPasswordAsync(password);

    expect(result1).not.toEqual(result2);
  });
});

describe("comparePasswordsAsync should compare passwords correctly", () => {
  it("should return true for matching passwords", async () => {
    // Arrange
    const password = "password";
    const hash = await hashPasswordAsync(password);

    // Act
    const result = await comparePasswordsAsync(password, hash);

    // Assert
    expect(result).toBe(true);
  });
  it("should return false for non-matching passwords", async () => {
    // Arrange
    const password = "password";
    const wrongPassword = "wrongpassword";
    const hash = await hashPasswordAsync(password);

    // Act
    const result = await comparePasswordsAsync(wrongPassword, hash);

    // Assert
    expect(result).toBe(false);
  });
});