// @vitest-environment node
import { describe, it, expect } from "vitest";
import { signJWT, verifyJWT } from "./jwt";

describe("jwt", () => {
  it("should sign and verify a JWT", async () => {
    const payload = { sub: "user-123", role: "user" };
    const token = await signJWT(payload);
    const decoded = await verifyJWT<typeof payload>(token);
    expect(decoded.sub).toBe("user-123");
    expect(decoded.role).toBe("user");
  });

  it("should reject an invalid JWT", async () => {
    await expect(verifyJWT("invalid.token.here")).rejects.toThrow();
  });
});
