import { describe, expect, it } from "vitest";

import { inviteRequestSchema } from "./inviteRequestSchema";

describe("inviteRequestSchema", () => {
  it("accepts an invite request with just email and role (no name)", () => {
    const result = inviteRequestSchema.parse({
      email: "alice@example.com",
      role: "read",
    });

    expect(result).toEqual({
      email: "alice@example.com",
      role: "read",
    });
  });

  it("silently drops an unknown name field (in-flight clients still parse)", () => {
    const result = inviteRequestSchema.parse({
      email: "alice@example.com",
      role: "write",
      name: "Alice",
    });

    expect(result).toEqual({
      email: "alice@example.com",
      role: "write",
    });
    expect(result).not.toHaveProperty("name");
  });

  it("rejects an invite request with a malformed email", () => {
    expect(() =>
      inviteRequestSchema.parse({ email: "not-an-email", role: "read" }),
    ).toThrow();
  });

  it("rejects an invite request with a role outside the enum", () => {
    expect(() =>
      inviteRequestSchema.parse({
        email: "alice@example.com",
        role: "superuser",
      }),
    ).toThrow();
  });
});
