import { describe, expect, expectTypeOf, it } from "vitest";
import { definePermissions } from "./definePermissions";

describe("definePermissions", () => {
  it("infers literal types for permission keys", () => {
    const result = definePermissions("primitives", {
      category: ["createCategory", "updateCategory"],
    } as const);

    expectTypeOf(
      result.permissions.category.createCategory,
    ).toEqualTypeOf<"primitives:category:createCategory">();
  });

  it("creates scoped permission keys as module:scope:command", () => {
    const result = definePermissions("user-management", {
      user: ["createUser", "updateUser"],
      role: ["createRole"],
    } as const);

    expect(result.permissions.user.createUser).toBe("user-management:user:createUser");
    expect(result.permissions.user.updateUser).toBe("user-management:user:updateUser");
    expect(result.permissions.role.createRole).toBe("user-management:role:createRole");
  });
});
