Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

2.2 KB
Raw Blame
import { describe, it } from "node:test";
import assert from "node:assert/strict";

const mod = await import("../../open-sse/executors/adapta-web.ts");

describe("AdaptaWebExecutor", () => {
  it("can be instantiated", () => {
    const executor = new mod.AdaptaWebExecutor();
    assert.ok(executor);
  });

  it("returns 401 when credentials are missing", async () => {
    const executor = new mod.AdaptaWebExecutor();
    const result = await executor.execute({
      model: "adapta-one",
      body: { messages: [{ role: "user", content: "hi" }] },
      stream: false,
      credentials: {},
      signal: null,
    });
    assert.equal(result.response.status, 401);
    const json = await result.response.json();
    assert.ok(json.error.message.includes("Missing Adapta credentials"));
  });

  it("returns 401 when apiKey is empty", async () => {
    const executor = new mod.AdaptaWebExecutor();
    const result = await executor.execute({
      model: "adapta-one",
      body: { messages: [{ role: "user", content: "test" }] },
      stream: false,
      credentials: { apiKey: "" },
      signal: null,
    });
    assert.equal(result.response.status, 401);
  });

  it("execute returns proper result shape on auth failure", async () => {
    const originalFetch = globalThis.fetch;
    globalThis.fetch = (async () => new Response(null, { status: 401 })) as typeof fetch;

    try {
      const executor = new mod.AdaptaWebExecutor();
      const result = await executor.execute({
        model: "adapta-one",
        body: { messages: [{ role: "user", content: "hi" }] },
        stream: false,
        credentials: { apiKey: "invalid-jwt" },
        signal: null,
      });
      assert.ok(result.response instanceof Response);
      assert.ok(typeof result.url === "string");
      assert.ok(typeof result.headers === "object");
      assert.ok(result.transformedBody !== undefined);
    } finally {
      globalThis.fetch = originalFetch;
    }
  });

  it("testConnection returns false for invalid credentials", async () => {
    const executor = new mod.AdaptaWebExecutor();
    const connected = await executor.testConnection({ apiKey: "" });
    assert.equal(connected, false);
  });
});