@vibescope/mcp-server 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +84 -84
  2. package/README.md +194 -194
  3. package/dist/api-client/tasks.d.ts +1 -0
  4. package/dist/cli-init.js +21 -21
  5. package/dist/cli.js +26 -26
  6. package/dist/handlers/tasks.js +7 -1
  7. package/dist/handlers/tool-docs.js +1216 -1216
  8. package/dist/index.js +73 -73
  9. package/dist/templates/agent-guidelines.d.ts +1 -1
  10. package/dist/templates/agent-guidelines.js +205 -205
  11. package/dist/templates/help-content.js +1621 -1621
  12. package/dist/tools/bodies-of-work.js +6 -6
  13. package/dist/tools/cloud-agents.js +22 -22
  14. package/dist/tools/milestones.js +2 -2
  15. package/dist/tools/requests.js +1 -1
  16. package/dist/tools/session.js +11 -11
  17. package/dist/tools/sprints.js +9 -9
  18. package/dist/tools/tasks.js +43 -35
  19. package/dist/tools/worktrees.js +14 -14
  20. package/dist/utils.js +11 -11
  21. package/docs/TOOLS.md +2687 -2685
  22. package/package.json +53 -53
  23. package/scripts/generate-docs.ts +212 -212
  24. package/scripts/version-bump.ts +203 -203
  25. package/src/api-client/blockers.ts +86 -86
  26. package/src/api-client/bodies-of-work.ts +194 -194
  27. package/src/api-client/chat.ts +50 -50
  28. package/src/api-client/connectors.ts +152 -152
  29. package/src/api-client/cost.ts +185 -185
  30. package/src/api-client/decisions.ts +87 -87
  31. package/src/api-client/deployment.ts +313 -313
  32. package/src/api-client/discovery.ts +81 -81
  33. package/src/api-client/fallback.ts +52 -52
  34. package/src/api-client/file-checkouts.ts +115 -115
  35. package/src/api-client/findings.ts +100 -100
  36. package/src/api-client/git-issues.ts +88 -88
  37. package/src/api-client/ideas.ts +112 -112
  38. package/src/api-client/index.ts +592 -592
  39. package/src/api-client/milestones.ts +83 -83
  40. package/src/api-client/organizations.ts +185 -185
  41. package/src/api-client/progress.ts +94 -94
  42. package/src/api-client/project.ts +181 -181
  43. package/src/api-client/requests.ts +54 -54
  44. package/src/api-client/session.ts +220 -220
  45. package/src/api-client/sprints.ts +227 -227
  46. package/src/api-client/subtasks.ts +57 -57
  47. package/src/api-client/tasks.ts +451 -450
  48. package/src/api-client/types.ts +32 -32
  49. package/src/api-client/validation.ts +60 -60
  50. package/src/api-client/worktrees.ts +53 -53
  51. package/src/api-client.test.ts +847 -847
  52. package/src/api-client.ts +2728 -2728
  53. package/src/cli-init.ts +558 -558
  54. package/src/cli.test.ts +284 -284
  55. package/src/cli.ts +204 -204
  56. package/src/handlers/__test-setup__.ts +240 -240
  57. package/src/handlers/__test-utils__.ts +89 -89
  58. package/src/handlers/blockers.test.ts +468 -468
  59. package/src/handlers/blockers.ts +172 -172
  60. package/src/handlers/bodies-of-work.test.ts +704 -704
  61. package/src/handlers/bodies-of-work.ts +526 -526
  62. package/src/handlers/chat.test.ts +185 -185
  63. package/src/handlers/chat.ts +101 -101
  64. package/src/handlers/cloud-agents.test.ts +438 -438
  65. package/src/handlers/cloud-agents.ts +156 -156
  66. package/src/handlers/connectors.test.ts +834 -834
  67. package/src/handlers/connectors.ts +229 -229
  68. package/src/handlers/cost.test.ts +462 -462
  69. package/src/handlers/cost.ts +285 -285
  70. package/src/handlers/decisions.test.ts +382 -382
  71. package/src/handlers/decisions.ts +153 -153
  72. package/src/handlers/deployment.test.ts +551 -551
  73. package/src/handlers/deployment.ts +570 -570
  74. package/src/handlers/discovery.test.ts +206 -206
  75. package/src/handlers/discovery.ts +433 -433
  76. package/src/handlers/fallback.test.ts +537 -537
  77. package/src/handlers/fallback.ts +194 -194
  78. package/src/handlers/file-checkouts.test.ts +750 -750
  79. package/src/handlers/file-checkouts.ts +185 -185
  80. package/src/handlers/findings.test.ts +633 -633
  81. package/src/handlers/findings.ts +239 -239
  82. package/src/handlers/git-issues.test.ts +631 -631
  83. package/src/handlers/git-issues.ts +136 -136
  84. package/src/handlers/ideas.test.ts +644 -644
  85. package/src/handlers/ideas.ts +207 -207
  86. package/src/handlers/index.ts +93 -93
  87. package/src/handlers/milestones.test.ts +475 -475
  88. package/src/handlers/milestones.ts +180 -180
  89. package/src/handlers/organizations.test.ts +826 -826
  90. package/src/handlers/organizations.ts +315 -315
  91. package/src/handlers/progress.test.ts +269 -269
  92. package/src/handlers/progress.ts +77 -77
  93. package/src/handlers/project.test.ts +546 -546
  94. package/src/handlers/project.ts +245 -245
  95. package/src/handlers/requests.test.ts +303 -303
  96. package/src/handlers/requests.ts +99 -99
  97. package/src/handlers/roles.test.ts +305 -305
  98. package/src/handlers/roles.ts +219 -219
  99. package/src/handlers/session.test.ts +998 -998
  100. package/src/handlers/session.ts +1105 -1105
  101. package/src/handlers/sprints.test.ts +732 -732
  102. package/src/handlers/sprints.ts +537 -537
  103. package/src/handlers/tasks.test.ts +931 -931
  104. package/src/handlers/tasks.ts +1144 -1137
  105. package/src/handlers/tool-categories.test.ts +66 -66
  106. package/src/handlers/tool-docs.test.ts +511 -511
  107. package/src/handlers/tool-docs.ts +1595 -1595
  108. package/src/handlers/types.test.ts +259 -259
  109. package/src/handlers/types.ts +176 -176
  110. package/src/handlers/validation.test.ts +582 -582
  111. package/src/handlers/validation.ts +164 -164
  112. package/src/handlers/version.ts +63 -63
  113. package/src/index.test.ts +674 -674
  114. package/src/index.ts +884 -884
  115. package/src/setup.test.ts +243 -243
  116. package/src/setup.ts +410 -410
  117. package/src/templates/agent-guidelines.ts +233 -233
  118. package/src/templates/help-content.ts +1751 -1751
  119. package/src/token-tracking.test.ts +463 -463
  120. package/src/token-tracking.ts +167 -167
  121. package/src/tools/blockers.ts +122 -122
  122. package/src/tools/bodies-of-work.ts +283 -283
  123. package/src/tools/chat.ts +72 -72
  124. package/src/tools/cloud-agents.ts +101 -101
  125. package/src/tools/connectors.ts +191 -191
  126. package/src/tools/cost.ts +111 -111
  127. package/src/tools/decisions.ts +111 -111
  128. package/src/tools/deployment.ts +455 -455
  129. package/src/tools/discovery.ts +76 -76
  130. package/src/tools/fallback.ts +111 -111
  131. package/src/tools/features.ts +154 -154
  132. package/src/tools/file-checkouts.ts +145 -145
  133. package/src/tools/findings.ts +101 -101
  134. package/src/tools/git-issues.ts +130 -130
  135. package/src/tools/ideas.ts +162 -162
  136. package/src/tools/index.ts +145 -145
  137. package/src/tools/milestones.ts +118 -118
  138. package/src/tools/organizations.ts +224 -224
  139. package/src/tools/persona-templates.ts +25 -25
  140. package/src/tools/progress.ts +73 -73
  141. package/src/tools/project.ts +210 -210
  142. package/src/tools/requests.ts +68 -68
  143. package/src/tools/roles.ts +112 -112
  144. package/src/tools/session.ts +181 -181
  145. package/src/tools/sprints.ts +298 -298
  146. package/src/tools/tasks.ts +583 -575
  147. package/src/tools/tools.test.ts +222 -222
  148. package/src/tools/types.ts +9 -9
  149. package/src/tools/validation.ts +75 -75
  150. package/src/tools/version.ts +34 -34
  151. package/src/tools/worktrees.ts +66 -66
  152. package/src/tools.test.ts +416 -416
  153. package/src/utils.test.ts +1014 -1014
  154. package/src/utils.ts +586 -586
  155. package/src/validators.test.ts +223 -223
  156. package/src/validators.ts +249 -249
  157. package/src/version.ts +162 -162
  158. package/tsconfig.json +16 -16
  159. package/vitest.config.ts +14 -14
  160. package/dist/tools.d.ts +0 -2
  161. package/dist/tools.js +0 -3602
