smartling-api-sdk-nodejs 2.21.1 → 2.23.0
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/.scannerwork/report-task.txt +2 -2
- package/api/base/index.ts +2 -1
- package/api/tags/dto/project-id-tag-dto.ts +5 -0
- package/api/tags/dto/string-tags-dto.ts +6 -0
- package/api/tags/dto/tag-dto.ts +3 -0
- package/api/tags/index.ts +87 -0
- package/api/tags/params/add-tags-to-strings-parameters.ts +4 -0
- package/api/tags/params/base-tags-strings-parameters.ts +40 -0
- package/api/tags/params/list-account-tags-parameters.ts +40 -0
- package/api/tags/params/list-project-tags-parameters.ts +30 -0
- package/api/tags/params/remove-all-tags-from-strings-parameters.ts +18 -0
- package/api/tags/params/remove-tags-from-strings-parameters.ts +4 -0
- package/api/tags/params/search-string-tags-parameters.ts +18 -0
- package/api/webhooks/dto/scrollable-response.ts +7 -0
- package/api/webhooks/dto/subscription-attempted-event-dto.ts +10 -0
- package/api/webhooks/dto/subscription-dto.ts +18 -0
- package/api/webhooks/dto/subscription-event-attempt-dto.ts +16 -0
- package/api/webhooks/dto/subscription-event-attempt-status.ts +8 -0
- package/api/webhooks/dto/subscription-event-dto.ts +8 -0
- package/api/webhooks/dto/subscription-event-trigger-type.ts +6 -0
- package/api/webhooks/dto/subscription-secret-dto.ts +5 -0
- package/api/webhooks/dto/subscription-statistics-dto.ts +8 -0
- package/api/webhooks/dto/webhook-event-type.dto.ts +7 -0
- package/api/webhooks/index.ts +17 -0
- package/api/webhooks/params/create-subscription-parameters.ts +9 -0
- package/api/webhooks/params/create-update-subscription-parameters.ts +70 -0
- package/api/webhooks/params/get-subscription-events-parameters.ts +38 -0
- package/api/webhooks/params/subscription-event.ts +6 -0
- package/api/webhooks/params/subscription-request-header.ts +6 -0
- package/api/webhooks/params/update-subscription-parameters.ts +19 -0
- package/api/webhooks/params/update-subscription-secret-parameters.ts +14 -0
- package/api/webhooks/smartling-webhooks-api.ts +190 -0
- package/built/api/base/index.js +2 -1
- package/built/api/base/index.js.map +1 -1
- package/built/api/tags/dto/project-id-tag-dto.d.ts +4 -0
- package/built/api/tags/dto/project-id-tag-dto.js +3 -0
- package/built/api/tags/dto/project-id-tag-dto.js.map +1 -0
- package/built/api/tags/dto/string-tags-dto.d.ts +5 -0
- package/built/api/tags/dto/string-tags-dto.js +3 -0
- package/built/api/tags/dto/string-tags-dto.js.map +1 -0
- package/built/api/tags/dto/tag-dto.d.ts +3 -0
- package/built/api/tags/dto/tag-dto.js +3 -0
- package/built/api/tags/dto/tag-dto.js.map +1 -0
- package/built/api/tags/index.d.ts +22 -0
- package/built/api/tags/index.js +52 -0
- package/built/api/tags/index.js.map +1 -0
- package/built/api/tags/params/add-tags-to-strings-parameters.d.ts +3 -0
- package/built/api/tags/params/add-tags-to-strings-parameters.js +8 -0
- package/built/api/tags/params/add-tags-to-strings-parameters.js.map +1 -0
- package/built/api/tags/params/base-tags-strings-parameters.d.ts +5 -0
- package/built/api/tags/params/base-tags-strings-parameters.js +34 -0
- package/built/api/tags/params/base-tags-strings-parameters.js.map +1 -0
- package/built/api/tags/params/list-account-tags-parameters.d.ts +7 -0
- package/built/api/tags/params/list-account-tags-parameters.js +34 -0
- package/built/api/tags/params/list-account-tags-parameters.js.map +1 -0
- package/built/api/tags/params/list-project-tags-parameters.d.ts +6 -0
- package/built/api/tags/params/list-project-tags-parameters.js +27 -0
- package/built/api/tags/params/list-project-tags-parameters.js.map +1 -0
- package/built/api/tags/params/remove-all-tags-from-strings-parameters.d.ts +4 -0
- package/built/api/tags/params/remove-all-tags-from-strings-parameters.js +19 -0
- package/built/api/tags/params/remove-all-tags-from-strings-parameters.js.map +1 -0
- package/built/api/tags/params/remove-tags-from-strings-parameters.d.ts +3 -0
- package/built/api/tags/params/remove-tags-from-strings-parameters.js +8 -0
- package/built/api/tags/params/remove-tags-from-strings-parameters.js.map +1 -0
- package/built/api/tags/params/search-string-tags-parameters.d.ts +4 -0
- package/built/api/tags/params/search-string-tags-parameters.js +19 -0
- package/built/api/tags/params/search-string-tags-parameters.js.map +1 -0
- package/built/api/webhooks/dto/scrollable-response.d.ts +6 -0
- package/built/api/webhooks/dto/scrollable-response.js +3 -0
- package/built/api/webhooks/dto/scrollable-response.js.map +1 -0
- package/built/api/webhooks/dto/subscription-attempted-event-dto.d.ts +8 -0
- package/built/api/webhooks/dto/subscription-attempted-event-dto.js +3 -0
- package/built/api/webhooks/dto/subscription-attempted-event-dto.js.map +1 -0
- package/built/api/webhooks/dto/subscription-dto.d.ts +16 -0
- package/built/api/webhooks/dto/subscription-dto.js +3 -0
- package/built/api/webhooks/dto/subscription-dto.js.map +1 -0
- package/built/api/webhooks/dto/subscription-event-attempt-dto.d.ts +14 -0
- package/built/api/webhooks/dto/subscription-event-attempt-dto.js +3 -0
- package/built/api/webhooks/dto/subscription-event-attempt-dto.js.map +1 -0
- package/built/api/webhooks/dto/subscription-event-attempt-status.d.ts +7 -0
- package/built/api/webhooks/dto/subscription-event-attempt-status.js +12 -0
- package/built/api/webhooks/dto/subscription-event-attempt-status.js.map +1 -0
- package/built/api/webhooks/dto/subscription-event-dto.d.ts +7 -0
- package/built/api/webhooks/dto/subscription-event-dto.js +3 -0
- package/built/api/webhooks/dto/subscription-event-dto.js.map +1 -0
- package/built/api/webhooks/dto/subscription-event-trigger-type.d.ts +5 -0
- package/built/api/webhooks/dto/subscription-event-trigger-type.js +10 -0
- package/built/api/webhooks/dto/subscription-event-trigger-type.js.map +1 -0
- package/built/api/webhooks/dto/subscription-secret-dto.d.ts +4 -0
- package/built/api/webhooks/dto/subscription-secret-dto.js +3 -0
- package/built/api/webhooks/dto/subscription-secret-dto.js.map +1 -0
- package/built/api/webhooks/dto/subscription-statistics-dto.d.ts +7 -0
- package/built/api/webhooks/dto/subscription-statistics-dto.js +3 -0
- package/built/api/webhooks/dto/subscription-statistics-dto.js.map +1 -0
- package/built/api/webhooks/dto/webhook-event-type.dto.d.ts +6 -0
- package/built/api/webhooks/dto/webhook-event-type.dto.js +7 -0
- package/built/api/webhooks/dto/webhook-event-type.dto.js.map +1 -0
- package/built/api/webhooks/index.d.ts +17 -0
- package/built/api/webhooks/index.js +20 -0
- package/built/api/webhooks/index.js.map +1 -0
- package/built/api/webhooks/params/create-subscription-parameters.d.ts +4 -0
- package/built/api/webhooks/params/create-subscription-parameters.js +12 -0
- package/built/api/webhooks/params/create-subscription-parameters.js.map +1 -0
- package/built/api/webhooks/params/create-update-subscription-parameters.d.ts +9 -0
- package/built/api/webhooks/params/create-update-subscription-parameters.js +54 -0
- package/built/api/webhooks/params/create-update-subscription-parameters.js.map +1 -0
- package/built/api/webhooks/params/get-subscription-events-parameters.d.ts +11 -0
- package/built/api/webhooks/params/get-subscription-events-parameters.js +35 -0
- package/built/api/webhooks/params/get-subscription-events-parameters.js.map +1 -0
- package/built/api/webhooks/params/subscription-event.d.ts +5 -0
- package/built/api/webhooks/params/subscription-event.js +3 -0
- package/built/api/webhooks/params/subscription-event.js.map +1 -0
- package/built/api/webhooks/params/subscription-request-header.d.ts +5 -0
- package/built/api/webhooks/params/subscription-request-header.js +3 -0
- package/built/api/webhooks/params/subscription-request-header.js.map +1 -0
- package/built/api/webhooks/params/update-subscription-parameters.d.ts +5 -0
- package/built/api/webhooks/params/update-subscription-parameters.js +12 -0
- package/built/api/webhooks/params/update-subscription-parameters.js.map +1 -0
- package/built/api/webhooks/params/update-subscription-secret-parameters.d.ts +4 -0
- package/built/api/webhooks/params/update-subscription-secret-parameters.js +16 -0
- package/built/api/webhooks/params/update-subscription-secret-parameters.js.map +1 -0
- package/built/api/webhooks/smartling-webhooks-api.d.ts +35 -0
- package/built/api/webhooks/smartling-webhooks-api.js +61 -0
- package/built/api/webhooks/smartling-webhooks-api.js.map +1 -0
- package/built/index.d.ts +12 -0
- package/built/index.js +12 -0
- package/built/index.js.map +1 -1
- package/built/package.json +3 -3
- package/index.ts +12 -0
- package/package.json +3 -3
- package/test/tags.spec.ts +472 -0
- package/test/webhooks.spec.ts +610 -0
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import sinon from "sinon";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import {
|
|
4
|
+
SmartlingWebhooksApi,
|
|
5
|
+
CreateSubscriptionParameters,
|
|
6
|
+
UpdateSubscriptionParameters,
|
|
7
|
+
UpdateSubscriptionSecretParameters,
|
|
8
|
+
GetSubscriptionEventsParameters,
|
|
9
|
+
SubscriptionEventAttemptStatus,
|
|
10
|
+
SubscriptionEvent
|
|
11
|
+
} from "../api/webhooks";
|
|
12
|
+
import { SmartlingAuthApi } from "../api/auth";
|
|
13
|
+
import { SmartlingException } from "../api/exception";
|
|
14
|
+
import { loggerMock, authMock, responseMock } from "./mock";
|
|
15
|
+
|
|
16
|
+
describe("SmartlingWebhooksApi class tests.", () => {
|
|
17
|
+
const accountUid = "testAccountUid";
|
|
18
|
+
let webhooksApi: SmartlingWebhooksApi;
|
|
19
|
+
let webhooksApiFetchStub;
|
|
20
|
+
let webhooksApiUaStub;
|
|
21
|
+
let responseMockTextStub;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
webhooksApi = new SmartlingWebhooksApi("https://test.com", authMock as unknown as SmartlingAuthApi, loggerMock);
|
|
25
|
+
|
|
26
|
+
webhooksApiFetchStub = sinon.stub(webhooksApi, "fetch");
|
|
27
|
+
webhooksApiUaStub = sinon.stub(webhooksApi, "ua");
|
|
28
|
+
responseMockTextStub = sinon.stub(responseMock, "text");
|
|
29
|
+
|
|
30
|
+
webhooksApiUaStub.returns("test_user_agent");
|
|
31
|
+
webhooksApiFetchStub.returns(responseMock);
|
|
32
|
+
responseMockTextStub.returns("{\"response\": {}}");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
webhooksApiFetchStub.restore();
|
|
37
|
+
responseMockTextStub.restore();
|
|
38
|
+
webhooksApiUaStub.restore();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("gets all subscriptions", async () => {
|
|
42
|
+
await webhooksApi.getSubscriptions(accountUid);
|
|
43
|
+
|
|
44
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
45
|
+
sinon.assert.calledWithExactly(
|
|
46
|
+
webhooksApiFetchStub,
|
|
47
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions`,
|
|
48
|
+
{
|
|
49
|
+
headers: {
|
|
50
|
+
Authorization: "test_token_type test_access_token",
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
"User-Agent": "test_user_agent"
|
|
53
|
+
},
|
|
54
|
+
method: "get"
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("gets a subscription", async () => {
|
|
60
|
+
const subscriptionUid = "subscriptionUid";
|
|
61
|
+
await webhooksApi.getSubscription(accountUid, subscriptionUid);
|
|
62
|
+
|
|
63
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
64
|
+
sinon.assert.calledWithExactly(
|
|
65
|
+
webhooksApiFetchStub,
|
|
66
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}`,
|
|
67
|
+
{
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: "test_token_type test_access_token",
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
"User-Agent": "test_user_agent"
|
|
72
|
+
},
|
|
73
|
+
method: "get"
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("gets available webhook event types", async () => {
|
|
79
|
+
await webhooksApi.getAvailableEventTypes(accountUid);
|
|
80
|
+
|
|
81
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
82
|
+
sinon.assert.calledWithExactly(
|
|
83
|
+
webhooksApiFetchStub,
|
|
84
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/available-event-types`,
|
|
85
|
+
{
|
|
86
|
+
headers: {
|
|
87
|
+
Authorization: "test_token_type test_access_token",
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
"User-Agent": "test_user_agent"
|
|
90
|
+
},
|
|
91
|
+
method: "get"
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("createSubscription", () => {
|
|
97
|
+
it("creates a subscription", async () => {
|
|
98
|
+
const event: SubscriptionEvent = {
|
|
99
|
+
type: "project.created",
|
|
100
|
+
schemaVersion: "1.0"
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const params = new CreateSubscriptionParameters(
|
|
104
|
+
"TestSub",
|
|
105
|
+
"https://callback.url/hook",
|
|
106
|
+
[event]
|
|
107
|
+
)
|
|
108
|
+
.setDescription("Webhook for new projects")
|
|
109
|
+
.setRequestHeaders([{ headerName: "X-Auth", headerValue: "secret" }])
|
|
110
|
+
.setProjectUids(["project-1", "project-2"])
|
|
111
|
+
.setPayloadSecret("mySecret");
|
|
112
|
+
|
|
113
|
+
await webhooksApi.createSubscription(accountUid, params);
|
|
114
|
+
|
|
115
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
116
|
+
sinon.assert.calledWithExactly(
|
|
117
|
+
webhooksApiFetchStub,
|
|
118
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions`,
|
|
119
|
+
{
|
|
120
|
+
headers: {
|
|
121
|
+
Authorization: "test_token_type test_access_token",
|
|
122
|
+
"Content-Type": "application/json",
|
|
123
|
+
"User-Agent": "test_user_agent"
|
|
124
|
+
},
|
|
125
|
+
method: "post",
|
|
126
|
+
body: JSON.stringify({
|
|
127
|
+
subscriptionName: "TestSub",
|
|
128
|
+
subscriptionUrl: "https://callback.url/hook",
|
|
129
|
+
events: [{
|
|
130
|
+
type: "project.created",
|
|
131
|
+
schemaVersion: "1.0"
|
|
132
|
+
}],
|
|
133
|
+
description: "Webhook for new projects",
|
|
134
|
+
requestHeaders: [{ headerName: "X-Auth", headerValue: "secret" }],
|
|
135
|
+
projectUids: ["project-1", "project-2"],
|
|
136
|
+
payloadSecret: "mySecret"
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("throws if subscription name is missing", () => {
|
|
143
|
+
assert.throws(() => {
|
|
144
|
+
// eslint-disable-next-line no-new
|
|
145
|
+
new CreateSubscriptionParameters("", "https://callback.url", [{
|
|
146
|
+
type: "project.created",
|
|
147
|
+
schemaVersion: "1.0"
|
|
148
|
+
}]);
|
|
149
|
+
}, SmartlingException);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("throws if subscription url is missing", () => {
|
|
153
|
+
assert.throws(() => {
|
|
154
|
+
// eslint-disable-next-line no-new
|
|
155
|
+
new CreateSubscriptionParameters("name", "", [{
|
|
156
|
+
type: "project.created",
|
|
157
|
+
schemaVersion: "1.0"
|
|
158
|
+
}]);
|
|
159
|
+
}, SmartlingException);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("throws if events are empty", () => {
|
|
163
|
+
assert.throws(() => {
|
|
164
|
+
// eslint-disable-next-line no-new
|
|
165
|
+
new CreateSubscriptionParameters("name", "https://callback.url", []);
|
|
166
|
+
}, SmartlingException);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("throws if too many events", () => {
|
|
170
|
+
const events = new Array(1001).fill({
|
|
171
|
+
type: "project.created",
|
|
172
|
+
schemaVersion: "1.0"
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
assert.throws(() => {
|
|
176
|
+
// eslint-disable-next-line no-new
|
|
177
|
+
new CreateSubscriptionParameters("name", "https://callback.url", events);
|
|
178
|
+
}, SmartlingException);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("throws if too many headers", () => {
|
|
182
|
+
const headers = Array.from({ length: 21 }, (_, i) => ({ headerName: `h${i}`, headerValue: `v${i}` }));
|
|
183
|
+
const params = new CreateSubscriptionParameters("test", "https://callback", [{
|
|
184
|
+
type: "project.created",
|
|
185
|
+
schemaVersion: "1.0"
|
|
186
|
+
}]);
|
|
187
|
+
|
|
188
|
+
assert.throws(() => {
|
|
189
|
+
params.setRequestHeaders(headers);
|
|
190
|
+
}, SmartlingException);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("throws if too many project uids", () => {
|
|
194
|
+
const uids = Array.from({ length: 11 }, (_, i) => `project-${i}`);
|
|
195
|
+
const params = new CreateSubscriptionParameters("test", "https://callback", [{
|
|
196
|
+
type: "project.created",
|
|
197
|
+
schemaVersion: "1.0"
|
|
198
|
+
}]);
|
|
199
|
+
|
|
200
|
+
assert.throws(() => {
|
|
201
|
+
params.setProjectUids(uids);
|
|
202
|
+
}, SmartlingException);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe("updateSubscription", () => {
|
|
207
|
+
const subscriptionUid = "subscription-uid";
|
|
208
|
+
|
|
209
|
+
it("updates a subscription", async () => {
|
|
210
|
+
const event: SubscriptionEvent = {
|
|
211
|
+
type: "project.created",
|
|
212
|
+
schemaVersion: "1.0"
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const params = new UpdateSubscriptionParameters(
|
|
216
|
+
"UpdatedName",
|
|
217
|
+
"https://callback.url/updated",
|
|
218
|
+
[event],
|
|
219
|
+
true
|
|
220
|
+
)
|
|
221
|
+
.setDescription("Updated description")
|
|
222
|
+
.setRequestHeaders([{ headerName: "X-Token", headerValue: "abc" }])
|
|
223
|
+
.setProjectUids(["project-1", "project-2"]);
|
|
224
|
+
|
|
225
|
+
await webhooksApi.updateSubscription(accountUid, subscriptionUid, params);
|
|
226
|
+
|
|
227
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
228
|
+
sinon.assert.calledWithExactly(
|
|
229
|
+
webhooksApiFetchStub,
|
|
230
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}`,
|
|
231
|
+
{
|
|
232
|
+
headers: {
|
|
233
|
+
Authorization: "test_token_type test_access_token",
|
|
234
|
+
"Content-Type": "application/json",
|
|
235
|
+
"User-Agent": "test_user_agent"
|
|
236
|
+
},
|
|
237
|
+
method: "put",
|
|
238
|
+
body: JSON.stringify({
|
|
239
|
+
subscriptionName: "UpdatedName",
|
|
240
|
+
subscriptionUrl: "https://callback.url/updated",
|
|
241
|
+
events: [{
|
|
242
|
+
type: "project.created",
|
|
243
|
+
schemaVersion: "1.0"
|
|
244
|
+
}],
|
|
245
|
+
enabled: true,
|
|
246
|
+
description: "Updated description",
|
|
247
|
+
requestHeaders: [{ headerName: "X-Token", headerValue: "abc" }],
|
|
248
|
+
projectUids: ["project-1", "project-2"]
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("throws if subscription name is missing", () => {
|
|
255
|
+
assert.throws(() => {
|
|
256
|
+
// eslint-disable-next-line no-new
|
|
257
|
+
new UpdateSubscriptionParameters("", "https://callback", [{
|
|
258
|
+
type: "project.created",
|
|
259
|
+
schemaVersion: "1.0"
|
|
260
|
+
}], true);
|
|
261
|
+
}, SmartlingException);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("throws if subscription url is missing", () => {
|
|
265
|
+
assert.throws(() => {
|
|
266
|
+
// eslint-disable-next-line no-new
|
|
267
|
+
new UpdateSubscriptionParameters("name", "", [{
|
|
268
|
+
type: "project.created",
|
|
269
|
+
schemaVersion: "1.0"
|
|
270
|
+
}], true);
|
|
271
|
+
}, SmartlingException);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("throws if events are empty", () => {
|
|
275
|
+
assert.throws(() => {
|
|
276
|
+
// eslint-disable-next-line no-new
|
|
277
|
+
new UpdateSubscriptionParameters("name", "https://callback", [], true);
|
|
278
|
+
}, SmartlingException);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("throws if too many events", () => {
|
|
282
|
+
const events = new Array(1001).fill({
|
|
283
|
+
type: "project.created",
|
|
284
|
+
schemaVersion: "1.0"
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
assert.throws(() => {
|
|
288
|
+
// eslint-disable-next-line no-new
|
|
289
|
+
new UpdateSubscriptionParameters("name", "https://callback", events, true);
|
|
290
|
+
}, SmartlingException);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("throws if too many headers", () => {
|
|
294
|
+
const headers = Array.from({ length: 21 }, (_, i) => ({ headerName: `h${i}`, headerValue: `v${i}` }));
|
|
295
|
+
const params = new UpdateSubscriptionParameters("name", "https://callback", [{
|
|
296
|
+
type: "project.created",
|
|
297
|
+
schemaVersion: "1.0"
|
|
298
|
+
}], true);
|
|
299
|
+
|
|
300
|
+
assert.throws(() => {
|
|
301
|
+
params.setRequestHeaders(headers);
|
|
302
|
+
}, SmartlingException);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("throws if too many project uids", () => {
|
|
306
|
+
const uids = Array.from({ length: 11 }, (_, i) => `project-${i}`);
|
|
307
|
+
const params = new UpdateSubscriptionParameters("name", "https://callback", [{
|
|
308
|
+
type: "project.created",
|
|
309
|
+
schemaVersion: "1.0"
|
|
310
|
+
}], true);
|
|
311
|
+
|
|
312
|
+
assert.throws(() => {
|
|
313
|
+
params.setProjectUids(uids);
|
|
314
|
+
}, SmartlingException);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("deletes a subscription", async () => {
|
|
319
|
+
const subscriptionUid = "sub-123";
|
|
320
|
+
|
|
321
|
+
await webhooksApi.deleteSubscription(accountUid, subscriptionUid);
|
|
322
|
+
|
|
323
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
324
|
+
sinon.assert.calledWithExactly(
|
|
325
|
+
webhooksApiFetchStub,
|
|
326
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}`,
|
|
327
|
+
{
|
|
328
|
+
headers: {
|
|
329
|
+
Authorization: "test_token_type test_access_token",
|
|
330
|
+
"Content-Type": "application/json",
|
|
331
|
+
"User-Agent": "test_user_agent"
|
|
332
|
+
},
|
|
333
|
+
method: "delete"
|
|
334
|
+
}
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("enables a subscription", async () => {
|
|
339
|
+
const subscriptionUid = "sub-456";
|
|
340
|
+
|
|
341
|
+
await webhooksApi.enableSubscription(accountUid, subscriptionUid);
|
|
342
|
+
|
|
343
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
344
|
+
sinon.assert.calledWithExactly(
|
|
345
|
+
webhooksApiFetchStub,
|
|
346
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/enable`,
|
|
347
|
+
{
|
|
348
|
+
headers: {
|
|
349
|
+
Authorization: "test_token_type test_access_token",
|
|
350
|
+
"Content-Type": "application/json",
|
|
351
|
+
"User-Agent": "test_user_agent"
|
|
352
|
+
},
|
|
353
|
+
method: "post"
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("disables a subscription", async () => {
|
|
359
|
+
const subscriptionUid = "sub-789";
|
|
360
|
+
|
|
361
|
+
await webhooksApi.disableSubscription(accountUid, subscriptionUid);
|
|
362
|
+
|
|
363
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
364
|
+
sinon.assert.calledWithExactly(
|
|
365
|
+
webhooksApiFetchStub,
|
|
366
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/disable`,
|
|
367
|
+
{
|
|
368
|
+
headers: {
|
|
369
|
+
Authorization: "test_token_type test_access_token",
|
|
370
|
+
"Content-Type": "application/json",
|
|
371
|
+
"User-Agent": "test_user_agent"
|
|
372
|
+
},
|
|
373
|
+
method: "post"
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("tests a subscription", async () => {
|
|
379
|
+
const subscriptionUid = "sub-999";
|
|
380
|
+
|
|
381
|
+
await webhooksApi.testSubscription(accountUid, subscriptionUid);
|
|
382
|
+
|
|
383
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
384
|
+
sinon.assert.calledWithExactly(
|
|
385
|
+
webhooksApiFetchStub,
|
|
386
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/test`,
|
|
387
|
+
{
|
|
388
|
+
headers: {
|
|
389
|
+
Authorization: "test_token_type test_access_token",
|
|
390
|
+
"Content-Type": "application/json",
|
|
391
|
+
"User-Agent": "test_user_agent"
|
|
392
|
+
},
|
|
393
|
+
method: "post"
|
|
394
|
+
}
|
|
395
|
+
);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it("gets subscription secret", async () => {
|
|
399
|
+
const subscriptionUid = "sub-secret";
|
|
400
|
+
|
|
401
|
+
await webhooksApi.getSubscriptionSecret(accountUid, subscriptionUid);
|
|
402
|
+
|
|
403
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
404
|
+
sinon.assert.calledWithExactly(
|
|
405
|
+
webhooksApiFetchStub,
|
|
406
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/secret`,
|
|
407
|
+
{
|
|
408
|
+
headers: {
|
|
409
|
+
Authorization: "test_token_type test_access_token",
|
|
410
|
+
"Content-Type": "application/json",
|
|
411
|
+
"User-Agent": "test_user_agent"
|
|
412
|
+
},
|
|
413
|
+
method: "get"
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it("updates subscription secret", async () => {
|
|
419
|
+
const subscriptionUid = "sub-secret-update";
|
|
420
|
+
|
|
421
|
+
const params = new UpdateSubscriptionSecretParameters("newSecret");
|
|
422
|
+
|
|
423
|
+
await webhooksApi.updateSubscriptionSecret(accountUid, subscriptionUid, params);
|
|
424
|
+
|
|
425
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
426
|
+
sinon.assert.calledWithExactly(
|
|
427
|
+
webhooksApiFetchStub,
|
|
428
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/secret`,
|
|
429
|
+
{
|
|
430
|
+
headers: {
|
|
431
|
+
Authorization: "test_token_type test_access_token",
|
|
432
|
+
"Content-Type": "application/json",
|
|
433
|
+
"User-Agent": "test_user_agent"
|
|
434
|
+
},
|
|
435
|
+
method: "put",
|
|
436
|
+
body: JSON.stringify({
|
|
437
|
+
payloadSecret: "newSecret"
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it("gets subscription statistics", async () => {
|
|
444
|
+
const subscriptionUid = "sub-stats";
|
|
445
|
+
|
|
446
|
+
await webhooksApi.getSubscriptionStatistics(accountUid, subscriptionUid);
|
|
447
|
+
|
|
448
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
449
|
+
sinon.assert.calledWithExactly(
|
|
450
|
+
webhooksApiFetchStub,
|
|
451
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/statistics`,
|
|
452
|
+
{
|
|
453
|
+
headers: {
|
|
454
|
+
Authorization: "test_token_type test_access_token",
|
|
455
|
+
"Content-Type": "application/json",
|
|
456
|
+
"User-Agent": "test_user_agent"
|
|
457
|
+
},
|
|
458
|
+
method: "get"
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it("gets available event types", async () => {
|
|
464
|
+
await webhooksApi.getAvailableEventTypes(accountUid);
|
|
465
|
+
|
|
466
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
467
|
+
sinon.assert.calledWithExactly(
|
|
468
|
+
webhooksApiFetchStub,
|
|
469
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/available-event-types`,
|
|
470
|
+
{
|
|
471
|
+
headers: {
|
|
472
|
+
Authorization: "test_token_type test_access_token",
|
|
473
|
+
"Content-Type": "application/json",
|
|
474
|
+
"User-Agent": "test_user_agent"
|
|
475
|
+
},
|
|
476
|
+
method: "get"
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
describe("getSubscriptionEvents", () => {
|
|
482
|
+
it("gets a subscription events when no parameters", async () => {
|
|
483
|
+
const subscriptionUid = "subscriptionUid";
|
|
484
|
+
await webhooksApi.getSubscriptionEvents(accountUid, subscriptionUid);
|
|
485
|
+
|
|
486
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
487
|
+
sinon.assert.calledWithExactly(
|
|
488
|
+
webhooksApiFetchStub,
|
|
489
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/events`,
|
|
490
|
+
{
|
|
491
|
+
headers: {
|
|
492
|
+
Authorization: "test_token_type test_access_token",
|
|
493
|
+
"Content-Type": "application/json",
|
|
494
|
+
"User-Agent": "test_user_agent"
|
|
495
|
+
},
|
|
496
|
+
method: "get"
|
|
497
|
+
}
|
|
498
|
+
);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
it("gets a subscription events when empty parameters", async () => {
|
|
502
|
+
const subscriptionUid = "subscriptionUid";
|
|
503
|
+
await webhooksApi.getSubscriptionEvents(
|
|
504
|
+
accountUid, subscriptionUid, new GetSubscriptionEventsParameters());
|
|
505
|
+
|
|
506
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
507
|
+
sinon.assert.calledWithExactly(
|
|
508
|
+
webhooksApiFetchStub,
|
|
509
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/events?`,
|
|
510
|
+
{
|
|
511
|
+
headers: {
|
|
512
|
+
Authorization: "test_token_type test_access_token",
|
|
513
|
+
"Content-Type": "application/json",
|
|
514
|
+
"User-Agent": "test_user_agent"
|
|
515
|
+
},
|
|
516
|
+
method: "get"
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it("gets a subscription events when parameter specified", async () => {
|
|
522
|
+
const subscriptionUid = "subscriptionUid";
|
|
523
|
+
const date = new Date();
|
|
524
|
+
const dateString = encodeURIComponent(`${date.toISOString().split(".")[0]}Z`);
|
|
525
|
+
const params = new GetSubscriptionEventsParameters()
|
|
526
|
+
.setLimit(10)
|
|
527
|
+
.setScrollId("scrollId123")
|
|
528
|
+
.setAttemptStatus(SubscriptionEventAttemptStatus.SUCCESS)
|
|
529
|
+
.setCreatedDateBefore(date)
|
|
530
|
+
.setCreatedDateAfter(date)
|
|
531
|
+
.setEventTypes(["event1", "event2"]);
|
|
532
|
+
await webhooksApi.getSubscriptionEvents(accountUid, subscriptionUid, params);
|
|
533
|
+
|
|
534
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
535
|
+
sinon.assert.calledWithExactly(
|
|
536
|
+
webhooksApiFetchStub,
|
|
537
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/events?limit=10&scrollId=scrollId123&attemptStatus=SUCCESS&createdDateBefore=${dateString}&createdDateAfter=${dateString}&eventTypes=event1&eventTypes=event2`,
|
|
538
|
+
{
|
|
539
|
+
headers: {
|
|
540
|
+
Authorization: "test_token_type test_access_token",
|
|
541
|
+
"Content-Type": "application/json",
|
|
542
|
+
"User-Agent": "test_user_agent"
|
|
543
|
+
},
|
|
544
|
+
method: "get"
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("gets a subscription event", async () => {
|
|
551
|
+
const subscriptionUid = "subscriptionUid";
|
|
552
|
+
const eventId = "eventId";
|
|
553
|
+
await webhooksApi.getSubscriptionEvent(accountUid, subscriptionUid, eventId);
|
|
554
|
+
|
|
555
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
556
|
+
sinon.assert.calledWithExactly(
|
|
557
|
+
webhooksApiFetchStub,
|
|
558
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/events/${eventId}`,
|
|
559
|
+
{
|
|
560
|
+
headers: {
|
|
561
|
+
Authorization: "test_token_type test_access_token",
|
|
562
|
+
"Content-Type": "application/json",
|
|
563
|
+
"User-Agent": "test_user_agent"
|
|
564
|
+
},
|
|
565
|
+
method: "get"
|
|
566
|
+
}
|
|
567
|
+
);
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it("gets a subscription event attempts", async () => {
|
|
571
|
+
const subscriptionUid = "subscriptionUid";
|
|
572
|
+
const eventId = "eventId";
|
|
573
|
+
await webhooksApi.getSubscriptionEventAttempts(accountUid, subscriptionUid, eventId);
|
|
574
|
+
|
|
575
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
576
|
+
sinon.assert.calledWithExactly(
|
|
577
|
+
webhooksApiFetchStub,
|
|
578
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/events/${eventId}/attempts`,
|
|
579
|
+
{
|
|
580
|
+
headers: {
|
|
581
|
+
Authorization: "test_token_type test_access_token",
|
|
582
|
+
"Content-Type": "application/json",
|
|
583
|
+
"User-Agent": "test_user_agent"
|
|
584
|
+
},
|
|
585
|
+
method: "get"
|
|
586
|
+
}
|
|
587
|
+
);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it("sends a subscription", async () => {
|
|
591
|
+
const subscriptionUid = "sub-999";
|
|
592
|
+
const eventId = "event-123";
|
|
593
|
+
|
|
594
|
+
await webhooksApi.sendSubscriptionEvent(accountUid, subscriptionUid, eventId);
|
|
595
|
+
|
|
596
|
+
sinon.assert.calledOnce(webhooksApiFetchStub);
|
|
597
|
+
sinon.assert.calledWithExactly(
|
|
598
|
+
webhooksApiFetchStub,
|
|
599
|
+
`https://test.com/webhooks-api/v2/accounts/${accountUid}/subscriptions/${subscriptionUid}/events/${eventId}/send`,
|
|
600
|
+
{
|
|
601
|
+
headers: {
|
|
602
|
+
Authorization: "test_token_type test_access_token",
|
|
603
|
+
"Content-Type": "application/json",
|
|
604
|
+
"User-Agent": "test_user_agent"
|
|
605
|
+
},
|
|
606
|
+
method: "post"
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
});
|
|
610
|
+
});
|