Unified · Split
| @@ -0,0 +1,103 @@ | ||
| 1 | +import { randomBytes } from "node:crypto"; | |
| 2 | + | |
| 3 | +import { expect } from "@effect/vitest"; | |
| 4 | +import { Effect } from "effect"; | |
| 5 | +import { composePluginApi } from "@executor-js/api/server"; | |
| 6 | +import { | |
| 7 | + MICROSOFT_AUTH_TEMPLATE_SLUG, | |
| 8 | + MICROSOFT_GRAPH_DEFAULT_PRESET_IDS, | |
| 9 | +} from "@executor-js/plugin-microsoft"; | |
| 10 | +import { microsoftHttpPlugin } from "@executor-js/plugin-microsoft/api"; | |
| 11 | +import { AuthTemplateSlug, ConnectionName, IntegrationSlug } from "@executor-js/sdk/shared"; | |
| 12 | + | |
| 13 | +import { scenario } from "../src/scenario"; | |
| 14 | +import { Api, Target } from "../src/services"; | |
| 15 | + | |
| 16 | +const api = composePluginApi([microsoftHttpPlugin()] as const); | |
| 17 | + | |
| 18 | +type ToolView = { | |
| 19 | + readonly name: string; | |
| 20 | +}; | |
| 21 | + | |
| 22 | +const unique = (prefix: string) => `${prefix}_${randomBytes(4).toString("hex")}`; | |
| 23 | + | |
| 24 | +scenario( | |
| 25 | + "Microsoft Graph: default add stores the full Graph operation catalog", | |
| 26 | + { timeout: 180_000 }, | |
| 27 | + Effect.gen(function* () { | |
| 28 | + const target = yield* Target; | |
| 29 | + const { client: makeApiClient } = yield* Api; | |
| 30 | + const identity = yield* target.newIdentity(); | |
| 31 | + const client = yield* makeApiClient(api, identity); | |
| 32 | + | |
| 33 | + const integration = unique("msgraph_full"); | |
| 34 | + const connection = ConnectionName.make("main"); | |
| 35 | + | |
| 36 | + yield* Effect.ensuring( | |
| 37 | + Effect.gen(function* () { | |
| 38 | + const added = yield* client.microsoft.addGraph({ | |
| 39 | + payload: { | |
| 40 | + presetIds: [...MICROSOFT_GRAPH_DEFAULT_PRESET_IDS], | |
| 41 | + customScopes: [], | |
| 42 | + slug: integration, | |
| 43 | + name: "Microsoft Graph Full Catalog", | |
| 44 | + }, | |
| 45 | + }); | |
| 46 | + expect(added.slug, "the full Graph source keeps the requested slug").toBe(integration); | |
| 47 | + expect( | |
| 48 | + added.toolCount, | |
| 49 | + "the default Microsoft Graph add extracts a large operation catalog", | |
| 50 | + ).toBeGreaterThan(1_000); | |
| 51 | + | |
| 52 | + const config = yield* client.microsoft.getConfig({ | |
| 53 | + params: { slug: integration }, | |
| 54 | + }); | |
| 55 | + expect(config?.microsoftGraphPresetIds, "all default Graph groups are persisted").toEqual([ | |
| 56 | + ...MICROSOFT_GRAPH_DEFAULT_PRESET_IDS, | |
| 57 | + ]); | |
| 58 | + expect(config?.microsoftGraphCoversFullGraph, "the default selection is full Graph").toBe( | |
| 59 | + true, | |
| 60 | + ); | |
| 61 | + | |
| 62 | + yield* client.connections.create({ | |
| 63 | + payload: { | |
| 64 | + owner: "org", | |
| 65 | + name: connection, | |
| 66 | + integration: IntegrationSlug.make(integration), | |
| 67 | + template: AuthTemplateSlug.make(MICROSOFT_AUTH_TEMPLATE_SLUG), | |
| 68 | + value: "token-xyz", | |
| 69 | + }, | |
| 70 | + }); | |
| 71 | + | |
| 72 | + const tools = yield* client.tools.list({ | |
| 73 | + query: { integration: IntegrationSlug.make(integration), connection }, | |
| 74 | + }); | |
| 75 | + const names = tools.map((tool: ToolView) => tool.name); | |
| 76 | + const messageTools = names.filter((name) => name.toLowerCase().includes("message")); | |
| 77 | + const siteTools = names.filter((name) => name.toLowerCase().includes("site")); | |
| 78 | + expect( | |
| 79 | + messageTools, | |
| 80 | + "the retrieved full catalog includes Microsoft message operations", | |
| 81 | + ).not.toEqual([]); | |
| 82 | + expect( | |
| 83 | + siteTools, | |
| 84 | + "the retrieved full catalog includes SharePoint site operations", | |
| 85 | + ).not.toEqual([]); | |
| 86 | + }), | |
| 87 | + Effect.gen(function* () { | |
| 88 | + yield* client.connections | |
| 89 | + .remove({ | |
| 90 | + params: { | |
| 91 | + owner: "org", | |
| 92 | + integration: IntegrationSlug.make(integration), | |
| 93 | + name: connection, | |
| 94 | + }, | |
| 95 | + }) | |
| 96 | + .pipe(Effect.ignore); | |
| 97 | + yield* client.microsoft | |
| 98 | + .removeGraph({ params: { slug: IntegrationSlug.make(integration) } }) | |
| 99 | + .pipe(Effect.ignore); | |
| 100 | + }), | |
| 101 | + ); | |
| 102 | + }), | |
| 103 | +); | |