forked from bubblelabai/BubbleLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-bubble-flow.ts
More file actions
61 lines (52 loc) · 1.6 KB
/
test-bubble-flow.ts
File metadata and controls
61 lines (52 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Test the API manually
const API_URL = 'http://localhost:3001';
async function testAPI() {
console.log('Testing BubbleFlow API...\n');
// 1. Create a BubbleFlow
const createResponse = await fetch(`${API_URL}/bubble-flow`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: 'Test Greeting Flow',
description: 'A simple greeting flow',
code: `
import { BubbleFlow } from '@bubblelab/bubble-core';
import type { BubbleTriggerEventRegistry } from '@bubblelab/bubble-core';
export class GreetingFlow extends BubbleFlow<'webhook/http'> {
constructor() {
super('greeting-flow', 'Greets the user');
}
async handle(payload: BubbleTriggerEventRegistry['webhook/http']) {
const name = payload.body?.name || 'World';
return {
greeting: \`Hello, \${name}!\`,
timestamp: new Date().toISOString(),
receivedData: payload,
};
}
}
`,
eventType: 'webhook/http',
}),
});
const createResult = await createResponse.json();
console.log('Create response:', createResult);
if (!createResponse.ok) {
console.error('Failed to create flow');
return;
}
// 2. Execute the BubbleFlow
const executeResponse = await fetch(
`${API_URL}/execute-bubble-flow/${createResult.id}`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
payload: { name: 'TypeScript User' },
}),
}
);
const executeResult = await executeResponse.json();
console.log('\nExecute response:', executeResult);
}
testAPI().catch(console.error);