import { describe, expect, it } from "vitest";
import { createSessionTokenValue, verifySessionTokenValue } from "@/lib/auth/session-token";

describe("session token", () => {
  it("creates and verifies a valid token", () => {
    const token = createSessionTokenValue("user-1", "ana@empresa.com", "test-secret", 3600);
    const payload = verifySessionTokenValue(token, "test-secret");

    expect(payload).not.toBeNull();
    expect(payload?.userId).toBe("user-1");
    expect(payload?.email).toBe("ana@empresa.com");
  });

  it("rejects token with wrong secret", () => {
    const token = createSessionTokenValue("user-1", "ana@empresa.com", "test-secret", 3600);
    const payload = verifySessionTokenValue(token, "other-secret");

    expect(payload).toBeNull();
  });

  it("rejects expired token", () => {
    const token = createSessionTokenValue("user-1", "ana@empresa.com", "test-secret", -1);
    const payload = verifySessionTokenValue(token, "test-secret");

    expect(payload).toBeNull();
  });
});
