Hide Analytics section when GA4 OAuth app is pending (#475)
This commit is contained in:
parent
75aec8424f
commit
72eaa09c32
@ -28,10 +28,12 @@ export function GoogleAnalyticsConnectionCard({
|
||||
projectId,
|
||||
onDismiss,
|
||||
dismissing = false,
|
||||
heading,
|
||||
}: {
|
||||
projectId: string;
|
||||
onDismiss?: () => void;
|
||||
dismissing?: boolean;
|
||||
heading?: React.ReactNode;
|
||||
}) {
|
||||
const hosted = isHostedClientAuthMode();
|
||||
const queryClient = useQueryClient();
|
||||
@ -115,6 +117,8 @@ export function GoogleAnalyticsConnectionCard({
|
||||
if (hiddenPendingApproval) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{heading}
|
||||
<IntegrationConnectionCard
|
||||
title="Google Analytics"
|
||||
icon={<GoogleAnalyticsLogo className="size-5" />}
|
||||
@ -206,6 +210,7 @@ export function GoogleAnalyticsConnectionCard({
|
||||
</div>
|
||||
)}
|
||||
</IntegrationConnectionCard>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -63,8 +63,14 @@ export function ProjectSettings({ projectId }: { projectId: string }) {
|
||||
</section>
|
||||
|
||||
<section id="google-analytics" className="space-y-3 scroll-mt-6">
|
||||
<h2 className="text-sm font-medium text-base-content/50">Analytics</h2>
|
||||
<GoogleAnalyticsConnectionCard projectId={projectId} />
|
||||
<GoogleAnalyticsConnectionCard
|
||||
projectId={projectId}
|
||||
heading={
|
||||
<h2 className="text-sm font-medium text-base-content/50">
|
||||
Analytics
|
||||
</h2>
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<DangerSection project={project} canArchive={projects.length > 1} />
|
||||
|
||||
80
src/server/mcp/server.test.ts
Normal file
80
src/server/mcp/server.test.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createOpenSeoMcpServer } from "./server";
|
||||
|
||||
const mcpServerMocks = vi.hoisted(() => ({
|
||||
registerTool: vi.fn<(name: string, ...args: unknown[]) => void>(),
|
||||
}));
|
||||
|
||||
vi.mock("@modelcontextprotocol/server", () => ({
|
||||
McpServer: class {
|
||||
registerTool(name: string, ...args: unknown[]) {
|
||||
mcpServerMocks.registerTool(name, ...args);
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("cloudflare:workers", () => ({
|
||||
DurableObject: vi.fn(),
|
||||
env: {},
|
||||
waitUntil: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/server/mcp/instrumentation", () => ({
|
||||
instrumentMcpToolHandler: (
|
||||
_name: string,
|
||||
_outputSchema: unknown,
|
||||
handler: unknown,
|
||||
) => handler,
|
||||
}));
|
||||
|
||||
describe("createOpenSeoMcpServer", () => {
|
||||
beforeEach(() => {
|
||||
mcpServerMocks.registerTool.mockClear();
|
||||
});
|
||||
|
||||
it("does not expose GA4-backed tools while OAuth approval is pending", () => {
|
||||
createOpenSeoMcpServer({
|
||||
openSeoAuth: {
|
||||
userId: "user-1",
|
||||
userEmail: "user@example.com",
|
||||
organizationId: "org-1",
|
||||
baseUrl: "https://example.com",
|
||||
},
|
||||
});
|
||||
|
||||
const registeredToolNames = mcpServerMocks.registerTool.mock.calls.map(
|
||||
([name]) => name,
|
||||
);
|
||||
|
||||
expect(registeredToolNames).toContain("whoami");
|
||||
expect(registeredToolNames).toContain("get_search_console_performance");
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_organic_landing_pages",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_page_performance",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_key_events",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain("get_search_opportunities");
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_organic_overview",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_traffic_acquisition",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_measurement_health",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_ecommerce_performance",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_site_search",
|
||||
);
|
||||
expect(registeredToolNames).not.toContain(
|
||||
"get_google_analytics_audience_breakdown",
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -51,6 +51,7 @@ import {
|
||||
getSearchConsolePerformanceTool,
|
||||
inspectUrlsTool,
|
||||
} from "@/server/mcp/tools/search-console-tools";
|
||||
import { GA4_OAUTH_APP_PENDING } from "@/shared/ga4";
|
||||
import {
|
||||
getAuditIssuesTool,
|
||||
getAuditPagesTool,
|
||||
@ -166,6 +167,7 @@ export function createOpenSeoMcpServer(authProps: McpProps) {
|
||||
register(getKeywordMetricsTool);
|
||||
register(getSearchConsolePerformanceTool);
|
||||
register(inspectUrlsTool);
|
||||
if (!GA4_OAUTH_APP_PENDING) {
|
||||
register(getGoogleAnalyticsOrganicLandingPagesTool);
|
||||
register(getGoogleAnalyticsPagePerformanceTool);
|
||||
register(getGoogleAnalyticsKeyEventsTool);
|
||||
@ -176,6 +178,7 @@ export function createOpenSeoMcpServer(authProps: McpProps) {
|
||||
register(getGoogleAnalyticsEcommercePerformanceTool);
|
||||
register(getGoogleAnalyticsSiteSearchTool);
|
||||
register(getGoogleAnalyticsAudienceBreakdownTool);
|
||||
}
|
||||
register(runSiteAuditTool);
|
||||
register(getAuditStatusTool);
|
||||
register(getAuditIssuesTool);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user