mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-11-30 19:26:59 +08:00
Account rows only showed the sign-in date, so a Max and a Free Copilot account looked the same. Claude accounts already led their second line with the plan; the other services now do too. Account quota queries now carry a plan name (`planName`), read from data the services already return or from one parallel request: - Copilot: access_type_sku, then copilot_plan, mapped like VS Code. Free also reports `individual`, so it is never called Pro without a SKU. - ChatGPT: wham/usage `plan_type`, named as Codex's own /status does (Pro 200, Pro 100, Business ...). - Kimi: `user_level_name` from /me (/usages no longer carries membership). - Antigravity: loadCodeAssist `paidTier.name`, falling back to Free/Paid. - xAI: `subscription_tier_display` from the Grok CLI settings endpoint, only for the frontend command; the tray poll does not ask. A failed plan lookup only hides the plan; the quota is unaffected. The row reads the plan from the quota query cache and keeps the last one across a failed refresh, matching the quota column.
96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { CodexOAuthSection } from "@/components/providers/forms/CodexOAuthSection";
|
|
import { CopilotAuthSection } from "@/components/providers/forms/CopilotAuthSection";
|
|
|
|
const authMocks = vi.hoisted(() => ({
|
|
refetchCodex: vi.fn(),
|
|
refetchCopilot: vi.fn(),
|
|
}));
|
|
|
|
const failedStatus = (refetchStatus: () => void) => ({
|
|
accounts: [],
|
|
defaultAccountId: null,
|
|
migrationError: null,
|
|
isStatusSuccess: false,
|
|
isStatusError: true,
|
|
hasAnyAccount: false,
|
|
pollingState: "idle" as const,
|
|
deviceCode: null,
|
|
error: null,
|
|
isPolling: false,
|
|
isAddingAccount: false,
|
|
isRemovingAccount: false,
|
|
isSettingDefaultAccount: false,
|
|
addAccount: vi.fn(),
|
|
removeAccount: vi.fn(),
|
|
setDefaultAccount: vi.fn(),
|
|
cancelAuth: vi.fn(),
|
|
logout: vi.fn(),
|
|
refetchStatus,
|
|
});
|
|
|
|
vi.mock("@/lib/query/accountPlans", () => ({
|
|
useAccountQuotaPlans: () => ({}),
|
|
}));
|
|
|
|
vi.mock("@/components/providers/forms/hooks/useCodexOauth", () => ({
|
|
useCodexOauth: () => failedStatus(authMocks.refetchCodex),
|
|
}));
|
|
|
|
vi.mock("@/components/providers/forms/hooks/useCopilotAuth", () => ({
|
|
useCopilotAuth: () => failedStatus(authMocks.refetchCopilot),
|
|
}));
|
|
|
|
// 「N 个供应商在用」要读供应商列表(React Query);这里不关心,给空
|
|
vi.mock("@/components/providers/forms/hooks/useManagedAccountUsers", () => ({
|
|
useManagedAccountUsers: () => () => [],
|
|
}));
|
|
|
|
describe("managed auth status failures", () => {
|
|
beforeEach(() => {
|
|
authMocks.refetchCodex.mockResolvedValue(undefined);
|
|
authMocks.refetchCopilot.mockResolvedValue(undefined);
|
|
});
|
|
|
|
it("shows a retryable error instead of an empty Codex account selector", () => {
|
|
const onAccountSelect = vi.fn();
|
|
render(
|
|
<CodexOAuthSection
|
|
mode="select"
|
|
selectedAccountId="acct-existing"
|
|
onAccountSelect={onAccountSelect}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByRole("alert")).toHaveTextContent(
|
|
"无法加载 ChatGPT 账号状态,请重试。",
|
|
);
|
|
expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
|
|
expect(onAccountSelect).not.toHaveBeenCalled();
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "重试" }));
|
|
expect(authMocks.refetchCodex).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("shows a retryable error instead of an empty Copilot account selector", () => {
|
|
const onAccountSelect = vi.fn();
|
|
render(
|
|
<CopilotAuthSection
|
|
mode="select"
|
|
selectedAccountId="acct-existing"
|
|
onAccountSelect={onAccountSelect}
|
|
/>,
|
|
);
|
|
|
|
expect(screen.getByRole("alert")).toHaveTextContent(
|
|
"无法加载 GitHub Copilot 账号状态,请重试。",
|
|
);
|
|
expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
|
|
expect(onAccountSelect).not.toHaveBeenCalled();
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "重试" }));
|
|
expect(authMocks.refetchCopilot).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|