import { describe, expect, it } from "vitest";
import { cookieSchema } from "./cookie";

describe("cookieSchema", () => {
  it("accepts a minimal cookie with empty attributes", () => {
    const result = cookieSchema.parse({
      name: "session",
      value: "abc123",
      attributes: {},
    });
    expect(result.name).toBe("session");
    expect(result.value).toBe("abc123");
  });

  it("accepts a fully-populated cookie", () => {
    const result = cookieSchema.parse({
      name: "session",
      value: "abc123",
      attributes: {
        secure: true,
        path: "/",
        domain: "example.com",
        sameSite: "strict",
        httpOnly: true,
        maxAge: 3600,
        expires: new Date(),
      },
    });
    expect(result.attributes.sameSite).toBe("strict");
  });

  it("rejects an invalid sameSite value", () => {
    expect(() =>
      cookieSchema.parse({
        name: "session",
        value: "abc123",
        attributes: { sameSite: "invalid" },
      }),
    ).toThrow();
  });

  it("rejects a missing required field", () => {
    expect(() =>
      cookieSchema.parse({ name: "session", attributes: {} }),
    ).toThrow();
  });
});
