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

describe("OAuth State Encoding/Decoding", () => {
  it("should encode redirect URI as base64", () => {
    const redirectUri = "/dashboard";
    const state = Buffer.from(redirectUri).toString("base64");
    expect(state).toBe(Buffer.from("/dashboard").toString("base64"));
  });

  it("should decode base64 state back to redirect URI", () => {
    const redirectUri = "/dashboard";
    const state = Buffer.from(redirectUri).toString("base64");
    const decodedUri = Buffer.from(state, "base64").toString();
    expect(decodedUri).toBe(redirectUri);
  });

  it("should handle different redirect URIs", () => {
    const testCases = [
      "/dashboard",
      "/account-settings",
      "/games/slots",
      "https://example.com/callback",
    ];

    testCases.forEach((redirectUri) => {
      const state = Buffer.from(redirectUri).toString("base64");
      const decodedUri = Buffer.from(state, "base64").toString();
      expect(decodedUri).toBe(redirectUri);
    });
  });

  it("should handle special characters in redirect URI", () => {
    const redirectUri = "/dashboard?game=slots&bet=100";
    const state = Buffer.from(redirectUri).toString("base64");
    const decodedUri = Buffer.from(state, "base64").toString();
    expect(decodedUri).toBe(redirectUri);
  });
});
