You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
975 B

import { describe, expect, it } from "vitest";
import {
assertCustomerUsername,
CustomerAccountError,
} from "@/services/auth/customers";
import { hashPassword, passwordMatches } from "@/services/auth/passwords";
import { isStaffRole } from "@/services/tenant/access";
describe("customer accounts", () => {
it("rejects reserved-like short names", () => {
expect(() => assertCustomerUsername("ab")).toThrow(CustomerAccountError);
});
it("accepts dotted customer usernames", () => {
expect(assertCustomerUsername("acme.ops")).toBe("acme.ops");
});
it("matches sha256 password hash", () => {
const hash = hashPassword("secret-1");
expect(passwordMatches("secret-1", hash, "")).toBe(true);
expect(passwordMatches("wrong", hash, "")).toBe(false);
});
it("treats admin/ops as staff", () => {
expect(isStaffRole("admin")).toBe(true);
expect(isStaffRole("ops")).toBe(true);
expect(isStaffRole("customer")).toBe(false);
});
});