@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__/ContactTest.ts
CHANGED
|
@@ -1,395 +1,395 @@
|
|
|
1
|
-
import * as assert from "assert";
|
|
2
|
-
import axios, { AxiosRequestConfig } from "axios";
|
|
3
|
-
import nock from "nock";
|
|
4
|
-
import { WebApiStatus } from "../src/WebApiBase";
|
|
5
|
-
import { ContactEntity } from "../src/Carriers";
|
|
6
|
-
import { ContactAgent } from "../src/ContactAgent";
|
|
7
|
-
import { WebApiRequestOptions } from "../src/WebApi";
|
|
8
|
-
import { HEADER_NAME_TIMEZONE } from "../src/SoApiConstants";
|
|
9
|
-
|
|
10
|
-
const host: string = "http://localhost/";
|
|
11
|
-
const defaultContact = require("./ContactDefault.json");
|
|
12
|
-
const aContact = require("./ContactEntity.json");
|
|
13
|
-
|
|
14
|
-
axios.defaults.baseURL = host;
|
|
15
|
-
|
|
16
|
-
describe("WebAPI Contact tests", () => {
|
|
17
|
-
it("Can create a default contact", done => {
|
|
18
|
-
let scope = nock(host)
|
|
19
|
-
.post("/api/v1/Agents/Contact/CreateDefaultContactEntity")
|
|
20
|
-
.reply(200, defaultContact);
|
|
21
|
-
|
|
22
|
-
let agent = new ContactAgent(host);
|
|
23
|
-
agent.createDefaultContactEntityAsync().then(response => {
|
|
24
|
-
assert.equal(response.contactId, 0);
|
|
25
|
-
assert.equal(response.name, "");
|
|
26
|
-
assert.equal(response.deleted, 0);
|
|
27
|
-
assert.equal(response.business?.id, 7);
|
|
28
|
-
done();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("create a new contact when we save", done => {
|
|
33
|
-
let contact: ContactEntity = { name: "Bjørge AS", department: "" };
|
|
34
|
-
|
|
35
|
-
let scope = nock(host)
|
|
36
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
37
|
-
.post("/api/v1/Agents/Contact/SaveContactEntity")
|
|
38
|
-
.reply(200, aContact);
|
|
39
|
-
|
|
40
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
41
|
-
let agent = new ContactAgent(host, config);
|
|
42
|
-
agent.saveContactEntityAsync(contact).then(res => {
|
|
43
|
-
assert.equal(res.name, "Bjørge AS");
|
|
44
|
-
done();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("Get a list of contacts", done => {
|
|
49
|
-
let scope = nock(host)
|
|
50
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
51
|
-
.post("/api/v1/Agents/Contact/GetContactList", [1])
|
|
52
|
-
.reply(200, [aContact]);
|
|
53
|
-
|
|
54
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
55
|
-
let agent = new ContactAgent(host, config);
|
|
56
|
-
agent.getContactListAsync([1]).then(contact => {
|
|
57
|
-
assert.equal(contact[0].name, "Bjørge AS");
|
|
58
|
-
assert.notEqual(contact[0].contactId, 0);
|
|
59
|
-
done();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("Get a single contacts", done => {
|
|
64
|
-
let scope = nock(host)
|
|
65
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
66
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
67
|
-
.reply(200, aContact);
|
|
68
|
-
|
|
69
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
70
|
-
let agent = new ContactAgent(host, config);
|
|
71
|
-
agent.getContactAsync(1).then(contact => {
|
|
72
|
-
assert.equal(contact.name, "Bjørge AS");
|
|
73
|
-
assert.notEqual(contact.contactId, 0);
|
|
74
|
-
done();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("Get a single contacts with tz included", done => {
|
|
79
|
-
let scope = nock(host)
|
|
80
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
81
|
-
.matchHeader(HEADER_NAME_TIMEZONE, "includeTZOffset")
|
|
82
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
83
|
-
.reply(200, aContact);
|
|
84
|
-
|
|
85
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
86
|
-
let options: WebApiRequestOptions = { timezoneInclude: true };
|
|
87
|
-
let agent = new ContactAgent(host, config);
|
|
88
|
-
agent.getContactAsync(1, options).then(contact => {
|
|
89
|
-
assert.equal(contact.name, "Bjørge AS");
|
|
90
|
-
assert.notEqual(contact.contactId, 0);
|
|
91
|
-
done();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("Get a single contacts with UTC timezone", done => {
|
|
96
|
-
let scope = nock(host)
|
|
97
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
98
|
-
.matchHeader(HEADER_NAME_TIMEZONE, "UTC")
|
|
99
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
100
|
-
.reply(200, aContact);
|
|
101
|
-
|
|
102
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
103
|
-
let options: WebApiRequestOptions = { timezone: "UTC" };
|
|
104
|
-
let agent = new ContactAgent(host, config);
|
|
105
|
-
agent.getContactAsync(1, options).then(contact => {
|
|
106
|
-
assert.equal(contact.name, "Bjørge AS");
|
|
107
|
-
assert.notEqual(contact.contactId, 0);
|
|
108
|
-
done();
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("Get a single contacts with UTC timezone", done => {
|
|
113
|
-
let scope = nock(host)
|
|
114
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
115
|
-
.matchHeader(HEADER_NAME_TIMEZONE, "UTC,includeTZOffset")
|
|
116
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
117
|
-
.reply(200, aContact);
|
|
118
|
-
|
|
119
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
120
|
-
let options: WebApiRequestOptions = { timezone: "UTC", timezoneInclude: true };
|
|
121
|
-
let agent = new ContactAgent(host, config);
|
|
122
|
-
agent.getContactAsync(1, options).then(contact => {
|
|
123
|
-
assert.equal(contact.name, "Bjørge AS");
|
|
124
|
-
assert.notEqual(contact.contactId, 0);
|
|
125
|
-
done();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
it("Can setup a cancelable a request", done => {
|
|
129
|
-
let scope = nock(host)
|
|
130
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
131
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
132
|
-
.reply(200, aContact);
|
|
133
|
-
|
|
134
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
135
|
-
let agent = new ContactAgent(host, config);
|
|
136
|
-
let options = agent.MakeOptions();
|
|
137
|
-
agent.getContactAsync(1, options).then(contact => {
|
|
138
|
-
assert.equal(contact.name, "Bjørge AS");
|
|
139
|
-
assert.notEqual(contact.contactId, 0);
|
|
140
|
-
assert.equal(options.requestStatus, WebApiStatus.Completed);
|
|
141
|
-
done();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("Can cancel a request before calling", done => {
|
|
146
|
-
let scope = nock(host)
|
|
147
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
148
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
149
|
-
.reply(200, aContact);
|
|
150
|
-
|
|
151
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
152
|
-
let agent = new ContactAgent(host, config);
|
|
153
|
-
let options = agent.MakeOptions();
|
|
154
|
-
options.cancelToken.cancel("dead on arrival");
|
|
155
|
-
agent
|
|
156
|
-
.getContactAsync(1, options)
|
|
157
|
-
.then(contact => {
|
|
158
|
-
assert.fail("should not get here");
|
|
159
|
-
done();
|
|
160
|
-
})
|
|
161
|
-
.catch(err => {
|
|
162
|
-
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
163
|
-
assert.equal(err.message, "dead on arrival");
|
|
164
|
-
done();
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("Can cancel a request in flight", done => {
|
|
169
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
170
|
-
let agent = new ContactAgent(host, config);
|
|
171
|
-
let options = agent.MakeOptions();
|
|
172
|
-
|
|
173
|
-
//console.log("Preflight");
|
|
174
|
-
let scope = nock(host)
|
|
175
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
176
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
177
|
-
.delayBody(500) // half second wait
|
|
178
|
-
.reply(function (uri, requestBody, cb) {
|
|
179
|
-
setTimeout(function () {
|
|
180
|
-
//console.log("Returning mock");
|
|
181
|
-
cb(null, [200, aContact]);
|
|
182
|
-
}, 1000);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// Cancel request before half second
|
|
186
|
-
setTimeout(function () {
|
|
187
|
-
//console.log("Cancelling request");
|
|
188
|
-
options.cancelToken.cancel("dead on arrival");
|
|
189
|
-
}, 1);
|
|
190
|
-
|
|
191
|
-
console.log("Take flight");
|
|
192
|
-
agent
|
|
193
|
-
.getContactAsync(1, options)
|
|
194
|
-
.then(contact => {
|
|
195
|
-
console.log("Landed");
|
|
196
|
-
assert.fail("should not get here");
|
|
197
|
-
done();
|
|
198
|
-
})
|
|
199
|
-
.catch(err => {
|
|
200
|
-
assert.equal(err.message, "dead on arrival");
|
|
201
|
-
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
202
|
-
done();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("Can cancel a request before calling with AbortController", done => {
|
|
207
|
-
let scope = nock(host)
|
|
208
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
209
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
210
|
-
.reply(200, aContact);
|
|
211
|
-
|
|
212
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
213
|
-
let agent = new ContactAgent(host, config);
|
|
214
|
-
let options = agent.MakeAbortableOptions();
|
|
215
|
-
options.abortController.abort();
|
|
216
|
-
agent
|
|
217
|
-
.getContactAsync(1, options)
|
|
218
|
-
.then(contact => {
|
|
219
|
-
assert.fail("should not get here");
|
|
220
|
-
done();
|
|
221
|
-
})
|
|
222
|
-
.catch(err => {
|
|
223
|
-
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
224
|
-
done();
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("Can cancel a request in flight with AbortController", done => {
|
|
229
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
230
|
-
let agent = new ContactAgent(host, config);
|
|
231
|
-
let options = agent.MakeAbortableOptions();
|
|
232
|
-
|
|
233
|
-
//console.log("Preflight");
|
|
234
|
-
let scope = nock(host)
|
|
235
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
236
|
-
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
237
|
-
.delayBody(500) // half second wait
|
|
238
|
-
.reply(function (uri, requestBody, cb) {
|
|
239
|
-
setTimeout(function () {
|
|
240
|
-
console.log("Returning mock");
|
|
241
|
-
cb(null, [200, aContact]);
|
|
242
|
-
}, 1000);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// Cancel request before half second
|
|
246
|
-
setTimeout(function () {
|
|
247
|
-
//console.log("Cancelling request");
|
|
248
|
-
options.abortController.abort();
|
|
249
|
-
}, 1);
|
|
250
|
-
|
|
251
|
-
console.log("Take flight");
|
|
252
|
-
agent
|
|
253
|
-
.getContactAsync(1, options)
|
|
254
|
-
.then(contact => {
|
|
255
|
-
//console.log("Landed");
|
|
256
|
-
assert.fail("should not get here");
|
|
257
|
-
done();
|
|
258
|
-
})
|
|
259
|
-
.catch(err => {
|
|
260
|
-
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
261
|
-
done();
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("Check if number is valid using params", done => {
|
|
266
|
-
let scope = nock(host)
|
|
267
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
268
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "foo456" })
|
|
269
|
-
.reply(200, "true");
|
|
270
|
-
|
|
271
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
272
|
-
let agent = new ContactAgent(host, config);
|
|
273
|
-
agent.isNumberValidAsync(123, "foo456").then(res => {
|
|
274
|
-
assert.equal(res, true);
|
|
275
|
-
done();
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("Check if number is valid using object", done => {
|
|
280
|
-
let scope = nock(host)
|
|
281
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
282
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "foo567" })
|
|
283
|
-
.reply(200, "true");
|
|
284
|
-
|
|
285
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
286
|
-
let agent = new ContactAgent(host, config);
|
|
287
|
-
agent.isNumberValidAsync({ contactId: 123, number: "foo567" }).then(res => {
|
|
288
|
-
assert.equal(res, true);
|
|
289
|
-
done();
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it("Check if number is valid using blank params", done => {
|
|
294
|
-
let scope = nock(host)
|
|
295
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
296
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "" })
|
|
297
|
-
.reply(200, "true");
|
|
298
|
-
|
|
299
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
300
|
-
let agent = new ContactAgent(host, config);
|
|
301
|
-
agent.isNumberValidAsync(123, "").then(res => {
|
|
302
|
-
assert.equal(res, true);
|
|
303
|
-
done();
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("Check if number is valid using blank object", done => {
|
|
308
|
-
let scope = nock(host)
|
|
309
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
310
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "" })
|
|
311
|
-
.reply(200, "true");
|
|
312
|
-
|
|
313
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
314
|
-
let agent = new ContactAgent(host, config);
|
|
315
|
-
agent.isNumberValidAsync({ contactId: 123, number: "" }).then(res => {
|
|
316
|
-
assert.equal(res, true);
|
|
317
|
-
done();
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it("Check if number is valid using null params", done => {
|
|
322
|
-
let scope = nock(host)
|
|
323
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
324
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
325
|
-
.reply(200, "true");
|
|
326
|
-
|
|
327
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
328
|
-
let agent = new ContactAgent(host, config);
|
|
329
|
-
agent.isNumberValidAsync(0, null).then(res => {
|
|
330
|
-
assert.equal(res, true);
|
|
331
|
-
done();
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("Check if number is valid using object", done => {
|
|
336
|
-
let scope = nock(host)
|
|
337
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
338
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
339
|
-
.reply(200, "true");
|
|
340
|
-
|
|
341
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
342
|
-
let agent = new ContactAgent(host, config);
|
|
343
|
-
agent.isNumberValidAsync({ contactId: 0, number: null }).then(res => {
|
|
344
|
-
assert.equal(res, true);
|
|
345
|
-
done();
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it("Check Threshold callback", done => {
|
|
350
|
-
let scope = nock(host)
|
|
351
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
352
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
353
|
-
.delay(2000)
|
|
354
|
-
.reply(200, "true");
|
|
355
|
-
|
|
356
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
357
|
-
let agent = new ContactAgent(host, config);
|
|
358
|
-
agent
|
|
359
|
-
.isNumberValidAsync(
|
|
360
|
-
{ contactId: 0, number: null },
|
|
361
|
-
{
|
|
362
|
-
threshold: {
|
|
363
|
-
timeout: 1000,
|
|
364
|
-
callback: () => {
|
|
365
|
-
done();
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
)
|
|
370
|
-
.then(res => {});
|
|
371
|
-
});
|
|
372
|
-
it("Check Threshold successCallback", done => {
|
|
373
|
-
let scope = nock(host)
|
|
374
|
-
.matchHeader("authorization", "Basic QURNMDo=")
|
|
375
|
-
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
376
|
-
.delay(500)
|
|
377
|
-
.reply(200, "true");
|
|
378
|
-
|
|
379
|
-
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
380
|
-
let agent = new ContactAgent(host, config);
|
|
381
|
-
agent
|
|
382
|
-
.isNumberValidAsync(
|
|
383
|
-
{ contactId: 0, number: null },
|
|
384
|
-
{
|
|
385
|
-
threshold: {
|
|
386
|
-
timeout: 1000,
|
|
387
|
-
successCallback: () => {
|
|
388
|
-
done();
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
)
|
|
393
|
-
.then(res => {});
|
|
394
|
-
});
|
|
395
|
-
});
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import axios, { AxiosRequestConfig } from "axios";
|
|
3
|
+
import nock from "nock";
|
|
4
|
+
import { WebApiStatus } from "../src/WebApiBase";
|
|
5
|
+
import { ContactEntity } from "../src/Carriers";
|
|
6
|
+
import { ContactAgent } from "../src/ContactAgent";
|
|
7
|
+
import { WebApiRequestOptions } from "../src/WebApi";
|
|
8
|
+
import { HEADER_NAME_TIMEZONE } from "../src/SoApiConstants";
|
|
9
|
+
|
|
10
|
+
const host: string = "http://localhost/";
|
|
11
|
+
const defaultContact = require("./ContactDefault.json");
|
|
12
|
+
const aContact = require("./ContactEntity.json");
|
|
13
|
+
|
|
14
|
+
axios.defaults.baseURL = host;
|
|
15
|
+
|
|
16
|
+
describe("WebAPI Contact tests", () => {
|
|
17
|
+
it("Can create a default contact", done => {
|
|
18
|
+
let scope = nock(host)
|
|
19
|
+
.post("/api/v1/Agents/Contact/CreateDefaultContactEntity")
|
|
20
|
+
.reply(200, defaultContact);
|
|
21
|
+
|
|
22
|
+
let agent = new ContactAgent(host);
|
|
23
|
+
agent.createDefaultContactEntityAsync().then(response => {
|
|
24
|
+
assert.equal(response.contactId, 0);
|
|
25
|
+
assert.equal(response.name, "");
|
|
26
|
+
assert.equal(response.deleted, 0);
|
|
27
|
+
assert.equal(response.business?.id, 7);
|
|
28
|
+
done();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("create a new contact when we save", done => {
|
|
33
|
+
let contact: ContactEntity = { name: "Bjørge AS", department: "" };
|
|
34
|
+
|
|
35
|
+
let scope = nock(host)
|
|
36
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
37
|
+
.post("/api/v1/Agents/Contact/SaveContactEntity")
|
|
38
|
+
.reply(200, aContact);
|
|
39
|
+
|
|
40
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
41
|
+
let agent = new ContactAgent(host, config);
|
|
42
|
+
agent.saveContactEntityAsync(contact).then(res => {
|
|
43
|
+
assert.equal(res.name, "Bjørge AS");
|
|
44
|
+
done();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("Get a list of contacts", done => {
|
|
49
|
+
let scope = nock(host)
|
|
50
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
51
|
+
.post("/api/v1/Agents/Contact/GetContactList", [1])
|
|
52
|
+
.reply(200, [aContact]);
|
|
53
|
+
|
|
54
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
55
|
+
let agent = new ContactAgent(host, config);
|
|
56
|
+
agent.getContactListAsync([1]).then(contact => {
|
|
57
|
+
assert.equal(contact[0].name, "Bjørge AS");
|
|
58
|
+
assert.notEqual(contact[0].contactId, 0);
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("Get a single contacts", done => {
|
|
64
|
+
let scope = nock(host)
|
|
65
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
66
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
67
|
+
.reply(200, aContact);
|
|
68
|
+
|
|
69
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
70
|
+
let agent = new ContactAgent(host, config);
|
|
71
|
+
agent.getContactAsync(1).then(contact => {
|
|
72
|
+
assert.equal(contact.name, "Bjørge AS");
|
|
73
|
+
assert.notEqual(contact.contactId, 0);
|
|
74
|
+
done();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("Get a single contacts with tz included", done => {
|
|
79
|
+
let scope = nock(host)
|
|
80
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
81
|
+
.matchHeader(HEADER_NAME_TIMEZONE, "includeTZOffset")
|
|
82
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
83
|
+
.reply(200, aContact);
|
|
84
|
+
|
|
85
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
86
|
+
let options: WebApiRequestOptions = { timezoneInclude: true };
|
|
87
|
+
let agent = new ContactAgent(host, config);
|
|
88
|
+
agent.getContactAsync(1, options).then(contact => {
|
|
89
|
+
assert.equal(contact.name, "Bjørge AS");
|
|
90
|
+
assert.notEqual(contact.contactId, 0);
|
|
91
|
+
done();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("Get a single contacts with UTC timezone", done => {
|
|
96
|
+
let scope = nock(host)
|
|
97
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
98
|
+
.matchHeader(HEADER_NAME_TIMEZONE, "UTC")
|
|
99
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
100
|
+
.reply(200, aContact);
|
|
101
|
+
|
|
102
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
103
|
+
let options: WebApiRequestOptions = { timezone: "UTC" };
|
|
104
|
+
let agent = new ContactAgent(host, config);
|
|
105
|
+
agent.getContactAsync(1, options).then(contact => {
|
|
106
|
+
assert.equal(contact.name, "Bjørge AS");
|
|
107
|
+
assert.notEqual(contact.contactId, 0);
|
|
108
|
+
done();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("Get a single contacts with UTC timezone", done => {
|
|
113
|
+
let scope = nock(host)
|
|
114
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
115
|
+
.matchHeader(HEADER_NAME_TIMEZONE, "UTC,includeTZOffset")
|
|
116
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
117
|
+
.reply(200, aContact);
|
|
118
|
+
|
|
119
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
120
|
+
let options: WebApiRequestOptions = { timezone: "UTC", timezoneInclude: true };
|
|
121
|
+
let agent = new ContactAgent(host, config);
|
|
122
|
+
agent.getContactAsync(1, options).then(contact => {
|
|
123
|
+
assert.equal(contact.name, "Bjørge AS");
|
|
124
|
+
assert.notEqual(contact.contactId, 0);
|
|
125
|
+
done();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
it("Can setup a cancelable a request", done => {
|
|
129
|
+
let scope = nock(host)
|
|
130
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
131
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
132
|
+
.reply(200, aContact);
|
|
133
|
+
|
|
134
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
135
|
+
let agent = new ContactAgent(host, config);
|
|
136
|
+
let options = agent.MakeOptions();
|
|
137
|
+
agent.getContactAsync(1, options).then(contact => {
|
|
138
|
+
assert.equal(contact.name, "Bjørge AS");
|
|
139
|
+
assert.notEqual(contact.contactId, 0);
|
|
140
|
+
assert.equal(options.requestStatus, WebApiStatus.Completed);
|
|
141
|
+
done();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("Can cancel a request before calling", done => {
|
|
146
|
+
let scope = nock(host)
|
|
147
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
148
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
149
|
+
.reply(200, aContact);
|
|
150
|
+
|
|
151
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
152
|
+
let agent = new ContactAgent(host, config);
|
|
153
|
+
let options = agent.MakeOptions();
|
|
154
|
+
options.cancelToken.cancel("dead on arrival");
|
|
155
|
+
agent
|
|
156
|
+
.getContactAsync(1, options)
|
|
157
|
+
.then(contact => {
|
|
158
|
+
assert.fail("should not get here");
|
|
159
|
+
done();
|
|
160
|
+
})
|
|
161
|
+
.catch(err => {
|
|
162
|
+
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
163
|
+
assert.equal(err.message, "dead on arrival");
|
|
164
|
+
done();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("Can cancel a request in flight", done => {
|
|
169
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
170
|
+
let agent = new ContactAgent(host, config);
|
|
171
|
+
let options = agent.MakeOptions();
|
|
172
|
+
|
|
173
|
+
//console.log("Preflight");
|
|
174
|
+
let scope = nock(host)
|
|
175
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
176
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
177
|
+
.delayBody(500) // half second wait
|
|
178
|
+
.reply(function (uri, requestBody, cb) {
|
|
179
|
+
setTimeout(function () {
|
|
180
|
+
//console.log("Returning mock");
|
|
181
|
+
cb(null, [200, aContact]);
|
|
182
|
+
}, 1000);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Cancel request before half second
|
|
186
|
+
setTimeout(function () {
|
|
187
|
+
//console.log("Cancelling request");
|
|
188
|
+
options.cancelToken.cancel("dead on arrival");
|
|
189
|
+
}, 1);
|
|
190
|
+
|
|
191
|
+
console.log("Take flight");
|
|
192
|
+
agent
|
|
193
|
+
.getContactAsync(1, options)
|
|
194
|
+
.then(contact => {
|
|
195
|
+
console.log("Landed");
|
|
196
|
+
assert.fail("should not get here");
|
|
197
|
+
done();
|
|
198
|
+
})
|
|
199
|
+
.catch(err => {
|
|
200
|
+
assert.equal(err.message, "dead on arrival");
|
|
201
|
+
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
202
|
+
done();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("Can cancel a request before calling with AbortController", done => {
|
|
207
|
+
let scope = nock(host)
|
|
208
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
209
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
210
|
+
.reply(200, aContact);
|
|
211
|
+
|
|
212
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
213
|
+
let agent = new ContactAgent(host, config);
|
|
214
|
+
let options = agent.MakeAbortableOptions();
|
|
215
|
+
options.abortController.abort();
|
|
216
|
+
agent
|
|
217
|
+
.getContactAsync(1, options)
|
|
218
|
+
.then(contact => {
|
|
219
|
+
assert.fail("should not get here");
|
|
220
|
+
done();
|
|
221
|
+
})
|
|
222
|
+
.catch(err => {
|
|
223
|
+
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
224
|
+
done();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("Can cancel a request in flight with AbortController", done => {
|
|
229
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
230
|
+
let agent = new ContactAgent(host, config);
|
|
231
|
+
let options = agent.MakeAbortableOptions();
|
|
232
|
+
|
|
233
|
+
//console.log("Preflight");
|
|
234
|
+
let scope = nock(host)
|
|
235
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
236
|
+
.post("/api/v1/Agents/Contact/GetContact?contactId=1")
|
|
237
|
+
.delayBody(500) // half second wait
|
|
238
|
+
.reply(function (uri, requestBody, cb) {
|
|
239
|
+
setTimeout(function () {
|
|
240
|
+
console.log("Returning mock");
|
|
241
|
+
cb(null, [200, aContact]);
|
|
242
|
+
}, 1000);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Cancel request before half second
|
|
246
|
+
setTimeout(function () {
|
|
247
|
+
//console.log("Cancelling request");
|
|
248
|
+
options.abortController.abort();
|
|
249
|
+
}, 1);
|
|
250
|
+
|
|
251
|
+
console.log("Take flight");
|
|
252
|
+
agent
|
|
253
|
+
.getContactAsync(1, options)
|
|
254
|
+
.then(contact => {
|
|
255
|
+
//console.log("Landed");
|
|
256
|
+
assert.fail("should not get here");
|
|
257
|
+
done();
|
|
258
|
+
})
|
|
259
|
+
.catch(err => {
|
|
260
|
+
assert.equal(options.requestStatus, WebApiStatus.Cancelled);
|
|
261
|
+
done();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("Check if number is valid using params", done => {
|
|
266
|
+
let scope = nock(host)
|
|
267
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
268
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "foo456" })
|
|
269
|
+
.reply(200, "true");
|
|
270
|
+
|
|
271
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
272
|
+
let agent = new ContactAgent(host, config);
|
|
273
|
+
agent.isNumberValidAsync(123, "foo456").then(res => {
|
|
274
|
+
assert.equal(res, true);
|
|
275
|
+
done();
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("Check if number is valid using object", done => {
|
|
280
|
+
let scope = nock(host)
|
|
281
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
282
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "foo567" })
|
|
283
|
+
.reply(200, "true");
|
|
284
|
+
|
|
285
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
286
|
+
let agent = new ContactAgent(host, config);
|
|
287
|
+
agent.isNumberValidAsync({ contactId: 123, number: "foo567" }).then(res => {
|
|
288
|
+
assert.equal(res, true);
|
|
289
|
+
done();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("Check if number is valid using blank params", done => {
|
|
294
|
+
let scope = nock(host)
|
|
295
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
296
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "" })
|
|
297
|
+
.reply(200, "true");
|
|
298
|
+
|
|
299
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
300
|
+
let agent = new ContactAgent(host, config);
|
|
301
|
+
agent.isNumberValidAsync(123, "").then(res => {
|
|
302
|
+
assert.equal(res, true);
|
|
303
|
+
done();
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("Check if number is valid using blank object", done => {
|
|
308
|
+
let scope = nock(host)
|
|
309
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
310
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 123, number: "" })
|
|
311
|
+
.reply(200, "true");
|
|
312
|
+
|
|
313
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
314
|
+
let agent = new ContactAgent(host, config);
|
|
315
|
+
agent.isNumberValidAsync({ contactId: 123, number: "" }).then(res => {
|
|
316
|
+
assert.equal(res, true);
|
|
317
|
+
done();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("Check if number is valid using null params", done => {
|
|
322
|
+
let scope = nock(host)
|
|
323
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
324
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
325
|
+
.reply(200, "true");
|
|
326
|
+
|
|
327
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
328
|
+
let agent = new ContactAgent(host, config);
|
|
329
|
+
agent.isNumberValidAsync(0, null).then(res => {
|
|
330
|
+
assert.equal(res, true);
|
|
331
|
+
done();
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("Check if number is valid using object", done => {
|
|
336
|
+
let scope = nock(host)
|
|
337
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
338
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
339
|
+
.reply(200, "true");
|
|
340
|
+
|
|
341
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
342
|
+
let agent = new ContactAgent(host, config);
|
|
343
|
+
agent.isNumberValidAsync({ contactId: 0, number: null }).then(res => {
|
|
344
|
+
assert.equal(res, true);
|
|
345
|
+
done();
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("Check Threshold callback", done => {
|
|
350
|
+
let scope = nock(host)
|
|
351
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
352
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
353
|
+
.delay(2000)
|
|
354
|
+
.reply(200, "true");
|
|
355
|
+
|
|
356
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
357
|
+
let agent = new ContactAgent(host, config);
|
|
358
|
+
agent
|
|
359
|
+
.isNumberValidAsync(
|
|
360
|
+
{ contactId: 0, number: null },
|
|
361
|
+
{
|
|
362
|
+
threshold: {
|
|
363
|
+
timeout: 1000,
|
|
364
|
+
callback: () => {
|
|
365
|
+
done();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
.then(res => {});
|
|
371
|
+
});
|
|
372
|
+
it("Check Threshold successCallback", done => {
|
|
373
|
+
let scope = nock(host)
|
|
374
|
+
.matchHeader("authorization", "Basic QURNMDo=")
|
|
375
|
+
.post("/api/v1/Agents/Contact/IsNumberValid", { contactId: 0, number: null })
|
|
376
|
+
.delay(500)
|
|
377
|
+
.reply(200, "true");
|
|
378
|
+
|
|
379
|
+
let config: AxiosRequestConfig = { auth: { username: "ADM0", password: "" } };
|
|
380
|
+
let agent = new ContactAgent(host, config);
|
|
381
|
+
agent
|
|
382
|
+
.isNumberValidAsync(
|
|
383
|
+
{ contactId: 0, number: null },
|
|
384
|
+
{
|
|
385
|
+
threshold: {
|
|
386
|
+
timeout: 1000,
|
|
387
|
+
successCallback: () => {
|
|
388
|
+
done();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
)
|
|
393
|
+
.then(res => {});
|
|
394
|
+
});
|
|
395
|
+
});
|