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

1.8 KB
Raw Blame
// @vitest-environment jsdom
import { describe, expect, it } from "vitest";

import {
  computeNoAuthFallbackDisabledProviders,
  isNoAuthFallbackEnabled,
} from "../components/AnonymousFallbackToggle";

describe("AnonymousFallbackToggle list-update helpers", () => {
  it("disabling adds the providerId exactly once and dedupes existing entries", () => {
    const next = computeNoAuthFallbackDisabledProviders(
      ["openai", "openai", "opencode-go"],
      "opencode-go",
      "opencode",
      true
    );
    expect(next).toEqual(["openai", "opencode-go"]);
    expect(next.filter((id) => id === "opencode-go")).toHaveLength(1);
  });

  it("enabling removes both the providerId and its alias", () => {
    const next = computeNoAuthFallbackDisabledProviders(
      ["openai", "opencode-go", "opencode"],
      "opencode-go",
      "opencode",
      false
    );
    expect(next).toEqual(["openai"]);
  });

  it("enabling with only the alias present also removes it", () => {
    const next = computeNoAuthFallbackDisabledProviders(
      ["opencode"],
      "opencode-go",
      "opencode",
      false
    );
    expect(next).toEqual([]);
  });

  it("is enabled by default when the disabled list is absent", () => {
    expect(isNoAuthFallbackEnabled("opencode-go", "opencode", undefined)).toBe(true);
  });

  it("is disabled when the providerId is in the list", () => {
    expect(isNoAuthFallbackEnabled("opencode-go", "opencode", ["opencode-go"])).toBe(false);
  });

  it("is disabled when only the alias is in the list", () => {
    expect(isNoAuthFallbackEnabled("opencode-go", "opencode", ["opencode"])).toBe(false);
  });

  it("is enabled when the list is present but does not contain the provider", () => {
    expect(isNoAuthFallbackEnabled("opencode-go", "opencode", ["openai"])).toBe(true);
  });
});