-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorkflowAI.test.ts
More file actions
121 lines (108 loc) · 2.9 KB
/
WorkflowAI.test.ts
File metadata and controls
121 lines (108 loc) · 2.9 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import fetchMock from 'jest-fetch-mock';
import { WorkflowAI } from './WorkflowAI.js';
import { z } from './schema/zod/zod.js';
interface TaskInput1 {
a: string;
}
const workflowAI = new WorkflowAI({
url: 'https://test.workflowai.com',
key: 'test',
});
describe('useTask', () => {
it('should return a run function', () => {
const run = workflowAI.agent<TaskInput1, TaskInput1>({
id: 'bla',
schemaId: 2,
});
expect(run).toBeDefined();
});
it('is compatible with the old zod schema', () => {
const task = workflowAI.useTask(
{
taskId: 'detect-company-domain',
schema: {
id: 1,
input: z.object({
messages: z
.array(
z.object({
role: z.enum(['USER', 'ASSISTANT']).optional(),
content: z.string().optional(),
})
)
.optional(),
}),
output: z.object({
company_domain: z.string().nullable().default(null),
failure_assistant_answer: z.string().nullable().default(null),
}),
},
},
{
version: 'production',
}
);
expect(task).toBeDefined();
});
});
describe('sendFeedback', () => {
beforeEach(() => {
fetchMock.resetMocks();
});
it('should successfully send feedback', async () => {
fetchMock.mockResponseOnce(JSON.stringify({}));
await workflowAI.sendFeedback({
feedbackToken: 'test-token',
outcome: 'positive',
comment: 'Great work!',
userID: 'user123',
});
expect(fetchMock).toHaveBeenCalledWith(
'https://test.workflowai.com/v1/feedback',
{
method: 'POST',
body: JSON.stringify({
feedback_token: 'test-token',
outcome: 'positive',
comment: 'Great work!',
user_id: 'user123',
}),
headers: {
'Content-Type': 'application/json',
},
}
);
});
it('should handle negative feedback', async () => {
fetchMock.mockResponseOnce(JSON.stringify({}));
await workflowAI.sendFeedback({
feedbackToken: 'test-token',
outcome: 'negative',
comment: 'Needs improvement',
});
expect(fetchMock).toHaveBeenCalledWith(
'https://test.workflowai.com/v1/feedback',
{
method: 'POST',
body: JSON.stringify({
feedback_token: 'test-token',
outcome: 'negative',
comment: 'Needs improvement',
user_id: undefined,
}),
headers: {
'Content-Type': 'application/json',
},
}
);
});
it('should throw error when feedback request fails', async () => {
fetchMock.mockResponseOnce('', { status: 400 });
await expect(
workflowAI.sendFeedback({
feedbackToken: 'test-token',
outcome: 'positive',
})
).rejects.toThrow('Failed to send feedback');
});
});