|
| 1 | +import type { ProviderActionHandlers } from "@/lib/integrations/types"; |
| 2 | +import { render } from "@testing-library/react"; |
| 3 | +import type { ReactNode } from "react"; |
| 4 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 5 | +import IntegrationsPage from "./page"; |
| 6 | + |
| 7 | +const mocks = vi.hoisted(() => ({ |
| 8 | + completeGooglePropertySelection: vi.fn(), |
| 9 | + loadStoredGoogleProperties: vi.fn(), |
| 10 | + getIntegrationsView: vi.fn(), |
| 11 | + integrationCategory: vi.fn(), |
| 12 | + requireReadableProject: vi.fn(), |
| 13 | + resolveProjectAccess: vi.fn(), |
| 14 | + saveStoredGoogleProperty: vi.fn(), |
| 15 | +})); |
| 16 | + |
| 17 | +vi.mock("@/components/integrations/IntegrationCategory", () => ({ |
| 18 | + IntegrationCategory: (props: unknown) => { |
| 19 | + mocks.integrationCategory(props); |
| 20 | + return null; |
| 21 | + }, |
| 22 | +})); |
| 23 | +vi.mock("@/components/shell/PageContent", () => ({ |
| 24 | + PageContent: ({ children }: { children: ReactNode }) => children, |
| 25 | +})); |
| 26 | +vi.mock("@/components/ui", () => ({ |
| 27 | + Card: ({ children }: { children: ReactNode }) => children, |
| 28 | +})); |
| 29 | +vi.mock("@/lib/actions/providers", () => ({ |
| 30 | + completeGooglePropertySelection: mocks.completeGooglePropertySelection, |
| 31 | + connectProvider: vi.fn(), |
| 32 | + disconnectProvider: vi.fn(), |
| 33 | + loadStoredGoogleProperties: mocks.loadStoredGoogleProperties, |
| 34 | + saveStoredGoogleProperty: mocks.saveStoredGoogleProperty, |
| 35 | + testConnection: vi.fn(), |
| 36 | + updateProviderCost: vi.fn(), |
| 37 | + updateProviderRate: vi.fn(), |
| 38 | + updateProviderSettings: vi.fn(), |
| 39 | +})); |
| 40 | +vi.mock("@/lib/actions/traffic-sync", () => ({ syncProjectTraffic: vi.fn() })); |
| 41 | +vi.mock("@/lib/auth/authorize", () => ({ getProjectRole: () => "owner" })); |
| 42 | +vi.mock("@/lib/auth/capabilities", () => ({ canProjectAction: () => true })); |
| 43 | +vi.mock("@/lib/providers/analytics/google-oauth-pending", () => ({ |
| 44 | + getPendingGoogleOAuthSetup: vi.fn(), |
| 45 | +})); |
| 46 | +vi.mock("@/lib/queries/_auth", () => ({ |
| 47 | + requireReadableProject: mocks.requireReadableProject, |
| 48 | + resolveProjectAccess: mocks.resolveProjectAccess, |
| 49 | +})); |
| 50 | +vi.mock("@/lib/queries/integrations", () => ({ |
| 51 | + getIntegrationsView: mocks.getIntegrationsView, |
| 52 | +})); |
| 53 | +vi.mock("@phosphor-icons/react/dist/ssr", () => ({ KeyIcon: () => null })); |
| 54 | + |
| 55 | +describe("IntegrationsPage", () => { |
| 56 | + beforeEach(() => { |
| 57 | + vi.clearAllMocks(); |
| 58 | + mocks.resolveProjectAccess.mockResolvedValue({ |
| 59 | + publicId: "prj_abcdefghijklmnopqrstuvwx", |
| 60 | + }); |
| 61 | + mocks.requireReadableProject.mockResolvedValue({ |
| 62 | + actor: { id: "user_1" }, |
| 63 | + project: { id: "project_1" }, |
| 64 | + }); |
| 65 | + mocks.getIntegrationsView.mockResolvedValue({ |
| 66 | + categories: [{ id: "analytics", items: [], title: "Analytics" }], |
| 67 | + connectionCount: 0, |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it("wires verified Google property selection into integration drawers", async () => { |
| 72 | + render( |
| 73 | + await IntegrationsPage({ |
| 74 | + params: Promise.resolve({ project: "prj_abcdefghijklmnopqrstuvwx" }), |
| 75 | + }), |
| 76 | + ); |
| 77 | + |
| 78 | + const props = mocks.integrationCategory.mock.calls[0]?.[0] as { |
| 79 | + actions: ProviderActionHandlers; |
| 80 | + }; |
| 81 | + expect(props.actions.completeGooglePropertySelection).toBe( |
| 82 | + mocks.completeGooglePropertySelection, |
| 83 | + ); |
| 84 | + expect(props.actions.loadStoredGoogleProperties).toBe(mocks.loadStoredGoogleProperties); |
| 85 | + expect(props.actions.saveStoredGoogleProperty).toBe(mocks.saveStoredGoogleProperty); |
| 86 | + }); |
| 87 | +}); |
0 commit comments