import { describe, expect, it } from "vitest";
import { defaultGqlPermission, defaultPermission } from "./modelPermissions";

describe("defaultPermission", () => {
  it("permits all CRUD operations for logged-in users", () => {
    const expected = [{ conditions: [[{ user: "_loggedIn" }, "=", true]], permit: true }];
    expect(defaultPermission.create).toEqual(expected);
    expect(defaultPermission.read).toEqual(expected);
    expect(defaultPermission.update).toEqual(expected);
    expect(defaultPermission.delete).toEqual(expected);
  });
});

describe("defaultGqlPermission", () => {
  it("allows read and aggregate only for logged-in users", () => {
    expect(defaultGqlPermission).toEqual([
      {
        conditions: [[{ user: "_loggedIn" }, "=", true]],
        actions: ["read", "aggregate"],
        permit: true,
      },
    ]);
  });
});
