@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 122 lines 3.83 KB
Raw
1 import { env, createExecutionContext, waitOnExecutionContext } from 'cloudflare:test';
2 import { describe, it, expect } from 'vitest';
3 import app from '../src/index';
4
5 const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
6 const LIVE_API_TEST_TIMEOUT_MS = 30_000;
7
8 describe('@composio/core Cloudflare Workers compatibility', () => {
9 it('should list the available endpoints', async () => {
10 const request = new IncomingRequest('http://localhost/');
11 const ctx = createExecutionContext();
12 const response = await app.fetch(request, env, ctx);
13 await waitOnExecutionContext(ctx);
14
15 expect(response.status).toBe(200);
16
17 const body = (await response.json()) as {
18 message: string;
19 endpoints: string[];
20 };
21
22 expect(body.message).toContain('Composio Core Platform E2E Test Worker');
23 expect(body.endpoints).toMatchInlineSnapshot(`
24 [
25 "/test/import",
26 "/test/files/upload",
27 "/test/files/download",
28 "/test/hackernews",
29 ]
30 `);
31 });
32
33 it('should import and instantiate Composio without runtime errors', async () => {
34 const request = new IncomingRequest('http://localhost/test/import');
35 const ctx = createExecutionContext();
36 const response = await app.fetch(request, env, ctx);
37 await waitOnExecutionContext(ctx);
38
39 expect(response.status).toBe(200);
40
41 const body = (await response.json()) as {
42 success: boolean;
43 message?: string;
44 error?: string;
45 hasProvider?: boolean;
46 hasTools?: boolean;
47 };
48
49 expect(body.success).toBe(true);
50 expect(body.message).toContain('successfully');
51 expect(body.hasProvider).toBe(true);
52 expect(body.hasTools).toBe(true);
53 });
54
55 it('should throw an error when calling files.upload() in Cloudflare Workers', async () => {
56 const request = new IncomingRequest('http://localhost/test/files/upload');
57 const ctx = createExecutionContext();
58 const response = await app.fetch(request, env, ctx);
59 await waitOnExecutionContext(ctx);
60
61 expect(response.status).toBe(200);
62
63 const body = (await response.json()) as {
64 success: boolean;
65 message?: string;
66 error?: string;
67 };
68
69 expect(body.success).toBe(true);
70 expect(body.message).toContain('correctly throws an error');
71 expect(body.error).toContain('not supported in Cloudflare Workers');
72 });
73
74 it('should throw an error when calling files.download() in Cloudflare Workers', async () => {
75 const request = new IncomingRequest('http://localhost/test/files/download');
76 const ctx = createExecutionContext();
77 const response = await app.fetch(request, env, ctx);
78 await waitOnExecutionContext(ctx);
79
80 expect(response.status).toBe(200);
81
82 const body = (await response.json()) as {
83 success: boolean;
84 message?: string;
85 error?: string;
86 };
87
88 expect(body.success).toBe(true);
89 expect(body.message).toContain('correctly throws an error');
90 expect(body.error).toContain('not supported in Cloudflare Workers');
91 });
92
93 it(
94 'should fetch HackerNews user pg successfully',
95 async () => {
96 const request = new IncomingRequest('http://localhost/test/hackernews');
97 const ctx = createExecutionContext();
98 const response = await app.fetch(request, env, ctx);
99 await waitOnExecutionContext(ctx);
100
101 const body = (await response.json()) as {
102 success: boolean;
103 message?: string;
104 error?: string;
105 data?: {
106 username: string;
107 karma: number;
108 about?: string;
109 };
110 };
111
112 console.log('HackerNews response:', JSON.stringify(body, null, 2));
113
114 expect(response.status).toBe(200);
115 expect(body.success).toBe(true);
116 expect(body.message).toContain('pg');
117 expect(body.data?.username).toBe('pg');
118 expect(body.data?.karma).toBeGreaterThan(0);
119 },
120 LIVE_API_TEST_TIMEOUT_MS
121 );
122 });