@superoffice/webapi 11.7.727 → 11.8.788
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/LICENSE.md +15 -15
- package/README.md +184 -184
- package/__tests__/Appointment63-notz.json +1925 -1925
- package/__tests__/Appointment63-utctz.json +1925 -1925
- package/__tests__/Appointment63.json +1925 -1925
- package/__tests__/AppointmentTzTest.ts +115 -115
- package/__tests__/AxiosNockTest.ts +28 -28
- package/__tests__/ContactDefault.json +699 -699
- package/__tests__/ContactEntity.json +272 -272
- package/__tests__/ContactRestTest.ts +144 -144
- package/__tests__/ContactTest.ts +395 -395
- package/__tests__/ConvertersTest.ts +97 -97
- package/__tests__/DocumentTest.ts +101 -101
- package/__tests__/Person210-notz.json +1932 -1932
- package/__tests__/Person210-utctz.json +1932 -1932
- package/__tests__/Person210.json +1932 -1932
- package/__tests__/PersonImageData.nock +22 -22
- package/__tests__/PersonTest.ts +41 -41
- package/__tests__/PersonTzTest.ts +113 -113
- package/__tests__/RecurrenceInfo.json +55 -55
- package/__tests__/ResponseCallbackTest.ts +23 -23
- package/__tests__/TableRights.json +441 -441
- package/__tests__/WebapiTest.ts +264 -264
- package/__tests__/Webhook.json +16 -16
- package/__tests__/WebhookTest.ts +209 -209
- package/dist/cjs/Carriers.d.ts +367 -4
- package/dist/cjs/Carriers.d.ts.map +1 -1
- package/dist/cjs/Converters.d.ts +9 -0
- package/dist/cjs/Converters.d.ts.map +1 -1
- package/dist/cjs/Converters.js +185 -17
- package/dist/cjs/Converters.js.map +1 -1
- package/dist/cjs/DiagnosticsAgent.d.ts +38 -0
- package/dist/cjs/DiagnosticsAgent.d.ts.map +1 -1
- package/dist/cjs/DiagnosticsAgent.js +91 -0
- package/dist/cjs/DiagnosticsAgent.js.map +1 -1
- package/dist/cjs/Enums.d.ts +18 -0
- package/dist/cjs/Enums.d.ts.map +1 -1
- package/dist/cjs/Enums.js +20 -1
- package/dist/cjs/Enums.js.map +1 -1
- package/dist/cjs/ListAgent.d.ts +71 -6
- package/dist/cjs/ListAgent.d.ts.map +1 -1
- package/dist/cjs/ListAgent.js +157 -0
- package/dist/cjs/ListAgent.js.map +1 -1
- package/dist/cjs/TicketAgent.d.ts +23 -0
- package/dist/cjs/TicketAgent.d.ts.map +1 -1
- package/dist/cjs/TicketAgent.js +65 -0
- package/dist/cjs/TicketAgent.js.map +1 -1
- package/dist/esm/Carriers.d.ts +367 -4
- package/dist/esm/Carriers.d.ts.map +1 -1
- package/dist/esm/Converters.d.ts +9 -0
- package/dist/esm/Converters.d.ts.map +1 -1
- package/dist/esm/Converters.js +159 -0
- package/dist/esm/Converters.js.map +1 -1
- package/dist/esm/DiagnosticsAgent.d.ts +38 -0
- package/dist/esm/DiagnosticsAgent.d.ts.map +1 -1
- package/dist/esm/DiagnosticsAgent.js +91 -0
- package/dist/esm/DiagnosticsAgent.js.map +1 -1
- package/dist/esm/Enums.d.ts +18 -0
- package/dist/esm/Enums.d.ts.map +1 -1
- package/dist/esm/Enums.js +19 -0
- package/dist/esm/Enums.js.map +1 -1
- package/dist/esm/ListAgent.d.ts +71 -6
- package/dist/esm/ListAgent.d.ts.map +1 -1
- package/dist/esm/ListAgent.js +157 -0
- package/dist/esm/ListAgent.js.map +1 -1
- package/dist/esm/TicketAgent.d.ts +23 -0
- package/dist/esm/TicketAgent.d.ts.map +1 -1
- package/dist/esm/TicketAgent.js +65 -0
- package/dist/esm/TicketAgent.js.map +1 -1
- package/examples-js/hello.js +12 -12
- package/examples-ts/hello.ts +8 -8
- package/package.json +93 -93
- package/scripts/postbuild.js +22 -22
- package/scripts/setVersion.js +44 -44
- package/src/AIAgent.ts +1992 -1992
- package/src/AppointmentAgent.ts +6263 -6263
- package/src/AppointmentRestApi.ts +225 -225
- package/src/ArchiveAgent.ts +1950 -1950
- package/src/AssociateAgent.ts +422 -422
- package/src/AxiosCacheHandler.ts +74 -74
- package/src/BLOBAgent.ts +2100 -2100
- package/src/Base64.ts +285 -285
- package/src/BatchAgent.ts +910 -910
- package/src/BulkUpdateAgent.ts +504 -504
- package/src/CRMScriptAgent.ts +1390 -1390
- package/src/Carriers.ts +52750 -52274
- package/src/ChatAgent.ts +1422 -1422
- package/src/ConfigurationAgent.ts +2228 -2228
- package/src/ContactAgent.ts +1756 -1756
- package/src/ContactRestApi.ts +237 -237
- package/src/Converters.ts +23271 -23090
- package/src/CustomerServiceAgent.ts +1799 -1799
- package/src/DashAgent.ts +1674 -1674
- package/src/DatabaseAgent.ts +120 -120
- package/src/DatabaseTableAgent.ts +534 -534
- package/src/Day_js.ts +41 -41
- package/src/DiagnosticsAgent.ts +1384 -1240
- package/src/DocumentAgent.ts +5079 -5079
- package/src/DocumentMigrationAgent.ts +524 -524
- package/src/DocumentRestApi.ts +259 -259
- package/src/EMailAgent.ts +5328 -5328
- package/src/Enums.ts +6936 -6916
- package/src/ErpSyncAgent.ts +2658 -2658
- package/src/FavouriteAgent.ts +720 -720
- package/src/FindAgent.ts +2330 -2330
- package/src/ForeignSystemAgent.ts +1710 -1710
- package/src/FreeTextAgent.ts +372 -372
- package/src/ImportAgent.ts +304 -304
- package/src/LicenseAgent.ts +1230 -1230
- package/src/ListAgent.ts +11451 -11237
- package/src/MDOAgent.ts +748 -748
- package/src/MarketingAgent.ts +890 -890
- package/src/MessagingAgent.ts +384 -384
- package/src/NavigatorAgent.ts +140 -140
- package/src/NumberAllocationAgent.ts +296 -296
- package/src/PersonAgent.ts +3287 -3287
- package/src/PersonRestApi.ts +241 -241
- package/src/PhoneListAgent.ts +458 -458
- package/src/PocketAgent.ts +780 -780
- package/src/PreferenceAgent.ts +1900 -1900
- package/src/PreviewsAgent.ts +116 -116
- package/src/ProjectAgent.ts +2391 -2391
- package/src/ProjectRestApi.ts +239 -239
- package/src/QuoteAgent.ts +5159 -5159
- package/src/RelationAgent.ts +220 -220
- package/src/ReportAgent.ts +154 -154
- package/src/ResourceAgent.ts +358 -358
- package/src/SaintAgent.ts +601 -601
- package/src/SaleAgent.ts +2034 -2034
- package/src/SaleRestApi.ts +233 -233
- package/src/SelectionAgent.ts +3195 -3195
- package/src/SentryAgent.ts +462 -462
- package/src/SoApiConstants.ts +8 -8
- package/src/TargetsAgent.ts +1104 -1104
- package/src/TicketAgent.ts +3708 -3638
- package/src/TimeZoneAgent.ts +528 -528
- package/src/TooltipsAgent.ts +116 -116
- package/src/UserAgent.ts +4856 -4856
- package/src/UserDefinedFieldInfoAgent.ts +1764 -1764
- package/src/ViewStateAgent.ts +858 -858
- package/src/WebApi.ts +872 -872
- package/src/WebApiBase.ts +565 -565
- package/src/WebhookAgent.ts +388 -388
- package/src/WorkflowAgent.ts +1338 -1338
- package/tsconfig.esm.json +8 -8
- package/tsconfig.jest.json +8 -8
- package/tsconfig.json +34 -34
package/__tests__/WebhookTest.ts
CHANGED
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
import * as assert from "assert";
|
|
2
|
-
import axios, { AxiosRequestConfig } from "axios";
|
|
3
|
-
import nock from "nock";
|
|
4
|
-
import { WebhookAgent } from "../src/WebhookAgent";
|
|
5
|
-
import { WebApiOptions, ResourceParsing } from "../src/WebApiBase";
|
|
6
|
-
import { WebhookState } from "../src/Enums";
|
|
7
|
-
import { WebApi } from "../src/WebApi";
|
|
8
|
-
import { Webhook } from "../src/Carriers";
|
|
9
|
-
import { HEADER_NAME_ACCEPT_LANGUAGE, HEADER_NAME_LANGUAGE } from "../src/SoApiConstants";
|
|
10
|
-
|
|
11
|
-
const host: string = "http://localhost/";
|
|
12
|
-
const defaultHook = {
|
|
13
|
-
WebhookId: 0,
|
|
14
|
-
Name: null,
|
|
15
|
-
Events: ["contact.created", "contact.deleted"],
|
|
16
|
-
TargetUrl: null,
|
|
17
|
-
Secret: null,
|
|
18
|
-
State: "Active",
|
|
19
|
-
Type: "webhook",
|
|
20
|
-
Headers: null,
|
|
21
|
-
Properties: null,
|
|
22
|
-
Registered: "0001-01-01T00:00:00",
|
|
23
|
-
RegisteredAssociate: null,
|
|
24
|
-
Updated: "0001-01-01T00:00:00",
|
|
25
|
-
UpdatedAssociate: null
|
|
26
|
-
};
|
|
27
|
-
const aHook = require("./Webhook.json");
|
|
28
|
-
|
|
29
|
-
axios.defaults.baseURL = host;
|
|
30
|
-
|
|
31
|
-
describe("WebAPI Webhook tests", () => {
|
|
32
|
-
it("Can create a default hook", done => {
|
|
33
|
-
let scope = nock(host)
|
|
34
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
35
|
-
.reply(200, defaultHook);
|
|
36
|
-
|
|
37
|
-
let agent = new WebhookAgent(host);
|
|
38
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
39
|
-
assert.equal(response.webhookId, 0);
|
|
40
|
-
assert.equal(response.name, null);
|
|
41
|
-
assert.equal(response.state, WebhookState.Active);
|
|
42
|
-
assert.equal(response.type, "webhook");
|
|
43
|
-
done();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("Can create a default hook using global defaults", done => {
|
|
48
|
-
let scope = nock(host)
|
|
49
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
50
|
-
.reply(200, defaultHook);
|
|
51
|
-
|
|
52
|
-
let agent1 = new WebhookAgent(host);
|
|
53
|
-
let agent2 = new WebhookAgent();
|
|
54
|
-
agent2.createDefaultWebhookAsync().then(response => {
|
|
55
|
-
assert.equal(response.webhookId, 0);
|
|
56
|
-
assert.equal(response.name, null);
|
|
57
|
-
assert.equal(response.state, WebhookState.Active);
|
|
58
|
-
assert.equal(response.type, "webhook");
|
|
59
|
-
done();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("Cannot create a default hook with no global defaults", done => {
|
|
64
|
-
WebApi.configure(""); // Reset global config
|
|
65
|
-
assert.throws(() => {
|
|
66
|
-
let agent2 = new WebhookAgent();
|
|
67
|
-
});
|
|
68
|
-
done();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("Can create a default hook using an options object", done => {
|
|
72
|
-
let scope = nock(host)
|
|
73
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
74
|
-
.reply(200, defaultHook);
|
|
75
|
-
|
|
76
|
-
let opts: WebApiOptions = { baseUrl: host };
|
|
77
|
-
let agent = new WebhookAgent(opts);
|
|
78
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
79
|
-
assert.equal(response.webhookId, 0);
|
|
80
|
-
assert.equal(response.name, null);
|
|
81
|
-
assert.equal(response.state, WebhookState.Active);
|
|
82
|
-
assert.equal(response.type, "webhook");
|
|
83
|
-
|
|
84
|
-
done();
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("Can create a default hook using an axios config object", done => {
|
|
89
|
-
let scope = nock(host, { badheaders: [HEADER_NAME_LANGUAGE] })
|
|
90
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
91
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
92
|
-
.reply(200, defaultHook);
|
|
93
|
-
|
|
94
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
95
|
-
let agent = new WebhookAgent(host, config);
|
|
96
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
97
|
-
assert.equal(response.webhookId, 0);
|
|
98
|
-
assert.equal(response.name, null);
|
|
99
|
-
assert.equal(response.state, WebhookState.Active);
|
|
100
|
-
assert.equal(response.type, "webhook");
|
|
101
|
-
done();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("can create a default hook without parsing languages", done => {
|
|
106
|
-
let scope = nock(host)
|
|
107
|
-
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
108
|
-
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
109
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
110
|
-
.reply(200, defaultHook);
|
|
111
|
-
|
|
112
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
113
|
-
let agent = new WebhookAgent(host, ResourceParsing.DoNotParse);
|
|
114
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
115
|
-
assert.equal(response.webhookId, 0);
|
|
116
|
-
assert.equal(response.name, null);
|
|
117
|
-
assert.equal(response.state, WebhookState.Active);
|
|
118
|
-
assert.equal(response.type, "webhook");
|
|
119
|
-
done();
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("can create a default hook without parsing languages and a password", done => {
|
|
124
|
-
let scope = nock(host)
|
|
125
|
-
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
126
|
-
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
127
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
128
|
-
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
129
|
-
.reply(200, defaultHook);
|
|
130
|
-
|
|
131
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
132
|
-
let agent = new WebhookAgent(host, config, ResourceParsing.DoNotParse);
|
|
133
|
-
agent.createDefaultWebhookAsync().then(response => {
|
|
134
|
-
assert.equal(response.webhookId, 0);
|
|
135
|
-
assert.equal(response.name, null);
|
|
136
|
-
assert.equal(response.state, WebhookState.Active);
|
|
137
|
-
assert.equal(response.type, "webhook");
|
|
138
|
-
done();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("create a new webhook will reject a non-https target URL", done => {
|
|
143
|
-
let webhook: Webhook = {
|
|
144
|
-
name: "My hook",
|
|
145
|
-
events: ["contact.created"],
|
|
146
|
-
type: "webhook",
|
|
147
|
-
targetUrl: "https://www.example.com"
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
let scope = nock(host)
|
|
151
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
152
|
-
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
153
|
-
.reply(400, {
|
|
154
|
-
Error: true,
|
|
155
|
-
ErrorType: "ArgumentException",
|
|
156
|
-
Message: "Webhook TargetUrl must be secure: 'HTTPS:' not found in http://www.example.com",
|
|
157
|
-
ErrorSource: "SuperOffice.Services.Implementation"
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
161
|
-
let agent = new WebhookAgent(host, config);
|
|
162
|
-
agent.saveWebhookAsync(webhook).catch(error => {
|
|
163
|
-
assert.equal(error.response.status, 400);
|
|
164
|
-
assert.equal(error.response.data.ErrorType, "ArgumentException");
|
|
165
|
-
done();
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("create a new webhook will accept a https target URL", done => {
|
|
170
|
-
let webhook: Webhook = {
|
|
171
|
-
name: "My hook",
|
|
172
|
-
events: ["contact.created"],
|
|
173
|
-
type: "webhook",
|
|
174
|
-
targetUrl: "https://www.example.com"
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
let scope = nock(host)
|
|
178
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
179
|
-
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
180
|
-
.reply(200, aHook);
|
|
181
|
-
|
|
182
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
183
|
-
let agent = new WebhookAgent(host, config);
|
|
184
|
-
agent.saveWebhookAsync(webhook).then(hook => {
|
|
185
|
-
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
186
|
-
assert.equal(hook.type, "webhook");
|
|
187
|
-
assert.equal(hook.state, WebhookState.Active);
|
|
188
|
-
assert.notEqual(hook.webhookId, 0);
|
|
189
|
-
done();
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("create a new webhook will accept a https target URL", done => {
|
|
194
|
-
let scope = nock(host)
|
|
195
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
196
|
-
.post("/api/v1/Agents/Webhook/GetWebhook?webhookId=1")
|
|
197
|
-
.reply(200, aHook);
|
|
198
|
-
|
|
199
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
200
|
-
let agent = new WebhookAgent(host, config);
|
|
201
|
-
agent.getWebhookAsync(1).then(hook => {
|
|
202
|
-
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
203
|
-
assert.equal(hook.type, "webhook");
|
|
204
|
-
assert.equal(hook.state, WebhookState.Active);
|
|
205
|
-
assert.notEqual(hook.webhookId, 0);
|
|
206
|
-
done();
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
});
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import axios, { AxiosRequestConfig } from "axios";
|
|
3
|
+
import nock from "nock";
|
|
4
|
+
import { WebhookAgent } from "../src/WebhookAgent";
|
|
5
|
+
import { WebApiOptions, ResourceParsing } from "../src/WebApiBase";
|
|
6
|
+
import { WebhookState } from "../src/Enums";
|
|
7
|
+
import { WebApi } from "../src/WebApi";
|
|
8
|
+
import { Webhook } from "../src/Carriers";
|
|
9
|
+
import { HEADER_NAME_ACCEPT_LANGUAGE, HEADER_NAME_LANGUAGE } from "../src/SoApiConstants";
|
|
10
|
+
|
|
11
|
+
const host: string = "http://localhost/";
|
|
12
|
+
const defaultHook = {
|
|
13
|
+
WebhookId: 0,
|
|
14
|
+
Name: null,
|
|
15
|
+
Events: ["contact.created", "contact.deleted"],
|
|
16
|
+
TargetUrl: null,
|
|
17
|
+
Secret: null,
|
|
18
|
+
State: "Active",
|
|
19
|
+
Type: "webhook",
|
|
20
|
+
Headers: null,
|
|
21
|
+
Properties: null,
|
|
22
|
+
Registered: "0001-01-01T00:00:00",
|
|
23
|
+
RegisteredAssociate: null,
|
|
24
|
+
Updated: "0001-01-01T00:00:00",
|
|
25
|
+
UpdatedAssociate: null
|
|
26
|
+
};
|
|
27
|
+
const aHook = require("./Webhook.json");
|
|
28
|
+
|
|
29
|
+
axios.defaults.baseURL = host;
|
|
30
|
+
|
|
31
|
+
describe("WebAPI Webhook tests", () => {
|
|
32
|
+
it("Can create a default hook", done => {
|
|
33
|
+
let scope = nock(host)
|
|
34
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
35
|
+
.reply(200, defaultHook);
|
|
36
|
+
|
|
37
|
+
let agent = new WebhookAgent(host);
|
|
38
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
39
|
+
assert.equal(response.webhookId, 0);
|
|
40
|
+
assert.equal(response.name, null);
|
|
41
|
+
assert.equal(response.state, WebhookState.Active);
|
|
42
|
+
assert.equal(response.type, "webhook");
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("Can create a default hook using global defaults", done => {
|
|
48
|
+
let scope = nock(host)
|
|
49
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
50
|
+
.reply(200, defaultHook);
|
|
51
|
+
|
|
52
|
+
let agent1 = new WebhookAgent(host);
|
|
53
|
+
let agent2 = new WebhookAgent();
|
|
54
|
+
agent2.createDefaultWebhookAsync().then(response => {
|
|
55
|
+
assert.equal(response.webhookId, 0);
|
|
56
|
+
assert.equal(response.name, null);
|
|
57
|
+
assert.equal(response.state, WebhookState.Active);
|
|
58
|
+
assert.equal(response.type, "webhook");
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("Cannot create a default hook with no global defaults", done => {
|
|
64
|
+
WebApi.configure(""); // Reset global config
|
|
65
|
+
assert.throws(() => {
|
|
66
|
+
let agent2 = new WebhookAgent();
|
|
67
|
+
});
|
|
68
|
+
done();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("Can create a default hook using an options object", done => {
|
|
72
|
+
let scope = nock(host)
|
|
73
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
74
|
+
.reply(200, defaultHook);
|
|
75
|
+
|
|
76
|
+
let opts: WebApiOptions = { baseUrl: host };
|
|
77
|
+
let agent = new WebhookAgent(opts);
|
|
78
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
79
|
+
assert.equal(response.webhookId, 0);
|
|
80
|
+
assert.equal(response.name, null);
|
|
81
|
+
assert.equal(response.state, WebhookState.Active);
|
|
82
|
+
assert.equal(response.type, "webhook");
|
|
83
|
+
|
|
84
|
+
done();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("Can create a default hook using an axios config object", done => {
|
|
89
|
+
let scope = nock(host, { badheaders: [HEADER_NAME_LANGUAGE] })
|
|
90
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
91
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
92
|
+
.reply(200, defaultHook);
|
|
93
|
+
|
|
94
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
95
|
+
let agent = new WebhookAgent(host, config);
|
|
96
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
97
|
+
assert.equal(response.webhookId, 0);
|
|
98
|
+
assert.equal(response.name, null);
|
|
99
|
+
assert.equal(response.state, WebhookState.Active);
|
|
100
|
+
assert.equal(response.type, "webhook");
|
|
101
|
+
done();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("can create a default hook without parsing languages", done => {
|
|
106
|
+
let scope = nock(host)
|
|
107
|
+
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
108
|
+
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
109
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
110
|
+
.reply(200, defaultHook);
|
|
111
|
+
|
|
112
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
113
|
+
let agent = new WebhookAgent(host, ResourceParsing.DoNotParse);
|
|
114
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
115
|
+
assert.equal(response.webhookId, 0);
|
|
116
|
+
assert.equal(response.name, null);
|
|
117
|
+
assert.equal(response.state, WebhookState.Active);
|
|
118
|
+
assert.equal(response.type, "webhook");
|
|
119
|
+
done();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("can create a default hook without parsing languages and a password", done => {
|
|
124
|
+
let scope = nock(host)
|
|
125
|
+
.matchHeader(HEADER_NAME_ACCEPT_LANGUAGE, "")
|
|
126
|
+
.matchHeader(HEADER_NAME_LANGUAGE, "")
|
|
127
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
128
|
+
.post("/api/v1/Agents/Webhook/CreateDefaultWebhook")
|
|
129
|
+
.reply(200, defaultHook);
|
|
130
|
+
|
|
131
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
132
|
+
let agent = new WebhookAgent(host, config, ResourceParsing.DoNotParse);
|
|
133
|
+
agent.createDefaultWebhookAsync().then(response => {
|
|
134
|
+
assert.equal(response.webhookId, 0);
|
|
135
|
+
assert.equal(response.name, null);
|
|
136
|
+
assert.equal(response.state, WebhookState.Active);
|
|
137
|
+
assert.equal(response.type, "webhook");
|
|
138
|
+
done();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("create a new webhook will reject a non-https target URL", done => {
|
|
143
|
+
let webhook: Webhook = {
|
|
144
|
+
name: "My hook",
|
|
145
|
+
events: ["contact.created"],
|
|
146
|
+
type: "webhook",
|
|
147
|
+
targetUrl: "https://www.example.com"
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
let scope = nock(host)
|
|
151
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
152
|
+
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
153
|
+
.reply(400, {
|
|
154
|
+
Error: true,
|
|
155
|
+
ErrorType: "ArgumentException",
|
|
156
|
+
Message: "Webhook TargetUrl must be secure: 'HTTPS:' not found in http://www.example.com",
|
|
157
|
+
ErrorSource: "SuperOffice.Services.Implementation"
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
161
|
+
let agent = new WebhookAgent(host, config);
|
|
162
|
+
agent.saveWebhookAsync(webhook).catch(error => {
|
|
163
|
+
assert.equal(error.response.status, 400);
|
|
164
|
+
assert.equal(error.response.data.ErrorType, "ArgumentException");
|
|
165
|
+
done();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("create a new webhook will accept a https target URL", done => {
|
|
170
|
+
let webhook: Webhook = {
|
|
171
|
+
name: "My hook",
|
|
172
|
+
events: ["contact.created"],
|
|
173
|
+
type: "webhook",
|
|
174
|
+
targetUrl: "https://www.example.com"
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
let scope = nock(host)
|
|
178
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
179
|
+
.post("/api/v1/Agents/Webhook/SaveWebhook")
|
|
180
|
+
.reply(200, aHook);
|
|
181
|
+
|
|
182
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
183
|
+
let agent = new WebhookAgent(host, config);
|
|
184
|
+
agent.saveWebhookAsync(webhook).then(hook => {
|
|
185
|
+
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
186
|
+
assert.equal(hook.type, "webhook");
|
|
187
|
+
assert.equal(hook.state, WebhookState.Active);
|
|
188
|
+
assert.notEqual(hook.webhookId, 0);
|
|
189
|
+
done();
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("create a new webhook will accept a https target URL", done => {
|
|
194
|
+
let scope = nock(host)
|
|
195
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
196
|
+
.post("/api/v1/Agents/Webhook/GetWebhook?webhookId=1")
|
|
197
|
+
.reply(200, aHook);
|
|
198
|
+
|
|
199
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
200
|
+
let agent = new WebhookAgent(host, config);
|
|
201
|
+
agent.getWebhookAsync(1).then(hook => {
|
|
202
|
+
assert.equal(hook.targetUrl, "https://www.example.com");
|
|
203
|
+
assert.equal(hook.type, "webhook");
|
|
204
|
+
assert.equal(hook.state, WebhookState.Active);
|
|
205
|
+
assert.notEqual(hook.webhookId, 0);
|
|
206
|
+
done();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|