import { describe, it, expect, vi } from "vitest";
import { runBase64 } from "./run";
import type { ToolContext } from "../../core/plugins/plugin-types";

describe("Base64 Plugin", () => {
  const mockContext: ToolContext = {
    signal: new AbortController().signal,
    reportProgress: vi.fn(),
    logger: {
      info: vi.fn(),
      warn: vi.fn(),
      error: vi.fn(),
    },
  };

  it("should encode text correctly", async () => {
    const result = await runBase64(
      { text: "Hello World" },
      { mode: "encode" },
      mockContext
    );
    expect(result).toEqual({ type: "text", value: "SGVsbG8gV29ybGQ=" });
  });

  it("should decode text correctly", async () => {
    const result = await runBase64(
      { text: "SGVsbG8gV29ybGQ=" },
      { mode: "decode" },
      mockContext
    );
    expect(result).toEqual({ type: "text", value: "Hello World" });
  });

  it("should return empty string for empty input", async () => {
    const result = await runBase64(
      { text: "" },
      { mode: "encode" },
      mockContext
    );
    expect(result).toEqual({ type: "text", value: "" });
  });

  it("should throw error on invalid base64 decode", async () => {
    await expect(
      runBase64({ text: "NotBase64!" }, { mode: "decode" }, mockContext)
    ).rejects.toThrow("Invalid Base64 input string or encoding error.");
  });
});