@@ -1,834 +1,834 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import {
3
- getConnectors,
4
- getConnector,
5
- addConnector,
6
- updateConnector,
7
- deleteConnector,
8
- testConnector,
9
- getConnectorEvents,
10
- } from './connectors.js';
11
- import { ValidationError } from '../validators.js';
12
- import { createMockContext } from './__test-utils__.js';
13
- import { mockApiClient } from './__test-setup__.js';
14
-
15
- // ============================================================================
16
- // getConnectors Tests
17
- // ============================================================================
18
-
19
- describe('getConnectors', () => {
20
- beforeEach(() => {});
21
-
22
- it('should throw error for missing project_id', async () => {
23
- const ctx = createMockContext();
24
-
25
- await expect(getConnectors({}, ctx)).rejects.toThrow(ValidationError);
26
- });
27
-
28
- it('should throw error for invalid project_id UUID', async () => {
29
- const ctx = createMockContext();
30
-
31
- await expect(
32
- getConnectors({ project_id: 'invalid' }, ctx)
33
- ).rejects.toThrow(ValidationError);
34
- });
35
-
36
- it('should return connectors successfully', async () => {
37
- const mockConnectors = [
38
- { id: 'conn-1', name: 'Slack Notifications', type: 'slack' },
39
- { id: 'conn-2', name: 'Webhook', type: 'webhook' },
40
- ];
41
- mockApiClient.getConnectors.mockResolvedValue({
42
- ok: true,
43
- data: { connectors: mockConnectors, total: 2 },
44
- });
45
- const ctx = createMockContext();
46
-
47
- const result = await getConnectors(
48
- { project_id: '123e4567-e89b-12d3-a456-426614174000' },
49
- ctx
50
- );
51
-
52
- expect(result.result).toMatchObject({
53
- connectors: mockConnectors,
54
- total: 2,
55
- });
56
- });
57
-
58
- it('should filter by type', async () => {
59
- mockApiClient.getConnectors.mockResolvedValue({
60
- ok: true,
61
- data: { connectors: [], total: 0 },
62
- });
63
- const ctx = createMockContext();
64
-
65
- await getConnectors(
66
- {
67
- project_id: '123e4567-e89b-12d3-a456-426614174000',
68
- type: 'slack',
69
- },
70
- ctx
71
- );
72
-
73
- expect(mockApiClient.getConnectors).toHaveBeenCalledWith(
74
- '123e4567-e89b-12d3-a456-426614174000',
75
- expect.objectContaining({ type: 'slack' })
76
- );
77
- });
78
-
79
- it('should filter by status', async () => {
80
- mockApiClient.getConnectors.mockResolvedValue({
81
- ok: true,
82
- data: { connectors: [], total: 0 },
83
- });
84
- const ctx = createMockContext();
85
-
86
- await getConnectors(
87
- {
88
- project_id: '123e4567-e89b-12d3-a456-426614174000',
89
- status: 'active',
90
- },
91
- ctx
92
- );
93
-
94
- expect(mockApiClient.getConnectors).toHaveBeenCalledWith(
95
- '123e4567-e89b-12d3-a456-426614174000',
96
- expect.objectContaining({ status: 'active' })
97
- );
98
- });
99
-
100
- it('should throw error for invalid type', async () => {
101
- const ctx = createMockContext();
102
-
103
- await expect(
104
- getConnectors(
105
- {
106
- project_id: '123e4567-e89b-12d3-a456-426614174000',
107
- type: 'invalid_type',
108
- },
109
- ctx
110
- )
111
- ).rejects.toThrow(ValidationError);
112
- });
113
-
114
- it('should throw error for invalid status', async () => {
115
- const ctx = createMockContext();
116
-
117
- await expect(
118
- getConnectors(
119
- {
120
- project_id: '123e4567-e89b-12d3-a456-426614174000',
121
- status: 'invalid_status',
122
- },
123
- ctx
124
- )
125
- ).rejects.toThrow(ValidationError);
126
- });
127
-
128
- it('should handle pagination with limit and offset', async () => {
129
- mockApiClient.getConnectors.mockResolvedValue({
130
- ok: true,
131
- data: { connectors: [], total: 100 },
132
- });
133
- const ctx = createMockContext();
134
-
135
- await getConnectors(
136
- {
137
- project_id: '123e4567-e89b-12d3-a456-426614174000',
138
- limit: 10,
139
- offset: 20,
140
- },
141
- ctx
142
- );
143
-
144
- expect(mockApiClient.getConnectors).toHaveBeenCalledWith(
145
- '123e4567-e89b-12d3-a456-426614174000',
146
- expect.objectContaining({ limit: 10, offset: 20 })
147
- );
148
- });
149
-
150
- it('should handle API error', async () => {
151
- mockApiClient.getConnectors.mockResolvedValue({
152
- ok: false,
153
- error: 'Database error',
154
- });
155
- const ctx = createMockContext();
156
-
157
- const result = await getConnectors(
158
- { project_id: '123e4567-e89b-12d3-a456-426614174000' },
159
- ctx
160
- );
161
-
162
- expect(result.result.error).toBe('Database error');
163
- });
164
- });
165
-
166
- // ============================================================================
167
- // getConnector Tests
168
- // ============================================================================
169
-
170
- describe('getConnector', () => {
171
- beforeEach(() => {});
172
-
173
- it('should throw error for missing connector_id', async () => {
174
- const ctx = createMockContext();
175
-
176
- await expect(getConnector({}, ctx)).rejects.toThrow(ValidationError);
177
- });
178
-
179
- it('should throw error for invalid connector_id UUID', async () => {
180
- const ctx = createMockContext();
181
-
182
- await expect(
183
- getConnector({ connector_id: 'invalid' }, ctx)
184
- ).rejects.toThrow(ValidationError);
185
- });
186
-
187
- it('should return connector details', async () => {
188
- const mockConnector = {
189
- id: 'conn-1',
190
- name: 'Slack Bot',
191
- type: 'slack',
192
- config: { webhook_url: 'https://hooks.slack.com/...' },
193
- events: { task_completed: true, blocker_added: true },
194
- };
195
- mockApiClient.getConnector.mockResolvedValue({
196
- ok: true,
197
- data: mockConnector,
198
- });
199
- const ctx = createMockContext();
200
-
201
- const result = await getConnector(
202
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
203
- ctx
204
- );
205
-
206
- expect(result.result).toMatchObject(mockConnector);
207
- });
208
-
209
- it('should handle API error', async () => {
210
- mockApiClient.getConnector.mockResolvedValue({
211
- ok: false,
212
- error: 'Connector not found',
213
- });
214
- const ctx = createMockContext();
215
-
216
- const result = await getConnector(
217
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
218
- ctx
219
- );
220
-
221
- expect(result.result.error).toBe('Connector not found');
222
- });
223
- });
224
-
225
- // ============================================================================
226
- // addConnector Tests
227
- // ============================================================================
228
-
229
- describe('addConnector', () => {
230
- beforeEach(() => {});
231
-
232
- it('should throw error for missing project_id', async () => {
233
- const ctx = createMockContext();
234
-
235
- await expect(
236
- addConnector({ name: 'Test', type: 'webhook' }, ctx)
237
- ).rejects.toThrow(ValidationError);
238
- });
239
-
240
- it('should throw error for missing name', async () => {
241
- const ctx = createMockContext();
242
-
243
- await expect(
244
- addConnector(
245
- {
246
- project_id: '123e4567-e89b-12d3-a456-426614174000',
247
- type: 'webhook',
248
- },
249
- ctx
250
- )
251
- ).rejects.toThrow(ValidationError);
252
- });
253
-
254
- it('should throw error for missing type', async () => {
255
- const ctx = createMockContext();
256
-
257
- await expect(
258
- addConnector(
259
- {
260
- project_id: '123e4567-e89b-12d3-a456-426614174000',
261
- name: 'Test',
262
- },
263
- ctx
264
- )
265
- ).rejects.toThrow(ValidationError);
266
- });
267
-
268
- it('should throw error for invalid type', async () => {
269
- const ctx = createMockContext();
270
-
271
- await expect(
272
- addConnector(
273
- {
274
- project_id: '123e4567-e89b-12d3-a456-426614174000',
275
- name: 'Test',
276
- type: 'invalid_type',
277
- },
278
- ctx
279
- )
280
- ).rejects.toThrow(ValidationError);
281
- });
282
-
283
- it('should create connector with minimal params', async () => {
284
- mockApiClient.addConnector.mockResolvedValue({
285
- ok: true,
286
- data: { connector_id: 'conn-new' },
287
- });
288
- const ctx = createMockContext();
289
-
290
- const result = await addConnector(
291
- {
292
- project_id: '123e4567-e89b-12d3-a456-426614174000',
293
- name: 'My Webhook',
294
- type: 'webhook',
295
- },
296
- ctx
297
- );
298
-
299
- expect(result.result).toMatchObject({
300
- connector_id: 'conn-new',
301
- });
302
- });
303
-
304
- it('should create connector with all params', async () => {
305
- mockApiClient.addConnector.mockResolvedValue({
306
- ok: true,
307
- data: { connector_id: 'conn-new' },
308
- });
309
- const ctx = createMockContext();
310
-
311
- await addConnector(
312
- {
313
- project_id: '123e4567-e89b-12d3-a456-426614174000',
314
- name: 'Slack Alerts',
315
- type: 'slack',
316
- description: 'Send alerts to Slack',
317
- config: { webhook_url: 'https://hooks.slack.com/...' },
318
- events: { task_completed: true, deployment_success: true },
319
- },
320
- ctx
321
- );
322
-
323
- expect(mockApiClient.addConnector).toHaveBeenCalledWith(
324
- '123e4567-e89b-12d3-a456-426614174000',
325
- expect.objectContaining({
326
- name: 'Slack Alerts',
327
- type: 'slack',
328
- description: 'Send alerts to Slack',
329
- config: { webhook_url: 'https://hooks.slack.com/...' },
330
- events: { task_completed: true, deployment_success: true },
331
- })
332
- );
333
- });
334
-
335
- it('should accept all valid connector types', async () => {
336
- const ctx = createMockContext();
337
- const validTypes = ['webhook', 'slack', 'discord', 'github', 'custom'];
338
-
339
- for (const type of validTypes) {
340
- mockApiClient.addConnector.mockResolvedValue({
341
- ok: true,
342
- data: { connector_id: `conn-${type}` },
343
- });
344
-
345
- const result = await addConnector(
346
- {
347
- project_id: '123e4567-e89b-12d3-a456-426614174000',
348
- name: `Test ${type}`,
349
- type,
350
- },
351
- ctx
352
- );
353
-
354
- expect(result.result.connector_id).toBe(`conn-${type}`);
355
- }
356
- });
357
-
358
- it('should handle API error', async () => {
359
- mockApiClient.addConnector.mockResolvedValue({
360
- ok: false,
361
- error: 'Project not found',
362
- });
363
- const ctx = createMockContext();
364
-
365
- const result = await addConnector(
366
- {
367
- project_id: '123e4567-e89b-12d3-a456-426614174000',
368
- name: 'Test',
369
- type: 'webhook',
370
- },
371
- ctx
372
- );
373
-
374
- expect(result.result.error).toBe('Project not found');
375
- });
376
- });
377
-
378
- // ============================================================================
379
- // updateConnector Tests
380
- // ============================================================================
381
-
382
- describe('updateConnector', () => {
383
- beforeEach(() => {});
384
-
385
- it('should throw error for missing connector_id', async () => {
386
- const ctx = createMockContext();
387
-
388
- await expect(
389
- updateConnector({ name: 'Updated Name' }, ctx)
390
- ).rejects.toThrow(ValidationError);
391
- });
392
-
393
- it('should throw error for invalid connector_id UUID', async () => {
394
- const ctx = createMockContext();
395
-
396
- await expect(
397
- updateConnector({ connector_id: 'invalid', name: 'Updated' }, ctx)
398
- ).rejects.toThrow(ValidationError);
399
- });
400
-
401
- it('should update connector name', async () => {
402
- mockApiClient.updateConnector.mockResolvedValue({
403
- ok: true,
404
- data: { updated: true },
405
- });
406
- const ctx = createMockContext();
407
-
408
- const result = await updateConnector(
409
- {
410
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
411
- name: 'New Name',
412
- },
413
- ctx
414
- );
415
-
416
- expect(result.result).toMatchObject({ updated: true });
417
- expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
418
- '123e4567-e89b-12d3-a456-426614174000',
419
- expect.objectContaining({ name: 'New Name' })
420
- );
421
- });
422
-
423
- it('should update connector config', async () => {
424
- mockApiClient.updateConnector.mockResolvedValue({
425
- ok: true,
426
- data: { updated: true },
427
- });
428
- const ctx = createMockContext();
429
-
430
- await updateConnector(
431
- {
432
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
433
- config: { webhook_url: 'https://new-url.com' },
434
- },
435
- ctx
436
- );
437
-
438
- expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
439
- '123e4567-e89b-12d3-a456-426614174000',
440
- expect.objectContaining({
441
- config: { webhook_url: 'https://new-url.com' },
442
- })
443
- );
444
- });
445
-
446
- it('should update connector events', async () => {
447
- mockApiClient.updateConnector.mockResolvedValue({
448
- ok: true,
449
- data: { updated: true },
450
- });
451
- const ctx = createMockContext();
452
-
453
- await updateConnector(
454
- {
455
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
456
- events: { task_completed: false, blocker_added: true },
457
- },
458
- ctx
459
- );
460
-
461
- expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
462
- '123e4567-e89b-12d3-a456-426614174000',
463
- expect.objectContaining({
464
- events: { task_completed: false, blocker_added: true },
465
- })
466
- );
467
- });
468
-
469
- it('should update connector status to active', async () => {
470
- mockApiClient.updateConnector.mockResolvedValue({
471
- ok: true,
472
- data: { updated: true },
473
- });
474
- const ctx = createMockContext();
475
-
476
- await updateConnector(
477
- {
478
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
479
- status: 'active',
480
- },
481
- ctx
482
- );
483
-
484
- expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
485
- '123e4567-e89b-12d3-a456-426614174000',
486
- expect.objectContaining({ status: 'active' })
487
- );
488
- });
489
-
490
- it('should update connector status to disabled', async () => {
491
- mockApiClient.updateConnector.mockResolvedValue({
492
- ok: true,
493
- data: { updated: true },
494
- });
495
- const ctx = createMockContext();
496
-
497
- await updateConnector(
498
- {
499
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
500
- status: 'disabled',
501
- },
502
- ctx
503
- );
504
-
505
- expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
506
- '123e4567-e89b-12d3-a456-426614174000',
507
- expect.objectContaining({ status: 'disabled' })
508
- );
509
- });
510
-
511
- it('should throw error for invalid status', async () => {
512
- const ctx = createMockContext();
513
-
514
- await expect(
515
- updateConnector(
516
- {
517
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
518
- status: 'invalid_status',
519
- },
520
- ctx
521
- )
522
- ).rejects.toThrow(ValidationError);
523
- });
524
-
525
- it('should handle API error', async () => {
526
- mockApiClient.updateConnector.mockResolvedValue({
527
- ok: false,
528
- error: 'Connector not found',
529
- });
530
- const ctx = createMockContext();
531
-
532
- const result = await updateConnector(
533
- {
534
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
535
- name: 'Updated',
536
- },
537
- ctx
538
- );
539
-
540
- expect(result.result.error).toBe('Connector not found');
541
- });
542
- });
543
-
544
- // ============================================================================
545
- // deleteConnector Tests
546
- // ============================================================================
547
-
548
- describe('deleteConnector', () => {
549
- beforeEach(() => {});
550
-
551
- it('should throw error for missing connector_id', async () => {
552
- const ctx = createMockContext();
553
-
554
- await expect(deleteConnector({}, ctx)).rejects.toThrow(ValidationError);
555
- });
556
-
557
- it('should throw error for invalid connector_id UUID', async () => {
558
- const ctx = createMockContext();
559
-
560
- await expect(
561
- deleteConnector({ connector_id: 'invalid' }, ctx)
562
- ).rejects.toThrow(ValidationError);
563
- });
564
-
565
- it('should delete connector successfully', async () => {
566
- mockApiClient.deleteConnector.mockResolvedValue({
567
- ok: true,
568
- data: { deleted: true },
569
- });
570
- const ctx = createMockContext();
571
-
572
- const result = await deleteConnector(
573
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
574
- ctx
575
- );
576
-
577
- expect(result.result).toMatchObject({ deleted: true });
578
- });
579
-
580
- it('should handle API error', async () => {
581
- mockApiClient.deleteConnector.mockResolvedValue({
582
- ok: false,
583
- error: 'Connector not found',
584
- });
585
- const ctx = createMockContext();
586
-
587
- const result = await deleteConnector(
588
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
589
- ctx
590
- );
591
-
592
- expect(result.result.error).toBe('Connector not found');
593
- });
594
- });
595
-
596
- // ============================================================================
597
- // testConnector Tests
598
- // ============================================================================
599
-
600
- describe('testConnector', () => {
601
- beforeEach(() => {});
602
-
603
- it('should throw error for missing connector_id', async () => {
604
- const ctx = createMockContext();
605
-
606
- await expect(testConnector({}, ctx)).rejects.toThrow(ValidationError);
607
- });
608
-
609
- it('should throw error for invalid connector_id UUID', async () => {
610
- const ctx = createMockContext();
611
-
612
- await expect(
613
- testConnector({ connector_id: 'invalid' }, ctx)
614
- ).rejects.toThrow(ValidationError);
615
- });
616
-
617
- it('should test connector successfully', async () => {
618
- mockApiClient.testConnector.mockResolvedValue({
619
- ok: true,
620
- data: { success: true, message: 'Test event sent' },
621
- });
622
- const ctx = createMockContext();
623
-
624
- const result = await testConnector(
625
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
626
- ctx
627
- );
628
-
629
- expect(result.result).toMatchObject({
630
- success: true,
631
- message: 'Test event sent',
632
- });
633
- });
634
-
635
- it('should handle test failure', async () => {
636
- mockApiClient.testConnector.mockResolvedValue({
637
- ok: true,
638
- data: { success: false, error: 'Webhook returned 404' },
639
- });
640
- const ctx = createMockContext();
641
-
642
- const result = await testConnector(
643
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
644
- ctx
645
- );
646
-
647
- expect(result.result).toMatchObject({
648
- success: false,
649
- error: 'Webhook returned 404',
650
- });
651
- });
652
-
653
- it('should handle API error', async () => {
654
- mockApiClient.testConnector.mockResolvedValue({
655
- ok: false,
656
- error: 'Connector not found',
657
- });
658
- const ctx = createMockContext();
659
-
660
- const result = await testConnector(
661
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
662
- ctx
663
- );
664
-
665
- expect(result.result.error).toBe('Connector not found');
666
- });
667
- });
668
-
669
- // ============================================================================
670
- // getConnectorEvents Tests
671
- // ============================================================================
672
-
673
- describe('getConnectorEvents', () => {
674
- beforeEach(() => {});
675
-
676
- it('should throw error when neither connector_id nor project_id provided', async () => {
677
- const ctx = createMockContext();
678
-
679
- const result = await getConnectorEvents({}, ctx);
680
-
681
- expect(result.result.error).toBe(
682
- 'Either connector_id or project_id is required'
683
- );
684
- });
685
-
686
- it('should throw error for invalid connector_id UUID', async () => {
687
- const ctx = createMockContext();
688
-
689
- await expect(
690
- getConnectorEvents({ connector_id: 'invalid' }, ctx)
691
- ).rejects.toThrow(ValidationError);
692
- });
693
-
694
- it('should throw error for invalid project_id UUID', async () => {
695
- const ctx = createMockContext();
696
-
697
- await expect(
698
- getConnectorEvents({ project_id: 'invalid' }, ctx)
699
- ).rejects.toThrow(ValidationError);
700
- });
701
-
702
- it('should get events by connector_id', async () => {
703
- const mockEvents = [
704
- { id: 'evt-1', event_type: 'task_completed', status: 'sent' },
705
- { id: 'evt-2', event_type: 'blocker_added', status: 'failed' },
706
- ];
707
- mockApiClient.getConnectorEvents.mockResolvedValue({
708
- ok: true,
709
- data: { events: mockEvents, total: 2 },
710
- });
711
- const ctx = createMockContext();
712
-
713
- const result = await getConnectorEvents(
714
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
715
- ctx
716
- );
717
-
718
- expect(result.result).toMatchObject({
719
- events: mockEvents,
720
- total: 2,
721
- });
722
- });
723
-
724
- it('should get events by project_id', async () => {
725
- mockApiClient.getConnectorEvents.mockResolvedValue({
726
- ok: true,
727
- data: { events: [], total: 0 },
728
- });
729
- const ctx = createMockContext();
730
-
731
- await getConnectorEvents(
732
- { project_id: '123e4567-e89b-12d3-a456-426614174000' },
733
- ctx
734
- );
735
-
736
- expect(mockApiClient.getConnectorEvents).toHaveBeenCalledWith(
737
- expect.objectContaining({
738
- project_id: '123e4567-e89b-12d3-a456-426614174000',
739
- })
740
- );
741
- });
742
-
743
- it('should filter by status', async () => {
744
- mockApiClient.getConnectorEvents.mockResolvedValue({
745
- ok: true,
746
- data: { events: [], total: 0 },
747
- });
748
- const ctx = createMockContext();
749
-
750
- await getConnectorEvents(
751
- {
752
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
753
- status: 'failed',
754
- },
755
- ctx
756
- );
757
-
758
- expect(mockApiClient.getConnectorEvents).toHaveBeenCalledWith(
759
- expect.objectContaining({ status: 'failed' })
760
- );
761
- });
762
-
763
- it('should accept all valid event statuses', async () => {
764
- const ctx = createMockContext();
765
- const validStatuses = ['pending', 'sent', 'failed', 'retrying'];
766
-
767
- for (const status of validStatuses) {
768
- mockApiClient.getConnectorEvents.mockResolvedValue({
769
- ok: true,
770
- data: { events: [], total: 0 },
771
- });
772
-
773
- const result = await getConnectorEvents(
774
- {
775
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
776
- status,
777
- },
778
- ctx
779
- );
780
-
781
- expect(result.result.events).toBeDefined();
782
- }
783
- });
784
-
785
- it('should throw error for invalid status', async () => {
786
- const ctx = createMockContext();
787
-
788
- await expect(
789
- getConnectorEvents(
790
- {
791
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
792
- status: 'invalid_status',
793
- },
794
- ctx
795
- )
796
- ).rejects.toThrow(ValidationError);
797
- });
798
-
799
- it('should handle pagination', async () => {
800
- mockApiClient.getConnectorEvents.mockResolvedValue({
801
- ok: true,
802
- data: { events: [], total: 100 },
803
- });
804
- const ctx = createMockContext();
805
-
806
- await getConnectorEvents(
807
- {
808
- connector_id: '123e4567-e89b-12d3-a456-426614174000',
809
- limit: 25,
810
- offset: 50,
811
- },
812
- ctx
813
- );
814
-
815
- expect(mockApiClient.getConnectorEvents).toHaveBeenCalledWith(
816
- expect.objectContaining({ limit: 25, offset: 50 })
817
- );
818
- });
819
-
820
- it('should handle API error', async () => {
821
- mockApiClient.getConnectorEvents.mockResolvedValue({
822
- ok: false,
823
- error: 'Database error',
824
- });
825
- const ctx = createMockContext();
826
-
827
- const result = await getConnectorEvents(
828
- { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
829
- ctx
830
- );
831
-
832
- expect(result.result.error).toBe('Database error');
833
- });
834
- });
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import {
3
+ getConnectors,
4
+ getConnector,
5
+ addConnector,
6
+ updateConnector,
7
+ deleteConnector,
8
+ testConnector,
9
+ getConnectorEvents,
10
+ } from './connectors.js';
11
+ import { ValidationError } from '../validators.js';
12
+ import { createMockContext } from './__test-utils__.js';
13
+ import { mockApiClient } from './__test-setup__.js';
14
+
15
+ // ============================================================================
16
+ // getConnectors Tests
17
+ // ============================================================================
18
+
19
+ describe('getConnectors', () => {
20
+ beforeEach(() => {});
21
+
22
+ it('should throw error for missing project_id', async () => {
23
+ const ctx = createMockContext();
24
+
25
+ await expect(getConnectors({}, ctx)).rejects.toThrow(ValidationError);
26
+ });
27
+
28
+ it('should throw error for invalid project_id UUID', async () => {
29
+ const ctx = createMockContext();
30
+
31
+ await expect(
32
+ getConnectors({ project_id: 'invalid' }, ctx)
33
+ ).rejects.toThrow(ValidationError);
34
+ });
35
+
36
+ it('should return connectors successfully', async () => {
37
+ const mockConnectors = [
38
+ { id: 'conn-1', name: 'Slack Notifications', type: 'slack' },
39
+ { id: 'conn-2', name: 'Webhook', type: 'webhook' },
40
+ ];
41
+ mockApiClient.getConnectors.mockResolvedValue({
42
+ ok: true,
43
+ data: { connectors: mockConnectors, total: 2 },
44
+ });
45
+ const ctx = createMockContext();
46
+
47
+ const result = await getConnectors(
48
+ { project_id: '123e4567-e89b-12d3-a456-426614174000' },
49
+ ctx
50
+ );
51
+
52
+ expect(result.result).toMatchObject({
53
+ connectors: mockConnectors,
54
+ total: 2,
55
+ });
56
+ });
57
+
58
+ it('should filter by type', async () => {
59
+ mockApiClient.getConnectors.mockResolvedValue({
60
+ ok: true,
61
+ data: { connectors: [], total: 0 },
62
+ });
63
+ const ctx = createMockContext();
64
+
65
+ await getConnectors(
66
+ {
67
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
68
+ type: 'slack',
69
+ },
70
+ ctx
71
+ );
72
+
73
+ expect(mockApiClient.getConnectors).toHaveBeenCalledWith(
74
+ '123e4567-e89b-12d3-a456-426614174000',
75
+ expect.objectContaining({ type: 'slack' })
76
+ );
77
+ });
78
+
79
+ it('should filter by status', async () => {
80
+ mockApiClient.getConnectors.mockResolvedValue({
81
+ ok: true,
82
+ data: { connectors: [], total: 0 },
83
+ });
84
+ const ctx = createMockContext();
85
+
86
+ await getConnectors(
87
+ {
88
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
89
+ status: 'active',
90
+ },
91
+ ctx
92
+ );
93
+
94
+ expect(mockApiClient.getConnectors).toHaveBeenCalledWith(
95
+ '123e4567-e89b-12d3-a456-426614174000',
96
+ expect.objectContaining({ status: 'active' })
97
+ );
98
+ });
99
+
100
+ it('should throw error for invalid type', async () => {
101
+ const ctx = createMockContext();
102
+
103
+ await expect(
104
+ getConnectors(
105
+ {
106
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
107
+ type: 'invalid_type',
108
+ },
109
+ ctx
110
+ )
111
+ ).rejects.toThrow(ValidationError);
112
+ });
113
+
114
+ it('should throw error for invalid status', async () => {
115
+ const ctx = createMockContext();
116
+
117
+ await expect(
118
+ getConnectors(
119
+ {
120
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
121
+ status: 'invalid_status',
122
+ },
123
+ ctx
124
+ )
125
+ ).rejects.toThrow(ValidationError);
126
+ });
127
+
128
+ it('should handle pagination with limit and offset', async () => {
129
+ mockApiClient.getConnectors.mockResolvedValue({
130
+ ok: true,
131
+ data: { connectors: [], total: 100 },
132
+ });
133
+ const ctx = createMockContext();
134
+
135
+ await getConnectors(
136
+ {
137
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
138
+ limit: 10,
139
+ offset: 20,
140
+ },
141
+ ctx
142
+ );
143
+
144
+ expect(mockApiClient.getConnectors).toHaveBeenCalledWith(
145
+ '123e4567-e89b-12d3-a456-426614174000',
146
+ expect.objectContaining({ limit: 10, offset: 20 })
147
+ );
148
+ });
149
+
150
+ it('should handle API error', async () => {
151
+ mockApiClient.getConnectors.mockResolvedValue({
152
+ ok: false,
153
+ error: 'Database error',
154
+ });
155
+ const ctx = createMockContext();
156
+
157
+ const result = await getConnectors(
158
+ { project_id: '123e4567-e89b-12d3-a456-426614174000' },
159
+ ctx
160
+ );
161
+
162
+ expect(result.result.error).toBe('Database error');
163
+ });
164
+ });
165
+
166
+ // ============================================================================
167
+ // getConnector Tests
168
+ // ============================================================================
169
+
170
+ describe('getConnector', () => {
171
+ beforeEach(() => {});
172
+
173
+ it('should throw error for missing connector_id', async () => {
174
+ const ctx = createMockContext();
175
+
176
+ await expect(getConnector({}, ctx)).rejects.toThrow(ValidationError);
177
+ });
178
+
179
+ it('should throw error for invalid connector_id UUID', async () => {
180
+ const ctx = createMockContext();
181
+
182
+ await expect(
183
+ getConnector({ connector_id: 'invalid' }, ctx)
184
+ ).rejects.toThrow(ValidationError);
185
+ });
186
+
187
+ it('should return connector details', async () => {
188
+ const mockConnector = {
189
+ id: 'conn-1',
190
+ name: 'Slack Bot',
191
+ type: 'slack',
192
+ config: { webhook_url: 'https://hooks.slack.com/...' },
193
+ events: { task_completed: true, blocker_added: true },
194
+ };
195
+ mockApiClient.getConnector.mockResolvedValue({
196
+ ok: true,
197
+ data: mockConnector,
198
+ });
199
+ const ctx = createMockContext();
200
+
201
+ const result = await getConnector(
202
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
203
+ ctx
204
+ );
205
+
206
+ expect(result.result).toMatchObject(mockConnector);
207
+ });
208
+
209
+ it('should handle API error', async () => {
210
+ mockApiClient.getConnector.mockResolvedValue({
211
+ ok: false,
212
+ error: 'Connector not found',
213
+ });
214
+ const ctx = createMockContext();
215
+
216
+ const result = await getConnector(
217
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
218
+ ctx
219
+ );
220
+
221
+ expect(result.result.error).toBe('Connector not found');
222
+ });
223
+ });
224
+
225
+ // ============================================================================
226
+ // addConnector Tests
227
+ // ============================================================================
228
+
229
+ describe('addConnector', () => {
230
+ beforeEach(() => {});
231
+
232
+ it('should throw error for missing project_id', async () => {
233
+ const ctx = createMockContext();
234
+
235
+ await expect(
236
+ addConnector({ name: 'Test', type: 'webhook' }, ctx)
237
+ ).rejects.toThrow(ValidationError);
238
+ });
239
+
240
+ it('should throw error for missing name', async () => {
241
+ const ctx = createMockContext();
242
+
243
+ await expect(
244
+ addConnector(
245
+ {
246
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
247
+ type: 'webhook',
248
+ },
249
+ ctx
250
+ )
251
+ ).rejects.toThrow(ValidationError);
252
+ });
253
+
254
+ it('should throw error for missing type', async () => {
255
+ const ctx = createMockContext();
256
+
257
+ await expect(
258
+ addConnector(
259
+ {
260
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
261
+ name: 'Test',
262
+ },
263
+ ctx
264
+ )
265
+ ).rejects.toThrow(ValidationError);
266
+ });
267
+
268
+ it('should throw error for invalid type', async () => {
269
+ const ctx = createMockContext();
270
+
271
+ await expect(
272
+ addConnector(
273
+ {
274
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
275
+ name: 'Test',
276
+ type: 'invalid_type',
277
+ },
278
+ ctx
279
+ )
280
+ ).rejects.toThrow(ValidationError);
281
+ });
282
+
283
+ it('should create connector with minimal params', async () => {
284
+ mockApiClient.addConnector.mockResolvedValue({
285
+ ok: true,
286
+ data: { connector_id: 'conn-new' },
287
+ });
288
+ const ctx = createMockContext();
289
+
290
+ const result = await addConnector(
291
+ {
292
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
293
+ name: 'My Webhook',
294
+ type: 'webhook',
295
+ },
296
+ ctx
297
+ );
298
+
299
+ expect(result.result).toMatchObject({
300
+ connector_id: 'conn-new',
301
+ });
302
+ });
303
+
304
+ it('should create connector with all params', async () => {
305
+ mockApiClient.addConnector.mockResolvedValue({
306
+ ok: true,
307
+ data: { connector_id: 'conn-new' },
308
+ });
309
+ const ctx = createMockContext();
310
+
311
+ await addConnector(
312
+ {
313
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
314
+ name: 'Slack Alerts',
315
+ type: 'slack',
316
+ description: 'Send alerts to Slack',
317
+ config: { webhook_url: 'https://hooks.slack.com/...' },
318
+ events: { task_completed: true, deployment_success: true },
319
+ },
320
+ ctx
321
+ );
322
+
323
+ expect(mockApiClient.addConnector).toHaveBeenCalledWith(
324
+ '123e4567-e89b-12d3-a456-426614174000',
325
+ expect.objectContaining({
326
+ name: 'Slack Alerts',
327
+ type: 'slack',
328
+ description: 'Send alerts to Slack',
329
+ config: { webhook_url: 'https://hooks.slack.com/...' },
330
+ events: { task_completed: true, deployment_success: true },
331
+ })
332
+ );
333
+ });
334
+
335
+ it('should accept all valid connector types', async () => {
336
+ const ctx = createMockContext();
337
+ const validTypes = ['webhook', 'slack', 'discord', 'github', 'custom'];
338
+
339
+ for (const type of validTypes) {
340
+ mockApiClient.addConnector.mockResolvedValue({
341
+ ok: true,
342
+ data: { connector_id: `conn-${type}` },
343
+ });
344
+
345
+ const result = await addConnector(
346
+ {
347
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
348
+ name: `Test ${type}`,
349
+ type,
350
+ },
351
+ ctx
352
+ );
353
+
354
+ expect(result.result.connector_id).toBe(`conn-${type}`);
355
+ }
356
+ });
357
+
358
+ it('should handle API error', async () => {
359
+ mockApiClient.addConnector.mockResolvedValue({
360
+ ok: false,
361
+ error: 'Project not found',
362
+ });
363
+ const ctx = createMockContext();
364
+
365
+ const result = await addConnector(
366
+ {
367
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
368
+ name: 'Test',
369
+ type: 'webhook',
370
+ },
371
+ ctx
372
+ );
373
+
374
+ expect(result.result.error).toBe('Project not found');
375
+ });
376
+ });
377
+
378
+ // ============================================================================
379
+ // updateConnector Tests
380
+ // ============================================================================
381
+
382
+ describe('updateConnector', () => {
383
+ beforeEach(() => {});
384
+
385
+ it('should throw error for missing connector_id', async () => {
386
+ const ctx = createMockContext();
387
+
388
+ await expect(
389
+ updateConnector({ name: 'Updated Name' }, ctx)
390
+ ).rejects.toThrow(ValidationError);
391
+ });
392
+
393
+ it('should throw error for invalid connector_id UUID', async () => {
394
+ const ctx = createMockContext();
395
+
396
+ await expect(
397
+ updateConnector({ connector_id: 'invalid', name: 'Updated' }, ctx)
398
+ ).rejects.toThrow(ValidationError);
399
+ });
400
+
401
+ it('should update connector name', async () => {
402
+ mockApiClient.updateConnector.mockResolvedValue({
403
+ ok: true,
404
+ data: { updated: true },
405
+ });
406
+ const ctx = createMockContext();
407
+
408
+ const result = await updateConnector(
409
+ {
410
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
411
+ name: 'New Name',
412
+ },
413
+ ctx
414
+ );
415
+
416
+ expect(result.result).toMatchObject({ updated: true });
417
+ expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
418
+ '123e4567-e89b-12d3-a456-426614174000',
419
+ expect.objectContaining({ name: 'New Name' })
420
+ );
421
+ });
422
+
423
+ it('should update connector config', async () => {
424
+ mockApiClient.updateConnector.mockResolvedValue({
425
+ ok: true,
426
+ data: { updated: true },
427
+ });
428
+ const ctx = createMockContext();
429
+
430
+ await updateConnector(
431
+ {
432
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
433
+ config: { webhook_url: 'https://new-url.com' },
434
+ },
435
+ ctx
436
+ );
437
+
438
+ expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
439
+ '123e4567-e89b-12d3-a456-426614174000',
440
+ expect.objectContaining({
441
+ config: { webhook_url: 'https://new-url.com' },
442
+ })
443
+ );
444
+ });
445
+
446
+ it('should update connector events', async () => {
447
+ mockApiClient.updateConnector.mockResolvedValue({
448
+ ok: true,
449
+ data: { updated: true },
450
+ });
451
+ const ctx = createMockContext();
452
+
453
+ await updateConnector(
454
+ {
455
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
456
+ events: { task_completed: false, blocker_added: true },
457
+ },
458
+ ctx
459
+ );
460
+
461
+ expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
462
+ '123e4567-e89b-12d3-a456-426614174000',
463
+ expect.objectContaining({
464
+ events: { task_completed: false, blocker_added: true },
465
+ })
466
+ );
467
+ });
468
+
469
+ it('should update connector status to active', async () => {
470
+ mockApiClient.updateConnector.mockResolvedValue({
471
+ ok: true,
472
+ data: { updated: true },
473
+ });
474
+ const ctx = createMockContext();
475
+
476
+ await updateConnector(
477
+ {
478
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
479
+ status: 'active',
480
+ },
481
+ ctx
482
+ );
483
+
484
+ expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
485
+ '123e4567-e89b-12d3-a456-426614174000',
486
+ expect.objectContaining({ status: 'active' })
487
+ );
488
+ });
489
+
490
+ it('should update connector status to disabled', async () => {
491
+ mockApiClient.updateConnector.mockResolvedValue({
492
+ ok: true,
493
+ data: { updated: true },
494
+ });
495
+ const ctx = createMockContext();
496
+
497
+ await updateConnector(
498
+ {
499
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
500
+ status: 'disabled',
501
+ },
502
+ ctx
503
+ );
504
+
505
+ expect(mockApiClient.updateConnector).toHaveBeenCalledWith(
506
+ '123e4567-e89b-12d3-a456-426614174000',
507
+ expect.objectContaining({ status: 'disabled' })
508
+ );
509
+ });
510
+
511
+ it('should throw error for invalid status', async () => {
512
+ const ctx = createMockContext();
513
+
514
+ await expect(
515
+ updateConnector(
516
+ {
517
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
518
+ status: 'invalid_status',
519
+ },
520
+ ctx
521
+ )
522
+ ).rejects.toThrow(ValidationError);
523
+ });
524
+
525
+ it('should handle API error', async () => {
526
+ mockApiClient.updateConnector.mockResolvedValue({
527
+ ok: false,
528
+ error: 'Connector not found',
529
+ });
530
+ const ctx = createMockContext();
531
+
532
+ const result = await updateConnector(
533
+ {
534
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
535
+ name: 'Updated',
536
+ },
537
+ ctx
538
+ );
539
+
540
+ expect(result.result.error).toBe('Connector not found');
541
+ });
542
+ });
543
+
544
+ // ============================================================================
545
+ // deleteConnector Tests
546
+ // ============================================================================
547
+
548
+ describe('deleteConnector', () => {
549
+ beforeEach(() => {});
550
+
551
+ it('should throw error for missing connector_id', async () => {
552
+ const ctx = createMockContext();
553
+
554
+ await expect(deleteConnector({}, ctx)).rejects.toThrow(ValidationError);
555
+ });
556
+
557
+ it('should throw error for invalid connector_id UUID', async () => {
558
+ const ctx = createMockContext();
559
+
560
+ await expect(
561
+ deleteConnector({ connector_id: 'invalid' }, ctx)
562
+ ).rejects.toThrow(ValidationError);
563
+ });
564
+
565
+ it('should delete connector successfully', async () => {
566
+ mockApiClient.deleteConnector.mockResolvedValue({
567
+ ok: true,
568
+ data: { deleted: true },
569
+ });
570
+ const ctx = createMockContext();
571
+
572
+ const result = await deleteConnector(
573
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
574
+ ctx
575
+ );
576
+
577
+ expect(result.result).toMatchObject({ deleted: true });
578
+ });
579
+
580
+ it('should handle API error', async () => {
581
+ mockApiClient.deleteConnector.mockResolvedValue({
582
+ ok: false,
583
+ error: 'Connector not found',
584
+ });
585
+ const ctx = createMockContext();
586
+
587
+ const result = await deleteConnector(
588
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
589
+ ctx
590
+ );
591
+
592
+ expect(result.result.error).toBe('Connector not found');
593
+ });
594
+ });
595
+
596
+ // ============================================================================
597
+ // testConnector Tests
598
+ // ============================================================================
599
+
600
+ describe('testConnector', () => {
601
+ beforeEach(() => {});
602
+
603
+ it('should throw error for missing connector_id', async () => {
604
+ const ctx = createMockContext();
605
+
606
+ await expect(testConnector({}, ctx)).rejects.toThrow(ValidationError);
607
+ });
608
+
609
+ it('should throw error for invalid connector_id UUID', async () => {
610
+ const ctx = createMockContext();
611
+
612
+ await expect(
613
+ testConnector({ connector_id: 'invalid' }, ctx)
614
+ ).rejects.toThrow(ValidationError);
615
+ });
616
+
617
+ it('should test connector successfully', async () => {
618
+ mockApiClient.testConnector.mockResolvedValue({
619
+ ok: true,
620
+ data: { success: true, message: 'Test event sent' },
621
+ });
622
+ const ctx = createMockContext();
623
+
624
+ const result = await testConnector(
625
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
626
+ ctx
627
+ );
628
+
629
+ expect(result.result).toMatchObject({
630
+ success: true,
631
+ message: 'Test event sent',
632
+ });
633
+ });
634
+
635
+ it('should handle test failure', async () => {
636
+ mockApiClient.testConnector.mockResolvedValue({
637
+ ok: true,
638
+ data: { success: false, error: 'Webhook returned 404' },
639
+ });
640
+ const ctx = createMockContext();
641
+
642
+ const result = await testConnector(
643
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
644
+ ctx
645
+ );
646
+
647
+ expect(result.result).toMatchObject({
648
+ success: false,
649
+ error: 'Webhook returned 404',
650
+ });
651
+ });
652
+
653
+ it('should handle API error', async () => {
654
+ mockApiClient.testConnector.mockResolvedValue({
655
+ ok: false,
656
+ error: 'Connector not found',
657
+ });
658
+ const ctx = createMockContext();
659
+
660
+ const result = await testConnector(
661
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
662
+ ctx
663
+ );
664
+
665
+ expect(result.result.error).toBe('Connector not found');
666
+ });
667
+ });
668
+
669
+ // ============================================================================
670
+ // getConnectorEvents Tests
671
+ // ============================================================================
672
+
673
+ describe('getConnectorEvents', () => {
674
+ beforeEach(() => {});
675
+
676
+ it('should throw error when neither connector_id nor project_id provided', async () => {
677
+ const ctx = createMockContext();
678
+
679
+ const result = await getConnectorEvents({}, ctx);
680
+
681
+ expect(result.result.error).toBe(
682
+ 'Either connector_id or project_id is required'
683
+ );
684
+ });
685
+
686
+ it('should throw error for invalid connector_id UUID', async () => {
687
+ const ctx = createMockContext();
688
+
689
+ await expect(
690
+ getConnectorEvents({ connector_id: 'invalid' }, ctx)
691
+ ).rejects.toThrow(ValidationError);
692
+ });
693
+
694
+ it('should throw error for invalid project_id UUID', async () => {
695
+ const ctx = createMockContext();
696
+
697
+ await expect(
698
+ getConnectorEvents({ project_id: 'invalid' }, ctx)
699
+ ).rejects.toThrow(ValidationError);
700
+ });
701
+
702
+ it('should get events by connector_id', async () => {
703
+ const mockEvents = [
704
+ { id: 'evt-1', event_type: 'task_completed', status: 'sent' },
705
+ { id: 'evt-2', event_type: 'blocker_added', status: 'failed' },
706
+ ];
707
+ mockApiClient.getConnectorEvents.mockResolvedValue({
708
+ ok: true,
709
+ data: { events: mockEvents, total: 2 },
710
+ });
711
+ const ctx = createMockContext();
712
+
713
+ const result = await getConnectorEvents(
714
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
715
+ ctx
716
+ );
717
+
718
+ expect(result.result).toMatchObject({
719
+ events: mockEvents,
720
+ total: 2,
721
+ });
722
+ });
723
+
724
+ it('should get events by project_id', async () => {
725
+ mockApiClient.getConnectorEvents.mockResolvedValue({
726
+ ok: true,
727
+ data: { events: [], total: 0 },
728
+ });
729
+ const ctx = createMockContext();
730
+
731
+ await getConnectorEvents(
732
+ { project_id: '123e4567-e89b-12d3-a456-426614174000' },
733
+ ctx
734
+ );
735
+
736
+ expect(mockApiClient.getConnectorEvents).toHaveBeenCalledWith(
737
+ expect.objectContaining({
738
+ project_id: '123e4567-e89b-12d3-a456-426614174000',
739
+ })
740
+ );
741
+ });
742
+
743
+ it('should filter by status', async () => {
744
+ mockApiClient.getConnectorEvents.mockResolvedValue({
745
+ ok: true,
746
+ data: { events: [], total: 0 },
747
+ });
748
+ const ctx = createMockContext();
749
+
750
+ await getConnectorEvents(
751
+ {
752
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
753
+ status: 'failed',
754
+ },
755
+ ctx
756
+ );
757
+
758
+ expect(mockApiClient.getConnectorEvents).toHaveBeenCalledWith(
759
+ expect.objectContaining({ status: 'failed' })
760
+ );
761
+ });
762
+
763
+ it('should accept all valid event statuses', async () => {
764
+ const ctx = createMockContext();
765
+ const validStatuses = ['pending', 'sent', 'failed', 'retrying'];
766
+
767
+ for (const status of validStatuses) {
768
+ mockApiClient.getConnectorEvents.mockResolvedValue({
769
+ ok: true,
770
+ data: { events: [], total: 0 },
771
+ });
772
+
773
+ const result = await getConnectorEvents(
774
+ {
775
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
776
+ status,
777
+ },
778
+ ctx
779
+ );
780
+
781
+ expect(result.result.events).toBeDefined();
782
+ }
783
+ });
784
+
785
+ it('should throw error for invalid status', async () => {
786
+ const ctx = createMockContext();
787
+
788
+ await expect(
789
+ getConnectorEvents(
790
+ {
791
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
792
+ status: 'invalid_status',
793
+ },
794
+ ctx
795
+ )
796
+ ).rejects.toThrow(ValidationError);
797
+ });
798
+
799
+ it('should handle pagination', async () => {
800
+ mockApiClient.getConnectorEvents.mockResolvedValue({
801
+ ok: true,
802
+ data: { events: [], total: 100 },
803
+ });
804
+ const ctx = createMockContext();
805
+
806
+ await getConnectorEvents(
807
+ {
808
+ connector_id: '123e4567-e89b-12d3-a456-426614174000',
809
+ limit: 25,
810
+ offset: 50,
811
+ },
812
+ ctx
813
+ );
814
+
815
+ expect(mockApiClient.getConnectorEvents).toHaveBeenCalledWith(
816
+ expect.objectContaining({ limit: 25, offset: 50 })
817
+ );
818
+ });
819
+
820
+ it('should handle API error', async () => {
821
+ mockApiClient.getConnectorEvents.mockResolvedValue({
822
+ ok: false,
823
+ error: 'Database error',
824
+ });
825
+ const ctx = createMockContext();
826
+
827
+ const result = await getConnectorEvents(
828
+ { connector_id: '123e4567-e89b-12d3-a456-426614174000' },
829
+ ctx
830
+ );
831
+
832
+ expect(result.result.error).toBe('Database error');
833
+ });
834
+ });