@zapier/zapier-sdk 0.33.0 → 0.33.2
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.
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs +2 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +1 -0
- package/dist/types/sdk.d.ts +8 -0
- package/dist/types/sdk.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/api/auth.test.d.ts +0 -2
- package/dist/api/auth.test.d.ts.map +0 -1
- package/dist/api/auth.test.js +0 -220
- package/dist/api/client.test.d.ts +0 -2
- package/dist/api/client.test.d.ts.map +0 -1
- package/dist/api/client.test.js +0 -611
- package/dist/api/debug.test.d.ts +0 -2
- package/dist/api/debug.test.d.ts.map +0 -1
- package/dist/api/debug.test.js +0 -59
- package/dist/api/polling.test.d.ts +0 -2
- package/dist/api/polling.test.d.ts.map +0 -1
- package/dist/api/polling.test.js +0 -360
- package/dist/auth.test.d.ts +0 -2
- package/dist/auth.test.d.ts.map +0 -1
- package/dist/auth.test.js +0 -480
- package/dist/plugins/eventEmission/builders.test.d.ts +0 -2
- package/dist/plugins/eventEmission/builders.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/builders.test.js +0 -138
- package/dist/plugins/eventEmission/index.test.d.ts +0 -5
- package/dist/plugins/eventEmission/index.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/index.test.js +0 -712
- package/dist/plugins/eventEmission/transport.test.d.ts +0 -5
- package/dist/plugins/eventEmission/transport.test.d.ts.map +0 -1
- package/dist/plugins/eventEmission/transport.test.js +0 -164
- package/dist/plugins/fetch/index.test.d.ts +0 -2
- package/dist/plugins/fetch/index.test.d.ts.map +0 -1
- package/dist/plugins/fetch/index.test.js +0 -428
- package/dist/plugins/findFirstConnection/index.test.d.ts +0 -2
- package/dist/plugins/findFirstConnection/index.test.d.ts.map +0 -1
- package/dist/plugins/findFirstConnection/index.test.js +0 -177
- package/dist/plugins/findUniqueConnection/index.test.d.ts +0 -2
- package/dist/plugins/findUniqueConnection/index.test.d.ts.map +0 -1
- package/dist/plugins/findUniqueConnection/index.test.js +0 -159
- package/dist/plugins/getAction/index.test.d.ts +0 -2
- package/dist/plugins/getAction/index.test.d.ts.map +0 -1
- package/dist/plugins/getAction/index.test.js +0 -211
- package/dist/plugins/getApp/index.test.d.ts +0 -2
- package/dist/plugins/getApp/index.test.d.ts.map +0 -1
- package/dist/plugins/getApp/index.test.js +0 -157
- package/dist/plugins/getConnection/index.test.d.ts +0 -2
- package/dist/plugins/getConnection/index.test.d.ts.map +0 -1
- package/dist/plugins/getConnection/index.test.js +0 -124
- package/dist/plugins/getInputFieldsSchema/index.test.d.ts +0 -2
- package/dist/plugins/getInputFieldsSchema/index.test.d.ts.map +0 -1
- package/dist/plugins/getInputFieldsSchema/index.test.js +0 -291
- package/dist/plugins/listActions/index.test.d.ts +0 -2
- package/dist/plugins/listActions/index.test.d.ts.map +0 -1
- package/dist/plugins/listActions/index.test.js +0 -454
- package/dist/plugins/listApps/index.test.d.ts +0 -2
- package/dist/plugins/listApps/index.test.d.ts.map +0 -1
- package/dist/plugins/listApps/index.test.js +0 -124
- package/dist/plugins/listConnections/index.test.d.ts +0 -2
- package/dist/plugins/listConnections/index.test.d.ts.map +0 -1
- package/dist/plugins/listConnections/index.test.js +0 -920
- package/dist/plugins/listInputFieldChoices/index.test.d.ts +0 -2
- package/dist/plugins/listInputFieldChoices/index.test.d.ts.map +0 -1
- package/dist/plugins/listInputFieldChoices/index.test.js +0 -717
- package/dist/plugins/listInputFields/index.test.d.ts +0 -2
- package/dist/plugins/listInputFields/index.test.d.ts.map +0 -1
- package/dist/plugins/listInputFields/index.test.js +0 -359
- package/dist/plugins/manifest/index.test.d.ts +0 -2
- package/dist/plugins/manifest/index.test.d.ts.map +0 -1
- package/dist/plugins/manifest/index.test.js +0 -1179
- package/dist/plugins/request/index.test.d.ts +0 -2
- package/dist/plugins/request/index.test.d.ts.map +0 -1
- package/dist/plugins/request/index.test.js +0 -458
- package/dist/plugins/runAction/index.test.d.ts +0 -2
- package/dist/plugins/runAction/index.test.d.ts.map +0 -1
- package/dist/plugins/runAction/index.test.js +0 -350
- package/dist/resolvers/connectionId.test.d.ts +0 -2
- package/dist/resolvers/connectionId.test.d.ts.map +0 -1
- package/dist/resolvers/connectionId.test.js +0 -61
- package/dist/sdk.test.d.ts +0 -2
- package/dist/sdk.test.d.ts.map +0 -1
- package/dist/sdk.test.js +0 -260
- package/dist/types/domain.test.d.ts +0 -2
- package/dist/types/domain.test.d.ts.map +0 -1
- package/dist/types/domain.test.js +0 -39
- package/dist/utils/array-utils.test.d.ts +0 -2
- package/dist/utils/array-utils.test.d.ts.map +0 -1
- package/dist/utils/array-utils.test.js +0 -107
- package/dist/utils/batch-utils.test.d.ts +0 -2
- package/dist/utils/batch-utils.test.d.ts.map +0 -1
- package/dist/utils/batch-utils.test.js +0 -476
- package/dist/utils/domain-utils.test.d.ts +0 -2
- package/dist/utils/domain-utils.test.d.ts.map +0 -1
- package/dist/utils/domain-utils.test.js +0 -346
- package/dist/utils/file-utils.test.d.ts +0 -2
- package/dist/utils/file-utils.test.d.ts.map +0 -1
- package/dist/utils/file-utils.test.js +0 -51
- package/dist/utils/function-utils.test.d.ts +0 -2
- package/dist/utils/function-utils.test.d.ts.map +0 -1
- package/dist/utils/function-utils.test.js +0 -188
- package/dist/utils/id-utils.test.d.ts +0 -2
- package/dist/utils/id-utils.test.d.ts.map +0 -1
- package/dist/utils/id-utils.test.js +0 -22
- package/dist/utils/pagination-utils.test.d.ts +0 -17
- package/dist/utils/pagination-utils.test.d.ts.map +0 -1
- package/dist/utils/pagination-utils.test.js +0 -461
- package/dist/utils/retry-utils.test.d.ts +0 -2
- package/dist/utils/retry-utils.test.d.ts.map +0 -1
- package/dist/utils/retry-utils.test.js +0 -90
- package/dist/utils/string-utils.test.d.ts +0 -2
- package/dist/utils/string-utils.test.d.ts.map +0 -1
- package/dist/utils/string-utils.test.js +0 -59
- package/dist/utils/telemetry-context.test.d.ts +0 -2
- package/dist/utils/telemetry-context.test.d.ts.map +0 -1
- package/dist/utils/telemetry-context.test.js +0 -154
- package/dist/utils/telemetry-utils.test.d.ts +0 -2
- package/dist/utils/telemetry-utils.test.d.ts.map +0 -1
- package/dist/utils/telemetry-utils.test.js +0 -155
- package/dist/utils/url-utils.test.d.ts +0 -2
- package/dist/utils/url-utils.test.d.ts.map +0 -1
- package/dist/utils/url-utils.test.js +0 -103
- package/dist/utils/validation.test.d.ts +0 -2
- package/dist/utils/validation.test.d.ts.map +0 -1
- package/dist/utils/validation.test.js +0 -44
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ZapierValidationError } from "../../types/errors";
|
|
3
|
-
import { findFirstConnectionPlugin } from "./index";
|
|
4
|
-
import { createSdk } from "../../sdk";
|
|
5
|
-
import { ListConnectionsQuerySchema } from "../listConnections/schemas";
|
|
6
|
-
import { eventEmissionPlugin } from "../eventEmission";
|
|
7
|
-
const mockConnections = [
|
|
8
|
-
{
|
|
9
|
-
id: "123",
|
|
10
|
-
title: "My Slack",
|
|
11
|
-
date: "2021-01-01",
|
|
12
|
-
account_id: "123",
|
|
13
|
-
implementation_id: "api_123",
|
|
14
|
-
is_expired: "false",
|
|
15
|
-
expired_at: null,
|
|
16
|
-
is_invite_only: false,
|
|
17
|
-
is_private: false,
|
|
18
|
-
shared_with_all: false,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
id: "456",
|
|
22
|
-
title: "Slack Workspace 2",
|
|
23
|
-
is_expired: "false",
|
|
24
|
-
expired_at: null,
|
|
25
|
-
date: "2021-01-01",
|
|
26
|
-
account_id: "123",
|
|
27
|
-
implementation_id: "api_123",
|
|
28
|
-
is_invite_only: false,
|
|
29
|
-
is_private: false,
|
|
30
|
-
shared_with_all: false,
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
describe("findFirstConnection plugin", () => {
|
|
34
|
-
let mockListConnections;
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
vi.clearAllMocks();
|
|
37
|
-
mockListConnections = vi.fn().mockResolvedValue({
|
|
38
|
-
data: mockConnections,
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
function createTestSdk() {
|
|
42
|
-
// Create a proper plugin chain: first add a mock listConnections plugin, then add findFirstConnection
|
|
43
|
-
const mockListConnectionsPlugin = () => ({
|
|
44
|
-
listConnections: mockListConnections,
|
|
45
|
-
context: {
|
|
46
|
-
meta: {
|
|
47
|
-
listConnections: {
|
|
48
|
-
inputSchema: ListConnectionsQuerySchema,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
// Build SDK with proper plugin composition
|
|
54
|
-
return createSdk()
|
|
55
|
-
.addPlugin(() => ({
|
|
56
|
-
context: {
|
|
57
|
-
options: {},
|
|
58
|
-
},
|
|
59
|
-
}))
|
|
60
|
-
.addPlugin(eventEmissionPlugin)
|
|
61
|
-
.addPlugin(mockListConnectionsPlugin)
|
|
62
|
-
.addPlugin(findFirstConnectionPlugin);
|
|
63
|
-
}
|
|
64
|
-
describe("schema validation", () => {
|
|
65
|
-
it("should pass validation with empty options", async () => {
|
|
66
|
-
const sdk = createTestSdk();
|
|
67
|
-
const result = await sdk.findFirstConnection({});
|
|
68
|
-
expect(result.data).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
it("should pass validation with undefined options", async () => {
|
|
71
|
-
const sdk = createTestSdk();
|
|
72
|
-
const result = await sdk.findFirstConnection();
|
|
73
|
-
expect(result.data).toBeDefined();
|
|
74
|
-
});
|
|
75
|
-
it("should throw validation error for invalid appKey type", async () => {
|
|
76
|
-
const sdk = createTestSdk();
|
|
77
|
-
await expect(sdk.findFirstConnection({
|
|
78
|
-
appKey: 123, // intentionally wrong type for testing
|
|
79
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
80
|
-
});
|
|
81
|
-
it("should throw validation error for invalid search type", async () => {
|
|
82
|
-
const sdk = createTestSdk();
|
|
83
|
-
await expect(sdk.findFirstConnection({
|
|
84
|
-
search: 123,
|
|
85
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
86
|
-
});
|
|
87
|
-
it("should throw validation error for invalid parameter types", async () => {
|
|
88
|
-
const sdk = createTestSdk();
|
|
89
|
-
await expect(sdk.findFirstConnection({
|
|
90
|
-
title: 123,
|
|
91
|
-
accountId: 456,
|
|
92
|
-
owner: true,
|
|
93
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
94
|
-
});
|
|
95
|
-
it("should pass validation with all valid fields", async () => {
|
|
96
|
-
const sdk = createTestSdk();
|
|
97
|
-
const result = await sdk.findFirstConnection({
|
|
98
|
-
appKey: "slack",
|
|
99
|
-
search: "workspace",
|
|
100
|
-
title: "My Slack Workspace",
|
|
101
|
-
accountId: "acc_123",
|
|
102
|
-
owner: "me",
|
|
103
|
-
});
|
|
104
|
-
expect(result.data).toBeDefined();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe("business logic", () => {
|
|
108
|
-
it("should return first connection when found", async () => {
|
|
109
|
-
const mockConnection = mockConnections[0];
|
|
110
|
-
mockListConnections.mockResolvedValue({
|
|
111
|
-
data: [mockConnection],
|
|
112
|
-
});
|
|
113
|
-
const sdk = createTestSdk();
|
|
114
|
-
const result = await sdk.findFirstConnection({
|
|
115
|
-
appKey: "slack",
|
|
116
|
-
});
|
|
117
|
-
expect(result.data).toEqual(mockConnection);
|
|
118
|
-
});
|
|
119
|
-
it("should throw error when no connections found", async () => {
|
|
120
|
-
mockListConnections.mockResolvedValue({
|
|
121
|
-
data: [],
|
|
122
|
-
});
|
|
123
|
-
const sdk = createTestSdk();
|
|
124
|
-
await expect(sdk.findFirstConnection({
|
|
125
|
-
appKey: "nonexistent",
|
|
126
|
-
})).rejects.toThrow("No connection found matching the specified criteria");
|
|
127
|
-
});
|
|
128
|
-
it("should return first connection when multiple found", async () => {
|
|
129
|
-
const mockConnection = mockConnections[0];
|
|
130
|
-
mockListConnections.mockResolvedValue({
|
|
131
|
-
data: [mockConnection, mockConnections[1]],
|
|
132
|
-
});
|
|
133
|
-
const sdk = createTestSdk();
|
|
134
|
-
const result = await sdk.findFirstConnection({
|
|
135
|
-
search: "Slack",
|
|
136
|
-
});
|
|
137
|
-
expect(result.data).toEqual(mockConnection);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
describe("options forwarding", () => {
|
|
141
|
-
it("should forward all options to listConnections", async () => {
|
|
142
|
-
const sdk = createTestSdk();
|
|
143
|
-
const options = {
|
|
144
|
-
appKey: "slack",
|
|
145
|
-
search: "workspace",
|
|
146
|
-
title: "My Slack Workspace",
|
|
147
|
-
accountId: "acc_123",
|
|
148
|
-
owner: "me",
|
|
149
|
-
};
|
|
150
|
-
await sdk.findFirstConnection(options);
|
|
151
|
-
expect(mockListConnections).toHaveBeenCalledWith(expect.objectContaining({
|
|
152
|
-
...options,
|
|
153
|
-
maxItems: 1,
|
|
154
|
-
}));
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe("limit enforcement", () => {
|
|
158
|
-
it("should automatically set maxItems to 1", async () => {
|
|
159
|
-
const sdk = createTestSdk();
|
|
160
|
-
await sdk.findFirstConnection({
|
|
161
|
-
appKey: "slack",
|
|
162
|
-
});
|
|
163
|
-
expect(mockListConnections).toHaveBeenCalledWith(expect.objectContaining({
|
|
164
|
-
appKey: "slack",
|
|
165
|
-
maxItems: 1,
|
|
166
|
-
}));
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe("context and metadata", () => {
|
|
170
|
-
it("should provide context with meta information", () => {
|
|
171
|
-
const sdk = createTestSdk();
|
|
172
|
-
const context = sdk.getContext();
|
|
173
|
-
expect(context.meta.findFirstConnection).toBeDefined();
|
|
174
|
-
expect(context.meta.findFirstConnection.inputSchema).toBeDefined();
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/findUniqueConnection/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ZapierValidationError, ZapierResourceNotFoundError, } from "../../types/errors";
|
|
3
|
-
import { findUniqueConnectionPlugin } from "./index";
|
|
4
|
-
import { createSdk } from "../../sdk";
|
|
5
|
-
import { ListConnectionsQuerySchema } from "../listConnections/schemas";
|
|
6
|
-
import { eventEmissionPlugin } from "../eventEmission";
|
|
7
|
-
const mockConnection = {
|
|
8
|
-
id: "123",
|
|
9
|
-
title: "My Slack",
|
|
10
|
-
date: "2021-01-01",
|
|
11
|
-
account_id: "123",
|
|
12
|
-
implementation_id: "api_123",
|
|
13
|
-
is_expired: "false",
|
|
14
|
-
expired_at: null,
|
|
15
|
-
is_invite_only: false,
|
|
16
|
-
is_private: false,
|
|
17
|
-
shared_with_all: false,
|
|
18
|
-
};
|
|
19
|
-
const mockConnections = [
|
|
20
|
-
mockConnection,
|
|
21
|
-
{
|
|
22
|
-
id: "456",
|
|
23
|
-
title: "Slack Workspace 2",
|
|
24
|
-
is_expired: "false",
|
|
25
|
-
expired_at: null,
|
|
26
|
-
date: "2021-01-01",
|
|
27
|
-
account_id: "123",
|
|
28
|
-
implementation_id: "api_123",
|
|
29
|
-
is_invite_only: false,
|
|
30
|
-
is_private: false,
|
|
31
|
-
shared_with_all: false,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
describe("findUniqueConnection plugin", () => {
|
|
35
|
-
let mockListConnections;
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
vi.clearAllMocks();
|
|
38
|
-
mockListConnections = vi.fn().mockResolvedValue({
|
|
39
|
-
data: [mockConnection],
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
function createTestSdk() {
|
|
43
|
-
// Create a proper plugin chain: first add a mock listConnections plugin, then add findUniqueConnection
|
|
44
|
-
const mockListConnectionsPlugin = () => ({
|
|
45
|
-
listConnections: mockListConnections,
|
|
46
|
-
context: {
|
|
47
|
-
meta: {
|
|
48
|
-
listConnections: {
|
|
49
|
-
inputSchema: ListConnectionsQuerySchema,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
// Build SDK with proper plugin composition
|
|
55
|
-
return createSdk()
|
|
56
|
-
.addPlugin(() => ({
|
|
57
|
-
context: {
|
|
58
|
-
options: {},
|
|
59
|
-
},
|
|
60
|
-
}))
|
|
61
|
-
.addPlugin(eventEmissionPlugin)
|
|
62
|
-
.addPlugin(mockListConnectionsPlugin)
|
|
63
|
-
.addPlugin(findUniqueConnectionPlugin);
|
|
64
|
-
}
|
|
65
|
-
describe("schema validation", () => {
|
|
66
|
-
it("should pass validation with empty options", async () => {
|
|
67
|
-
const sdk = createTestSdk();
|
|
68
|
-
const result = await sdk.findUniqueConnection({});
|
|
69
|
-
expect(result.data).toBeDefined();
|
|
70
|
-
});
|
|
71
|
-
it("should throw validation error for invalid appKey type", async () => {
|
|
72
|
-
const sdk = createTestSdk();
|
|
73
|
-
await expect(sdk.findUniqueConnection({
|
|
74
|
-
appKey: 123,
|
|
75
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
76
|
-
});
|
|
77
|
-
it("should throw validation error for invalid parameter types", async () => {
|
|
78
|
-
const sdk = createTestSdk();
|
|
79
|
-
await expect(sdk.findUniqueConnection({
|
|
80
|
-
search: 123,
|
|
81
|
-
title: 456,
|
|
82
|
-
accountId: 789,
|
|
83
|
-
owner: false,
|
|
84
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
85
|
-
});
|
|
86
|
-
it("should pass validation with all valid fields", async () => {
|
|
87
|
-
const sdk = createTestSdk();
|
|
88
|
-
const result = await sdk.findUniqueConnection({
|
|
89
|
-
appKey: "slack",
|
|
90
|
-
search: "Workspace",
|
|
91
|
-
title: "My Slack",
|
|
92
|
-
accountId: "acc_123",
|
|
93
|
-
owner: "me",
|
|
94
|
-
});
|
|
95
|
-
expect(result.data).toBeDefined();
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
describe("business logic", () => {
|
|
99
|
-
it("should return the first connection when exactly one is found", async () => {
|
|
100
|
-
mockListConnections.mockResolvedValue({
|
|
101
|
-
data: [mockConnection],
|
|
102
|
-
});
|
|
103
|
-
const sdk = createTestSdk();
|
|
104
|
-
const result = await sdk.findUniqueConnection({
|
|
105
|
-
appKey: "slack",
|
|
106
|
-
});
|
|
107
|
-
expect(result.data).toEqual(mockConnection);
|
|
108
|
-
});
|
|
109
|
-
it("should throw ZapierResourceNotFoundError when no connections found", async () => {
|
|
110
|
-
mockListConnections.mockResolvedValue({
|
|
111
|
-
data: [],
|
|
112
|
-
});
|
|
113
|
-
const sdk = createTestSdk();
|
|
114
|
-
await expect(sdk.findUniqueConnection({
|
|
115
|
-
appKey: "nonexistent",
|
|
116
|
-
})).rejects.toThrow(ZapierResourceNotFoundError);
|
|
117
|
-
await expect(sdk.findUniqueConnection({
|
|
118
|
-
appKey: "nonexistent",
|
|
119
|
-
})).rejects.toThrow("No connection found matching the specified criteria");
|
|
120
|
-
});
|
|
121
|
-
it("should throw ZapierValidationError when multiple connections found", async () => {
|
|
122
|
-
mockListConnections.mockResolvedValue({
|
|
123
|
-
data: mockConnections, // Two connections
|
|
124
|
-
});
|
|
125
|
-
const sdk = createTestSdk();
|
|
126
|
-
await expect(sdk.findUniqueConnection({
|
|
127
|
-
search: "Workspace",
|
|
128
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
129
|
-
await expect(sdk.findUniqueConnection({
|
|
130
|
-
search: "Workspace",
|
|
131
|
-
})).rejects.toThrow("Multiple connections found matching the specified criteria. Expected exactly one.");
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe("options forwarding", () => {
|
|
135
|
-
it("should forward all options to listConnections with maxItems=2", async () => {
|
|
136
|
-
const sdk = createTestSdk();
|
|
137
|
-
const options = {
|
|
138
|
-
appKey: "slack",
|
|
139
|
-
search: "workspace",
|
|
140
|
-
title: "My Slack Workspace",
|
|
141
|
-
accountId: "acc_123",
|
|
142
|
-
owner: "me",
|
|
143
|
-
};
|
|
144
|
-
await sdk.findUniqueConnection(options);
|
|
145
|
-
expect(mockListConnections).toHaveBeenCalledWith(expect.objectContaining({
|
|
146
|
-
...options,
|
|
147
|
-
maxItems: 2,
|
|
148
|
-
}));
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
describe("context and metadata", () => {
|
|
152
|
-
it("should provide context with meta information", () => {
|
|
153
|
-
const sdk = createTestSdk();
|
|
154
|
-
const context = sdk.getContext();
|
|
155
|
-
expect(context.meta.findUniqueConnection).toBeDefined();
|
|
156
|
-
expect(context.meta.findUniqueConnection.inputSchema).toBeDefined();
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/getAction/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ZapierValidationError, ZapierResourceNotFoundError, } from "../../types/errors";
|
|
3
|
-
import { getActionPlugin } from "./index";
|
|
4
|
-
import { createSdk } from "../../sdk";
|
|
5
|
-
import { ListActionsSchema } from "../listActions/schemas";
|
|
6
|
-
import { eventEmissionPlugin } from "../eventEmission";
|
|
7
|
-
const mockActions = [
|
|
8
|
-
{
|
|
9
|
-
type: "action",
|
|
10
|
-
key: "user_by_email",
|
|
11
|
-
title: "Search User by Email",
|
|
12
|
-
description: "Find a user by email address",
|
|
13
|
-
app_key: "slack",
|
|
14
|
-
action_type: "search",
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
type: "action",
|
|
18
|
-
key: "search_messages",
|
|
19
|
-
title: "Search Messages",
|
|
20
|
-
description: "Search for messages in channels",
|
|
21
|
-
app_key: "slack",
|
|
22
|
-
action_type: "search",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
type: "action",
|
|
26
|
-
key: "user_by_email",
|
|
27
|
-
title: "Search User by Email",
|
|
28
|
-
description: "Find a user by email address",
|
|
29
|
-
app_key: "slack",
|
|
30
|
-
action_type: "write", // Different action type for testing mismatch
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
describe("getAction plugin", () => {
|
|
34
|
-
let mockListActions;
|
|
35
|
-
let mockApiClient;
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
vi.clearAllMocks();
|
|
38
|
-
// Mock listActions to return a promise with .items() method
|
|
39
|
-
mockListActions = vi.fn().mockImplementation(() => {
|
|
40
|
-
const promise = Promise.resolve({
|
|
41
|
-
data: mockActions,
|
|
42
|
-
});
|
|
43
|
-
// Add .items() method that returns an async iterable
|
|
44
|
-
return Object.assign(promise, {
|
|
45
|
-
items: () => ({
|
|
46
|
-
async *[Symbol.asyncIterator]() {
|
|
47
|
-
for (const action of mockActions) {
|
|
48
|
-
yield action;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
mockApiClient = {};
|
|
55
|
-
});
|
|
56
|
-
function createTestSdk() {
|
|
57
|
-
// Create a proper plugin chain with context dependencies
|
|
58
|
-
const mockListActionsPlugin = () => ({
|
|
59
|
-
listActions: mockListActions,
|
|
60
|
-
context: {
|
|
61
|
-
meta: {
|
|
62
|
-
listActions: {
|
|
63
|
-
inputSchema: ListActionsSchema,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
// Build SDK with proper plugin composition, providing API in initial context
|
|
69
|
-
return createSdk({}, {}, { api: mockApiClient, meta: {}, options: {} })
|
|
70
|
-
.addPlugin(eventEmissionPlugin)
|
|
71
|
-
.addPlugin(mockListActionsPlugin)
|
|
72
|
-
.addPlugin(getActionPlugin);
|
|
73
|
-
}
|
|
74
|
-
describe("schema validation", () => {
|
|
75
|
-
it("should throw validation error for missing appKey", async () => {
|
|
76
|
-
const sdk = createTestSdk();
|
|
77
|
-
await expect(sdk.getAction({
|
|
78
|
-
actionType: "search",
|
|
79
|
-
actionKey: "user_by_email",
|
|
80
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
81
|
-
});
|
|
82
|
-
it("should throw validation error for missing actionType", async () => {
|
|
83
|
-
const sdk = createTestSdk();
|
|
84
|
-
await expect(sdk.getAction({
|
|
85
|
-
appKey: "slack",
|
|
86
|
-
actionKey: "user_by_email",
|
|
87
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
88
|
-
});
|
|
89
|
-
it("should throw validation error for missing actionKey", async () => {
|
|
90
|
-
const sdk = createTestSdk();
|
|
91
|
-
await expect(sdk.getAction({
|
|
92
|
-
appKey: "slack",
|
|
93
|
-
actionType: "search",
|
|
94
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
95
|
-
});
|
|
96
|
-
it("should throw validation error for invalid appKey type", async () => {
|
|
97
|
-
const sdk = createTestSdk();
|
|
98
|
-
await expect(sdk.getAction({
|
|
99
|
-
appKey: 123,
|
|
100
|
-
actionType: "search",
|
|
101
|
-
actionKey: "user_by_email",
|
|
102
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
103
|
-
});
|
|
104
|
-
it("should throw validation error for invalid actionType", async () => {
|
|
105
|
-
const sdk = createTestSdk();
|
|
106
|
-
await expect(sdk.getAction({
|
|
107
|
-
appKey: "slack",
|
|
108
|
-
actionType: "invalid-type",
|
|
109
|
-
actionKey: "user_by_email",
|
|
110
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
111
|
-
});
|
|
112
|
-
it("should throw validation error for invalid actionKey type", async () => {
|
|
113
|
-
const sdk = createTestSdk();
|
|
114
|
-
await expect(sdk.getAction({
|
|
115
|
-
appKey: "slack",
|
|
116
|
-
actionType: "search",
|
|
117
|
-
actionKey: 123,
|
|
118
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
119
|
-
});
|
|
120
|
-
it("should throw validation error for empty appKey", async () => {
|
|
121
|
-
const sdk = createTestSdk();
|
|
122
|
-
await expect(sdk.getAction({
|
|
123
|
-
appKey: "",
|
|
124
|
-
actionType: "search",
|
|
125
|
-
actionKey: "user_by_email",
|
|
126
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
127
|
-
});
|
|
128
|
-
it("should throw validation error for empty actionKey", async () => {
|
|
129
|
-
const sdk = createTestSdk();
|
|
130
|
-
await expect(sdk.getAction({
|
|
131
|
-
appKey: "slack",
|
|
132
|
-
actionType: "search",
|
|
133
|
-
actionKey: "",
|
|
134
|
-
})).rejects.toThrow(ZapierValidationError);
|
|
135
|
-
});
|
|
136
|
-
it("should pass validation with all required fields", async () => {
|
|
137
|
-
const sdk = createTestSdk();
|
|
138
|
-
const result = await sdk.getAction({
|
|
139
|
-
appKey: "slack",
|
|
140
|
-
actionType: "search",
|
|
141
|
-
actionKey: "user_by_email",
|
|
142
|
-
});
|
|
143
|
-
expect(result.data).toEqual(mockActions[0]);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
describe("action lookup", () => {
|
|
147
|
-
it("should call listActions with correct parameters", async () => {
|
|
148
|
-
const sdk = createTestSdk();
|
|
149
|
-
await sdk.getAction({
|
|
150
|
-
appKey: "slack",
|
|
151
|
-
actionType: "search",
|
|
152
|
-
actionKey: "user_by_email",
|
|
153
|
-
});
|
|
154
|
-
expect(mockListActions).toHaveBeenCalledWith(expect.objectContaining({
|
|
155
|
-
appKey: "slack",
|
|
156
|
-
}));
|
|
157
|
-
});
|
|
158
|
-
it("should return the correct action when found", async () => {
|
|
159
|
-
const sdk = createTestSdk();
|
|
160
|
-
const result = await sdk.getAction({
|
|
161
|
-
appKey: "slack",
|
|
162
|
-
actionType: "search",
|
|
163
|
-
actionKey: "user_by_email",
|
|
164
|
-
});
|
|
165
|
-
expect(result.data).toEqual(mockActions[0]);
|
|
166
|
-
});
|
|
167
|
-
it("should throw error when action key not found", async () => {
|
|
168
|
-
const sdk = createTestSdk();
|
|
169
|
-
await expect(sdk.getAction({
|
|
170
|
-
appKey: "slack",
|
|
171
|
-
actionType: "search",
|
|
172
|
-
actionKey: "nonexistent_action",
|
|
173
|
-
})).rejects.toThrow(ZapierResourceNotFoundError);
|
|
174
|
-
});
|
|
175
|
-
it("should throw error when action type doesn't match", async () => {
|
|
176
|
-
const sdk = createTestSdk();
|
|
177
|
-
await expect(sdk.getAction({
|
|
178
|
-
appKey: "slack",
|
|
179
|
-
actionType: "write",
|
|
180
|
-
actionKey: "search_messages", // This action is type "search" in mock
|
|
181
|
-
})).rejects.toThrow(ZapierResourceNotFoundError);
|
|
182
|
-
});
|
|
183
|
-
it("should handle listActions errors", async () => {
|
|
184
|
-
mockListActions.mockImplementation(() => {
|
|
185
|
-
const promise = Promise.reject(new Error("API Error"));
|
|
186
|
-
// Add .items() method that also rejects
|
|
187
|
-
return Object.assign(promise, {
|
|
188
|
-
items: () => ({
|
|
189
|
-
async *[Symbol.asyncIterator]() {
|
|
190
|
-
throw new Error("API Error");
|
|
191
|
-
},
|
|
192
|
-
}),
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
const sdk = createTestSdk();
|
|
196
|
-
await expect(sdk.getAction({
|
|
197
|
-
appKey: "slack",
|
|
198
|
-
actionType: "search",
|
|
199
|
-
actionKey: "user_by_email",
|
|
200
|
-
})).rejects.toThrow("API Error");
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
describe("plugin integration", () => {
|
|
204
|
-
it("should provide metadata in context", () => {
|
|
205
|
-
const sdk = createTestSdk();
|
|
206
|
-
const context = sdk.getContext();
|
|
207
|
-
expect(context.meta.getAction).toBeDefined();
|
|
208
|
-
expect(context.meta.getAction.inputSchema).toBeDefined();
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/getApp/index.test.ts"],"names":[],"mappings":""}
|