enterpriseStaticOnly.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { expect, it, vi } from "vitest";
  2. import { BUILTIN_MODEL_PROVIDER_IDS } from "@zcode/shared";
  3. const mocks = vi.hoisted(() => ({
  4. state: null as any,
  5. getStaticTeamProducts: vi.fn(),
  6. getEnterprisePricing: vi.fn(),
  7. }));
  8. vi.mock("@/hooks/useServices.js", () => ({
  9. useOptionalServices: () => ({ codingPlanSubscriptionService: mocks }),
  10. }));
  11. vi.mock("react", () => ({
  12. useCallback: (fn: unknown) => fn,
  13. useEffect: (fn: () => void) => fn(),
  14. useMemo: (fn: () => unknown) => fn(),
  15. useState: (initial: unknown) => {
  16. mocks.state = initial;
  17. return [
  18. initial,
  19. (next: any) => {
  20. mocks.state = typeof next === "function" ? next(mocks.state) : next;
  21. },
  22. ];
  23. },
  24. }));
  25. import { useEnterpriseCodingPlanProducts } from "@/settings/model-provider-section/useEnterpriseCodingPlanProducts.js";
  26. it.each([true, false])("未登录仅静态目录,配置存在=%s,不请求 pricing", async (configured) => {
  27. mocks.getEnterprisePricing.mockReset();
  28. mocks.getStaticTeamProducts.mockResolvedValue(
  29. configured
  30. ? {
  31. [BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan]: [
  32. {
  33. productId: "configured-team",
  34. productName: "标准版",
  35. tier: "PRO",
  36. subscribeMode: "CONTINUOUS",
  37. subscribePeriod: "MONTHLY",
  38. payAmount: 321,
  39. priceCurrency: "CNY",
  40. },
  41. ],
  42. }
  43. : {},
  44. );
  45. useEnterpriseCodingPlanProducts({ enabled: true, authenticated: false, staticOnly: true });
  46. await vi.waitFor(() => expect(mocks.state.loading).toBe(false));
  47. expect(mocks.getEnterprisePricing).not.toHaveBeenCalled();
  48. expect(mocks.state.snapshot.productList.map((p: any) => p.payAmount)).toEqual(
  49. configured ? [321] : [],
  50. );
  51. expect(mocks.state.snapshot.staticProductIds).toEqual(configured ? ["configured-team"] : []);
  52. });