@zapier/zapier-sdk 0.13.6 → 0.13.7

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 (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +7 -2
  5. package/src/api/auth.ts +0 -28
  6. package/src/api/client.ts +0 -491
  7. package/src/api/debug.test.ts +0 -76
  8. package/src/api/debug.ts +0 -154
  9. package/src/api/index.ts +0 -90
  10. package/src/api/polling.test.ts +0 -405
  11. package/src/api/polling.ts +0 -253
  12. package/src/api/schemas.ts +0 -465
  13. package/src/api/types.ts +0 -152
  14. package/src/auth.ts +0 -72
  15. package/src/constants.ts +0 -16
  16. package/src/index.ts +0 -111
  17. package/src/plugins/api/index.ts +0 -43
  18. package/src/plugins/apps/index.ts +0 -203
  19. package/src/plugins/apps/schemas.ts +0 -64
  20. package/src/plugins/eventEmission/builders.ts +0 -115
  21. package/src/plugins/eventEmission/index.test.ts +0 -169
  22. package/src/plugins/eventEmission/index.ts +0 -294
  23. package/src/plugins/eventEmission/transport.test.ts +0 -214
  24. package/src/plugins/eventEmission/transport.ts +0 -135
  25. package/src/plugins/eventEmission/types.ts +0 -58
  26. package/src/plugins/eventEmission/utils.ts +0 -121
  27. package/src/plugins/fetch/index.ts +0 -83
  28. package/src/plugins/fetch/schemas.ts +0 -37
  29. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  30. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  31. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  32. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  33. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  34. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  35. package/src/plugins/getAction/index.test.ts +0 -239
  36. package/src/plugins/getAction/index.ts +0 -75
  37. package/src/plugins/getAction/schemas.ts +0 -41
  38. package/src/plugins/getApp/index.test.ts +0 -181
  39. package/src/plugins/getApp/index.ts +0 -60
  40. package/src/plugins/getApp/schemas.ts +0 -33
  41. package/src/plugins/getAuthentication/index.test.ts +0 -294
  42. package/src/plugins/getAuthentication/index.ts +0 -95
  43. package/src/plugins/getAuthentication/schemas.ts +0 -38
  44. package/src/plugins/getProfile/index.ts +0 -60
  45. package/src/plugins/getProfile/schemas.ts +0 -24
  46. package/src/plugins/listActions/index.test.ts +0 -526
  47. package/src/plugins/listActions/index.ts +0 -132
  48. package/src/plugins/listActions/schemas.ts +0 -55
  49. package/src/plugins/listApps/index.test.ts +0 -378
  50. package/src/plugins/listApps/index.ts +0 -159
  51. package/src/plugins/listApps/schemas.ts +0 -41
  52. package/src/plugins/listAuthentications/index.test.ts +0 -739
  53. package/src/plugins/listAuthentications/index.ts +0 -152
  54. package/src/plugins/listAuthentications/schemas.ts +0 -77
  55. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  56. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  57. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  58. package/src/plugins/listInputFields/index.test.ts +0 -439
  59. package/src/plugins/listInputFields/index.ts +0 -294
  60. package/src/plugins/listInputFields/schemas.ts +0 -68
  61. package/src/plugins/manifest/index.test.ts +0 -776
  62. package/src/plugins/manifest/index.ts +0 -461
  63. package/src/plugins/manifest/schemas.ts +0 -60
  64. package/src/plugins/registry/index.ts +0 -160
  65. package/src/plugins/request/index.test.ts +0 -333
  66. package/src/plugins/request/index.ts +0 -105
  67. package/src/plugins/request/schemas.ts +0 -69
  68. package/src/plugins/runAction/index.test.ts +0 -388
  69. package/src/plugins/runAction/index.ts +0 -215
  70. package/src/plugins/runAction/schemas.ts +0 -60
  71. package/src/resolvers/actionKey.ts +0 -37
  72. package/src/resolvers/actionType.ts +0 -34
  73. package/src/resolvers/appKey.ts +0 -7
  74. package/src/resolvers/authenticationId.ts +0 -54
  75. package/src/resolvers/index.ts +0 -11
  76. package/src/resolvers/inputFieldKey.ts +0 -70
  77. package/src/resolvers/inputs.ts +0 -69
  78. package/src/schemas/Action.ts +0 -52
  79. package/src/schemas/App.ts +0 -45
  80. package/src/schemas/Auth.ts +0 -59
  81. package/src/schemas/Field.ts +0 -169
  82. package/src/schemas/Run.ts +0 -40
  83. package/src/schemas/UserProfile.ts +0 -60
  84. package/src/sdk.test.ts +0 -212
  85. package/src/sdk.ts +0 -178
  86. package/src/types/domain.test.ts +0 -50
  87. package/src/types/domain.ts +0 -66
  88. package/src/types/errors.ts +0 -278
  89. package/src/types/events.ts +0 -43
  90. package/src/types/functions.ts +0 -28
  91. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  92. package/src/types/plugin.ts +0 -125
  93. package/src/types/properties.ts +0 -80
  94. package/src/types/sdk.ts +0 -111
  95. package/src/types/telemetry-events.ts +0 -85
  96. package/src/utils/array-utils.test.ts +0 -131
  97. package/src/utils/array-utils.ts +0 -41
  98. package/src/utils/domain-utils.test.ts +0 -433
  99. package/src/utils/domain-utils.ts +0 -267
  100. package/src/utils/file-utils.test.ts +0 -73
  101. package/src/utils/file-utils.ts +0 -94
  102. package/src/utils/function-utils.test.ts +0 -141
  103. package/src/utils/function-utils.ts +0 -245
  104. package/src/utils/pagination-utils.test.ts +0 -620
  105. package/src/utils/pagination-utils.ts +0 -242
  106. package/src/utils/schema-utils.ts +0 -207
  107. package/src/utils/string-utils.test.ts +0 -45
  108. package/src/utils/string-utils.ts +0 -54
  109. package/src/utils/validation.test.ts +0 -51
  110. package/src/utils/validation.ts +0 -44
  111. package/tsconfig.build.json +0 -18
  112. package/tsconfig.json +0 -20
  113. package/tsconfig.tsbuildinfo +0 -1
  114. package/tsup.config.ts +0 -23
@@ -1,653 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { ZapierValidationError, ZapierApiError } from "../../types/errors";
3
- import { listInputFieldChoicesPlugin } from "./index";
4
- import { createSdk } from "../../sdk";
5
- import type { ApiClient } from "../../api";
6
- import type { ListInputFieldChoicesOptions } from "./schemas";
7
- import type { NeedChoicesResponse, NeedChoices } from "../../api/types";
8
- import { GetActionSchema } from "../getAction/schemas";
9
-
10
- const mockChoices: NeedChoices[] = [
11
- {
12
- key: "general",
13
- label: "General Channel",
14
- sample: "#general",
15
- value: "general",
16
- },
17
- {
18
- key: "random",
19
- label: "Random Channel",
20
- sample: "#random",
21
- value: "random",
22
- },
23
- {
24
- key: "dev",
25
- label: "Development Channel",
26
- sample: "#dev",
27
- value: "dev",
28
- },
29
- ];
30
-
31
- const mockChoicesResponse: NeedChoicesResponse = {
32
- success: true,
33
- choices: mockChoices,
34
- };
35
-
36
- const mockPaginatedChoicesResponse: NeedChoicesResponse = {
37
- success: true,
38
- choices: mockChoices.slice(0, 2),
39
- next_page: 1,
40
- };
41
-
42
- const mockExternalChoicesResponse: NeedChoicesResponse = {
43
- success: true,
44
- choices: mockChoices,
45
- meta: { page: "0" },
46
- links: {
47
- next: "https://api.zapier.com/api/v4/implementations/choices/?page=1",
48
- prev: null,
49
- },
50
- };
51
-
52
- describe("listInputFieldChoices plugin", () => {
53
- let mockApiClient: ApiClient;
54
- let mockGetAction: any;
55
-
56
- beforeEach(() => {
57
- vi.clearAllMocks();
58
- mockApiClient = {
59
- post: vi.fn().mockResolvedValue(mockChoicesResponse),
60
- } as Partial<ApiClient> as ApiClient;
61
-
62
- mockGetAction = vi.fn().mockResolvedValue({
63
- data: { id: "core:123", key: "send_message", action_type: "read" },
64
- });
65
- });
66
-
67
- function createTestSdk() {
68
- // Create a mock getAction plugin
69
- const mockGetActionPlugin = () => ({
70
- getAction: mockGetAction,
71
- context: {
72
- meta: {
73
- getAction: {
74
- inputSchema: GetActionSchema,
75
- },
76
- },
77
- },
78
- });
79
-
80
- // Build SDK with proper plugin composition
81
- return createSdk({}, {}, { api: mockApiClient, meta: {} })
82
- .addPlugin(mockGetActionPlugin)
83
- .addPlugin(listInputFieldChoicesPlugin as any);
84
- }
85
-
86
- describe("schema validation", () => {
87
- it("should throw validation error for missing inputFieldKey", async () => {
88
- const sdk = createTestSdk();
89
-
90
- try {
91
- await sdk.listInputFieldChoices({
92
- appKey: "slack",
93
- actionType: "read",
94
- actionKey: "send_message",
95
- // Missing inputFieldKey
96
- } as ListInputFieldChoicesOptions);
97
- expect.fail("Expected ZapierValidationError to be thrown");
98
- } catch (error) {
99
- expect(error).toBeInstanceOf(ZapierValidationError);
100
- }
101
- });
102
-
103
- it("should throw validation error for missing actionKey", async () => {
104
- const sdk = createTestSdk();
105
-
106
- try {
107
- await sdk.listInputFieldChoices({
108
- appKey: "slack",
109
- actionType: "read",
110
- inputFieldKey: "channel",
111
- // Missing actionKey
112
- } as ListInputFieldChoicesOptions);
113
- expect.fail("Expected ZapierValidationError to be thrown");
114
- } catch (error) {
115
- expect(error).toBeInstanceOf(ZapierValidationError);
116
- }
117
- });
118
-
119
- it("should pass validation with action method", async () => {
120
- const sdk = createTestSdk();
121
- const result = await sdk.listInputFieldChoices({
122
- appKey: "slack",
123
- actionType: "read",
124
- actionKey: "send_message",
125
- inputFieldKey: "channel",
126
- });
127
-
128
- expect(result.data).toBeDefined();
129
- });
130
-
131
- it("should pass validation with optional fields", async () => {
132
- const sdk = createTestSdk();
133
- const result = await sdk.listInputFieldChoices({
134
- appKey: "slack",
135
- actionType: "read",
136
- actionKey: "send_message",
137
- inputFieldKey: "channel",
138
- authenticationId: 456,
139
- inputs: { workspace: "my-team" },
140
- page: 0,
141
- });
142
-
143
- expect(result.data).toBeDefined();
144
- });
145
-
146
- it("should throw validation error for empty string actionKey", async () => {
147
- const sdk = createTestSdk();
148
-
149
- try {
150
- await sdk.listInputFieldChoices({
151
- appKey: "slack",
152
- actionType: "read",
153
- actionKey: "", // Empty string
154
- inputFieldKey: "channel",
155
- } as ListInputFieldChoicesOptions);
156
- expect.fail("Expected ZapierValidationError to be thrown");
157
- } catch (error) {
158
- expect(error).toBeInstanceOf(ZapierValidationError);
159
- }
160
- });
161
-
162
- it("should throw validation error for empty string inputFieldKey", async () => {
163
- const sdk = createTestSdk();
164
-
165
- try {
166
- await sdk.listInputFieldChoices({
167
- appKey: "slack",
168
- actionType: "read",
169
- actionKey: "send_message",
170
- inputFieldKey: "", // Empty string
171
- } as ListInputFieldChoicesOptions);
172
- expect.fail("Expected ZapierValidationError to be thrown");
173
- } catch (error) {
174
- expect(error).toBeInstanceOf(ZapierValidationError);
175
- }
176
- });
177
- });
178
-
179
- describe("API integration - action method", () => {
180
- it("should call the correct API endpoint with action method", async () => {
181
- const sdk = createTestSdk();
182
- await sdk.listInputFieldChoices({
183
- appKey: "slack",
184
- actionType: "read",
185
- actionKey: "send_message",
186
- inputFieldKey: "channel",
187
- });
188
-
189
- expect(mockGetAction).toHaveBeenCalledWith({
190
- appKey: "slack",
191
- actionType: "read",
192
- actionKey: "send_message",
193
- });
194
- expect(mockApiClient.post).toHaveBeenCalledWith(
195
- "/api/v4/implementations/choices/",
196
- {
197
- action_id: "core:123",
198
- input_field_id: "channel",
199
- page: 0,
200
- params: {},
201
- },
202
- );
203
- });
204
-
205
- it("should include authentication_id when provided", async () => {
206
- const sdk = createTestSdk();
207
- await sdk.listInputFieldChoices({
208
- appKey: "slack",
209
- actionType: "read",
210
- actionKey: "send_message",
211
- inputFieldKey: "channel",
212
- authenticationId: 456,
213
- });
214
-
215
- expect(mockApiClient.post).toHaveBeenCalledWith(
216
- "/api/v4/implementations/choices/",
217
- {
218
- action_id: "core:123",
219
- input_field_id: "channel",
220
- authentication_id: 456,
221
- page: 0,
222
- params: {},
223
- },
224
- );
225
- });
226
-
227
- it("should exclude authentication_id when null", async () => {
228
- const sdk = createTestSdk();
229
- await sdk.listInputFieldChoices({
230
- appKey: "slack",
231
- actionType: "read",
232
- actionKey: "send_message",
233
- inputFieldKey: "channel",
234
- authenticationId: null,
235
- });
236
-
237
- expect(mockApiClient.post).toHaveBeenCalledWith(
238
- "/api/v4/implementations/choices/",
239
- {
240
- action_id: "core:123",
241
- input_field_id: "channel",
242
- page: 0,
243
- params: {},
244
- // No authentication_id
245
- },
246
- );
247
- });
248
-
249
- it("should include inputs when provided", async () => {
250
- const sdk = createTestSdk();
251
- const inputs = { workspace: "my-team", board: "project" };
252
-
253
- await sdk.listInputFieldChoices({
254
- appKey: "slack",
255
- actionType: "read",
256
- actionKey: "send_message",
257
- inputFieldKey: "channel",
258
- inputs,
259
- });
260
-
261
- expect(mockApiClient.post).toHaveBeenCalledWith(
262
- "/api/v4/implementations/choices/",
263
- {
264
- action_id: "core:123",
265
- input_field_id: "channel",
266
- page: 0,
267
- params: inputs,
268
- },
269
- );
270
- });
271
-
272
- it("should include page when provided", async () => {
273
- const sdk = createTestSdk();
274
-
275
- await sdk.listInputFieldChoices({
276
- appKey: "slack",
277
- actionType: "read",
278
- actionKey: "send_message",
279
- inputFieldKey: "channel",
280
- page: 2,
281
- });
282
-
283
- expect(mockApiClient.post).toHaveBeenCalledWith(
284
- "/api/v4/implementations/choices/",
285
- {
286
- action_id: "core:123",
287
- input_field_id: "channel",
288
- page: 2,
289
- params: {},
290
- },
291
- );
292
- });
293
- });
294
-
295
- describe("data transformation", () => {
296
- it("should transform choices to input field choice items correctly", async () => {
297
- const sdk = createTestSdk();
298
- const result = await sdk.listInputFieldChoices({
299
- appKey: "slack",
300
- actionType: "read",
301
- actionKey: "send_message",
302
- inputFieldKey: "channel",
303
- });
304
-
305
- expect(result.data).toHaveLength(3);
306
-
307
- // Check first choice transformation
308
- expect(result.data[0]).toEqual({
309
- key: "general",
310
- label: "General Channel",
311
- sample: "#general",
312
- value: "general",
313
- });
314
-
315
- // Check second choice transformation
316
- expect(result.data[1]).toEqual({
317
- key: "random",
318
- label: "Random Channel",
319
- sample: "#random",
320
- value: "random",
321
- });
322
- });
323
-
324
- it("should handle choices with missing fields gracefully", async () => {
325
- const sparseChoices: NeedChoices[] = [
326
- { key: "item1", label: "Item 1" },
327
- { value: "item2", sample: "item2" },
328
- { label: "Item 3" },
329
- ];
330
-
331
- mockApiClient.post = vi.fn().mockResolvedValue({
332
- success: true,
333
- choices: sparseChoices,
334
- });
335
-
336
- const sdk = createTestSdk();
337
- const result = await sdk.listInputFieldChoices({
338
- appKey: "slack",
339
- actionType: "read",
340
- actionKey: "send_message",
341
- inputFieldKey: "item",
342
- });
343
-
344
- expect(result.data).toHaveLength(3);
345
- expect(result.data[0]).toEqual({
346
- key: "item1",
347
- label: "Item 1",
348
- sample: undefined,
349
- value: undefined,
350
- });
351
- expect(result.data[1]).toEqual({
352
- key: undefined,
353
- label: undefined,
354
- sample: "item2",
355
- value: "item2",
356
- });
357
- });
358
- });
359
-
360
- describe("pagination handling", () => {
361
- it("should handle next_page pagination correctly in the plugin", async () => {
362
- mockApiClient.post = vi
363
- .fn()
364
- .mockResolvedValue(mockPaginatedChoicesResponse);
365
-
366
- const sdk = createTestSdk();
367
-
368
- // Test that the plugin correctly sets nextCursor when next_page is present
369
- const listChoicesResult = sdk.listInputFieldChoices({
370
- appKey: "slack",
371
- actionType: "read",
372
- actionKey: "send_message",
373
- inputFieldKey: "channel",
374
- pageSize: 2, // Set a small page size to test pagination behavior
375
- });
376
-
377
- const pages = [];
378
- for await (const page of listChoicesResult) {
379
- pages.push(page);
380
- break; // Just get first page for testing
381
- }
382
-
383
- expect(pages).toHaveLength(1);
384
- expect(pages[0].nextCursor).toBe("1");
385
- });
386
-
387
- it("should handle external action link-based pagination correctly in the plugin", async () => {
388
- mockApiClient.post = vi
389
- .fn()
390
- .mockResolvedValue(mockExternalChoicesResponse);
391
-
392
- const sdk = createTestSdk();
393
-
394
- // Test that the plugin correctly extracts cursor from links.next
395
- const listChoicesResult = sdk.listInputFieldChoices({
396
- appKey: "slack",
397
- actionType: "read",
398
- actionKey: "send_message",
399
- inputFieldKey: "option",
400
- pageSize: 3, // Set a small page size to test pagination behavior
401
- });
402
-
403
- const pages = [];
404
- for await (const page of listChoicesResult) {
405
- pages.push(page);
406
- break; // Just get first page for testing
407
- }
408
-
409
- expect(pages).toHaveLength(1);
410
- expect(pages[0].nextCursor).toBe("1"); // Extracted from links.next URL
411
- });
412
-
413
- it("should handle no pagination", async () => {
414
- const sdk = createTestSdk();
415
- const listChoicesResult = sdk.listInputFieldChoices({
416
- appKey: "slack",
417
- actionType: "read",
418
- actionKey: "send_message",
419
- inputFieldKey: "channel",
420
- });
421
-
422
- const pages = [];
423
- for await (const page of listChoicesResult) {
424
- pages.push(page);
425
- break; // Just get first page for testing
426
- }
427
-
428
- expect(pages).toHaveLength(1);
429
- expect(pages[0].nextCursor).toBeUndefined();
430
- });
431
-
432
- it("should support async iteration over individual items", async () => {
433
- const sdk = createTestSdk();
434
- const listChoicesResult = sdk.listInputFieldChoices({
435
- appKey: "slack",
436
- actionType: "read",
437
- actionKey: "send_message",
438
- inputFieldKey: "channel",
439
- });
440
-
441
- const items = [];
442
- for await (const item of listChoicesResult.items()) {
443
- items.push(item);
444
- }
445
-
446
- expect(items).toHaveLength(3);
447
- expect(items[0].key).toBe("general");
448
- });
449
-
450
- it("should handle malformed links.next URL gracefully", async () => {
451
- const malformedExternalResponse: NeedChoicesResponse = {
452
- success: true,
453
- choices: mockChoices,
454
- links: {
455
- next: "invalid-url-format", // Malformed URL
456
- prev: null,
457
- },
458
- };
459
-
460
- mockApiClient.post = vi.fn().mockResolvedValue(malformedExternalResponse);
461
-
462
- const sdk = createTestSdk();
463
- const listChoicesResult = sdk.listInputFieldChoices({
464
- appKey: "slack",
465
- actionType: "read",
466
- actionKey: "send_message",
467
- inputFieldKey: "option",
468
- });
469
-
470
- const pages = [];
471
- for await (const page of listChoicesResult) {
472
- pages.push(page);
473
- break;
474
- }
475
-
476
- expect(pages).toHaveLength(1);
477
- expect(pages[0].nextCursor).toBeUndefined(); // Should handle gracefully
478
- });
479
-
480
- it("should handle links.next URL without page parameter", async () => {
481
- const noPageResponse: NeedChoicesResponse = {
482
- success: true,
483
- choices: mockChoices,
484
- links: {
485
- next: "https://api.zapier.com/api/v4/implementations/choices/", // No page param
486
- prev: null,
487
- },
488
- };
489
-
490
- mockApiClient.post = vi.fn().mockResolvedValue(noPageResponse);
491
-
492
- const sdk = createTestSdk();
493
- const listChoicesResult = sdk.listInputFieldChoices({
494
- appKey: "slack",
495
- actionType: "read",
496
- actionKey: "send_message",
497
- inputFieldKey: "option",
498
- });
499
-
500
- const pages = [];
501
- for await (const page of listChoicesResult) {
502
- pages.push(page);
503
- break;
504
- }
505
-
506
- expect(pages).toHaveLength(1);
507
- expect(pages[0].nextCursor).toBeUndefined();
508
- });
509
- });
510
-
511
- describe("error handling", () => {
512
- it("should throw ZapierApiError when API response indicates failure", async () => {
513
- mockApiClient.post = vi.fn().mockResolvedValue({
514
- success: false,
515
- errors: ["Invalid field", "Missing authentication"],
516
- });
517
-
518
- const sdk = createTestSdk();
519
- await expect(
520
- sdk.listInputFieldChoices({
521
- appKey: "slack",
522
- actionType: "read",
523
- actionKey: "send_message",
524
- inputFieldKey: "invalid_field",
525
- }),
526
- ).rejects.toThrow(ZapierApiError);
527
-
528
- await expect(
529
- sdk.listInputFieldChoices({
530
- appKey: "slack",
531
- actionType: "read",
532
- actionKey: "send_message",
533
- inputFieldKey: "invalid_field",
534
- }),
535
- ).rejects.toThrow(
536
- "Failed to get input field choices: Invalid field, Missing authentication",
537
- );
538
- });
539
-
540
- it("should handle API errors gracefully", async () => {
541
- mockApiClient.post = vi
542
- .fn()
543
- .mockRejectedValue(new Error("Network error"));
544
-
545
- const sdk = createTestSdk();
546
- await expect(
547
- sdk.listInputFieldChoices({
548
- appKey: "slack",
549
- actionType: "read",
550
- actionKey: "send_message",
551
- inputFieldKey: "channel",
552
- }),
553
- ).rejects.toThrow("Network error");
554
- });
555
-
556
- it("should handle empty choices array response", async () => {
557
- mockApiClient.post = vi.fn().mockResolvedValue({
558
- success: true,
559
- choices: [], // Empty choices
560
- });
561
-
562
- const sdk = createTestSdk();
563
- const result = await sdk.listInputFieldChoices({
564
- appKey: "slack",
565
- actionType: "read",
566
- actionKey: "send_message",
567
- inputFieldKey: "channel",
568
- });
569
-
570
- expect(result.data).toEqual([]);
571
- });
572
-
573
- it("should handle missing choices field in response", async () => {
574
- mockApiClient.post = vi.fn().mockResolvedValue({
575
- success: true,
576
- // Missing choices field
577
- });
578
-
579
- const sdk = createTestSdk();
580
- const result = await sdk.listInputFieldChoices({
581
- appKey: "slack",
582
- actionType: "read",
583
- actionKey: "send_message",
584
- inputFieldKey: "channel",
585
- });
586
-
587
- expect(result.data).toEqual([]);
588
- });
589
-
590
- it("should treat missing success field as failure", async () => {
591
- mockApiClient.post = vi.fn().mockResolvedValue({
592
- // Missing success field (undefined)
593
- choices: mockChoices,
594
- });
595
-
596
- const sdk = createTestSdk();
597
- await expect(
598
- sdk.listInputFieldChoices({
599
- appKey: "slack",
600
- actionType: "read",
601
- actionKey: "send_message",
602
- inputFieldKey: "channel",
603
- }),
604
- ).rejects.toThrow("Failed to get input field choices: Unknown error");
605
- });
606
-
607
- it("should handle API response with errors but no error messages", async () => {
608
- mockApiClient.post = vi.fn().mockResolvedValue({
609
- success: false,
610
- // Missing errors field
611
- });
612
-
613
- const sdk = createTestSdk();
614
- await expect(
615
- sdk.listInputFieldChoices({
616
- appKey: "slack",
617
- actionType: "read",
618
- actionKey: "send_message",
619
- inputFieldKey: "channel",
620
- }),
621
- ).rejects.toThrow("Failed to get input field choices: Unknown error");
622
- });
623
-
624
- it("should handle API response with empty errors array", async () => {
625
- mockApiClient.post = vi.fn().mockResolvedValue({
626
- success: false,
627
- errors: [], // Empty errors array
628
- });
629
-
630
- const sdk = createTestSdk();
631
- await expect(
632
- sdk.listInputFieldChoices({
633
- appKey: "slack",
634
- actionType: "read",
635
- actionKey: "send_message",
636
- inputFieldKey: "channel",
637
- }),
638
- ).rejects.toThrow("Failed to get input field choices: Unknown error");
639
- });
640
- });
641
-
642
- describe("context and metadata", () => {
643
- it("should provide context with meta information", () => {
644
- const sdk = createTestSdk();
645
- const context = sdk.getContext();
646
-
647
- expect((context.meta as any).listInputFieldChoices).toBeDefined();
648
- expect(
649
- (context.meta as any).listInputFieldChoices.inputSchema,
650
- ).toBeDefined();
651
- });
652
- });
653
- });