import { describe, expect, it } from "vitest";
import { canEnterRoom } from "../src/lib/access";

describe("canEnterRoom", () => {
  it("allows public rooms", () => {
    expect(canEnterRoom({ visibility: "PUBLIC" })).toBe(true);
  });

  it("allows owners and admins regardless of room visibility", () => {
    expect(canEnterRoom({ visibility: "EXPLICIT", isOwner: true })).toBe(true);
    expect(canEnterRoom({ visibility: "ROLE_RESTRICTED", isAdmin: true })).toBe(true);
  });

  it("requires accepted friend or explicit membership for friends-only rooms", () => {
    expect(canEnterRoom({ visibility: "FRIENDS" })).toBe(false);
    expect(canEnterRoom({ visibility: "FRIENDS", isFriend: true })).toBe(true);
    expect(canEnterRoom({ visibility: "FRIENDS", explicitMember: true })).toBe(true);
  });

  it("requires explicit membership for explicit rooms", () => {
    expect(canEnterRoom({ visibility: "EXPLICIT", isFriend: true })).toBe(false);
    expect(canEnterRoom({ visibility: "EXPLICIT", explicitMember: true })).toBe(true);
  });
});
