Skip to content

Commit c77bf8c

Browse files
committed
Verify Analytics Data discovery import end to end
1 parent 9e46dd8 commit c77bf8c

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { randomBytes, randomUUID } from "node:crypto";
2+
import { expect } from "@effect/vitest";
3+
import { Effect } from "effect";
4+
import { composePluginApi } from "@executor-js/api/server";
5+
import { openApiHttpPlugin } from "@executor-js/plugin-openapi/api";
6+
import {
7+
AuthTemplateSlug,
8+
ConnectionName,
9+
IntegrationSlug,
10+
ProviderItemId,
11+
} from "@executor-js/sdk/shared";
12+
13+
import { scenario } from "../src/scenario";
14+
import { Api, Target } from "../src/services";
15+
16+
const api = composePluginApi([openApiHttpPlugin()] as const);
17+
18+
scenario(
19+
"Google Analytics Data · public Discovery import exposes report tools",
20+
{ timeout: 120_000 },
21+
Effect.gen(function* () {
22+
const target = yield* Target;
23+
const { client } = yield* Api;
24+
const identity = yield* target.newIdentity();
25+
const apiClient = yield* client(api, identity);
26+
const slug = IntegrationSlug.make(`analytics_${randomBytes(4).toString("hex")}`);
27+
// Fetch Google's public document through the real server import path.
28+
// No Analytics account or authenticated report request is needed.
29+
const added = yield* apiClient.openapi.addSpec({
30+
payload: {
31+
slug,
32+
spec: {
33+
kind: "url",
34+
url: "https://www.googleapis.com/discovery/v1/apis/analyticsdata/v1beta/rest",
35+
},
36+
},
37+
});
38+
yield* Effect.gen(function* () {
39+
expect(added.toolCount).toBeGreaterThan(0);
40+
const providers = yield* apiClient.providers.list();
41+
const provider = providers[0];
42+
if (provider === undefined) return yield* Effect.die("No credential provider available");
43+
yield* apiClient.connections.create({
44+
payload: {
45+
owner: "org",
46+
name: ConnectionName.make("main"),
47+
integration: slug,
48+
template: AuthTemplateSlug.make("googleOAuth2"),
49+
from: { provider, id: ProviderItemId.make(randomUUID()) },
50+
},
51+
});
52+
const tools = yield* apiClient.tools.list({ query: { integration: slug } });
53+
expect(tools.some((tool) => tool.name.endsWith("runReport"))).toBe(true);
54+
expect(tools.some((tool) => tool.name.endsWith("runRealtimeReport"))).toBe(true);
55+
}).pipe(Effect.ensuring(apiClient.openapi.removeSpec({ params: { slug } }).pipe(Effect.orDie)));
56+
}),
57+
);

0 commit comments

Comments
 (0)