smartystreets-javascript-sdk 5.1.4 → 5.2.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/Makefile +2 -2
- package/package.json +1 -1
- package/src/us_enrichment/Client.js +40 -0
- package/tests/us_enrichment/test_Client.js +190 -6
package/Makefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/make -f
|
|
2
2
|
|
|
3
|
-
VERSION := $(shell tagit -
|
|
3
|
+
VERSION := $(shell tagit -m --dry-run)
|
|
4
4
|
VERSION_FILE1 := package.json
|
|
5
5
|
VERSION_FILE2 := package-lock.json
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ node_modules:
|
|
|
11
11
|
npm install
|
|
12
12
|
|
|
13
13
|
publish: test version upload unversion
|
|
14
|
-
tagit -
|
|
14
|
+
tagit -m
|
|
15
15
|
git push origin --tags
|
|
16
16
|
|
|
17
17
|
upload:
|
package/package.json
CHANGED
|
@@ -67,6 +67,46 @@ class Client {
|
|
|
67
67
|
.catch(reject);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
sendSecondary(lookup) {
|
|
72
|
+
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
73
|
+
|
|
74
|
+
let request = new Request();
|
|
75
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
76
|
+
|
|
77
|
+
request.baseUrlParam = lookup.smartyKey + "/secondary";
|
|
78
|
+
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
this.sender.send(request)
|
|
81
|
+
.then(response => {
|
|
82
|
+
if (response.error) reject(response.error);
|
|
83
|
+
|
|
84
|
+
lookup.response = response.payload;
|
|
85
|
+
resolve(lookup);
|
|
86
|
+
})
|
|
87
|
+
.catch(reject);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
sendSecondaryCount(lookup) {
|
|
92
|
+
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
93
|
+
|
|
94
|
+
let request = new Request();
|
|
95
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
96
|
+
|
|
97
|
+
request.baseUrlParam = lookup.smartyKey + "/secondary/count";
|
|
98
|
+
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
this.sender.send(request)
|
|
101
|
+
.then(response => {
|
|
102
|
+
if (response.error) reject(response.error);
|
|
103
|
+
|
|
104
|
+
lookup.response = response.payload;
|
|
105
|
+
resolve(lookup);
|
|
106
|
+
})
|
|
107
|
+
.catch(reject);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
70
110
|
}
|
|
71
111
|
|
|
72
112
|
module.exports = Client;
|
|
@@ -41,6 +41,28 @@ describe("A US Enrichment Client", function () {
|
|
|
41
41
|
expect(mockSender.request.baseUrlParam).to.deep.equal("0/geo-reference");
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
+
it("composes secondary url path properly", function () {
|
|
45
|
+
let mockSender = new MockSender();
|
|
46
|
+
let client = new Client(mockSender);
|
|
47
|
+
let smartyKey = "0";
|
|
48
|
+
let lookup = new Lookup(smartyKey);
|
|
49
|
+
|
|
50
|
+
client.sendSecondary(lookup);
|
|
51
|
+
|
|
52
|
+
expect(mockSender.request.baseUrlParam).to.deep.equal("0/secondary");
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it("composes secondary count url path properly", function () {
|
|
56
|
+
let mockSender = new MockSender();
|
|
57
|
+
let client = new Client(mockSender);
|
|
58
|
+
let smartyKey = "0";
|
|
59
|
+
let lookup = new Lookup(smartyKey);
|
|
60
|
+
|
|
61
|
+
client.sendSecondaryCount(lookup);
|
|
62
|
+
|
|
63
|
+
expect(mockSender.request.baseUrlParam).to.deep.equal("0/secondary/count");
|
|
64
|
+
})
|
|
65
|
+
|
|
44
66
|
it("correctly builds parameters for a smartyKey only principal lookup.", function () {
|
|
45
67
|
let mockSender = new MockSender();
|
|
46
68
|
let client = new Client(mockSender);
|
|
@@ -86,10 +108,40 @@ describe("A US Enrichment Client", function () {
|
|
|
86
108
|
expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
|
|
87
109
|
});
|
|
88
110
|
|
|
111
|
+
it("correctly builds parameters for a smartyKey only secondary lookup.", function () {
|
|
112
|
+
let mockSender = new MockSender();
|
|
113
|
+
let client = new Client(mockSender);
|
|
114
|
+
let smartyKey = '(>")>#';
|
|
115
|
+
let include = "1";
|
|
116
|
+
let lookup = new Lookup(smartyKey, include);
|
|
117
|
+
let expectedParameters = {
|
|
118
|
+
include: include,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
client.sendSecondary(lookup);
|
|
122
|
+
|
|
123
|
+
expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("correctly builds parameters for a smartyKey only secondary count lookup.", function () {
|
|
127
|
+
let mockSender = new MockSender();
|
|
128
|
+
let client = new Client(mockSender);
|
|
129
|
+
let smartyKey = '(>")>#';
|
|
130
|
+
let include = "1";
|
|
131
|
+
let lookup = new Lookup(smartyKey, include);
|
|
132
|
+
let expectedParameters = {
|
|
133
|
+
include: include,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
client.sendSecondaryCount(lookup);
|
|
137
|
+
|
|
138
|
+
expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
|
|
139
|
+
});
|
|
140
|
+
|
|
89
141
|
it("correctly builds parameters for a fully-populated principal lookup.", function () {
|
|
90
142
|
let mockSender = new MockSender();
|
|
91
143
|
let client = new Client(mockSender);
|
|
92
|
-
let lookup = new Lookup("0","1","2","3","4");
|
|
144
|
+
let lookup = new Lookup("0", "1", "2", "3", "4");
|
|
93
145
|
|
|
94
146
|
let expectedParameters = {
|
|
95
147
|
include: "1",
|
|
@@ -105,7 +157,7 @@ describe("A US Enrichment Client", function () {
|
|
|
105
157
|
it("correctly builds parameters for a fully-populated financial lookup.", function () {
|
|
106
158
|
let mockSender = new MockSender();
|
|
107
159
|
let client = new Client(mockSender);
|
|
108
|
-
let lookup = new Lookup("0","1","2","3","4");
|
|
160
|
+
let lookup = new Lookup("0", "1", "2", "3", "4");
|
|
109
161
|
|
|
110
162
|
let expectedParameters = {
|
|
111
163
|
include: "1",
|
|
@@ -121,7 +173,7 @@ describe("A US Enrichment Client", function () {
|
|
|
121
173
|
it("correctly builds parameters for a fully-populated geo lookup.", function () {
|
|
122
174
|
let mockSender = new MockSender();
|
|
123
175
|
let client = new Client(mockSender);
|
|
124
|
-
let lookup = new Lookup("0","1","2","3","4");
|
|
176
|
+
let lookup = new Lookup("0", "1", "2", "3", "4");
|
|
125
177
|
|
|
126
178
|
let expectedParameters = {
|
|
127
179
|
include: "1",
|
|
@@ -134,6 +186,38 @@ describe("A US Enrichment Client", function () {
|
|
|
134
186
|
expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
|
|
135
187
|
});
|
|
136
188
|
|
|
189
|
+
it("correctly builds parameters for a fully-populated secondary lookup.", function () {
|
|
190
|
+
let mockSender = new MockSender();
|
|
191
|
+
let client = new Client(mockSender);
|
|
192
|
+
let lookup = new Lookup("0", "1", "2", "3", "4");
|
|
193
|
+
|
|
194
|
+
let expectedParameters = {
|
|
195
|
+
include: "1",
|
|
196
|
+
exclude: "2",
|
|
197
|
+
dataset: "3",
|
|
198
|
+
data_subset: "4",
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
client.sendSecondary(lookup);
|
|
202
|
+
expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("correctly builds parameters for a fully-populated secondary count lookup.", function () {
|
|
206
|
+
let mockSender = new MockSender();
|
|
207
|
+
let client = new Client(mockSender);
|
|
208
|
+
let lookup = new Lookup("0", "1", "2", "3", "4");
|
|
209
|
+
|
|
210
|
+
let expectedParameters = {
|
|
211
|
+
include: "1",
|
|
212
|
+
exclude: "2",
|
|
213
|
+
dataset: "3",
|
|
214
|
+
data_subset: "4",
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
client.sendSecondaryCount(lookup);
|
|
218
|
+
expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
|
|
219
|
+
});
|
|
220
|
+
|
|
137
221
|
it("throws an error if sending without a principal lookup.", function () {
|
|
138
222
|
let mockSender = new MockSender();
|
|
139
223
|
let client = new Client(mockSender);
|
|
@@ -152,13 +236,27 @@ describe("A US Enrichment Client", function () {
|
|
|
152
236
|
expect(client.sendGeo).to.throw(errors.UndefinedLookupError);
|
|
153
237
|
});
|
|
154
238
|
|
|
239
|
+
it("throws an error if sending without a secondary lookup.", function () {
|
|
240
|
+
let mockSender = new MockSender();
|
|
241
|
+
let client = new Client(mockSender);
|
|
242
|
+
expect(client.sendSecondary).to.throw(errors.UndefinedLookupError);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("throws an error if sending without a secondary count lookup.", function () {
|
|
246
|
+
let mockSender = new MockSender();
|
|
247
|
+
let client = new Client(mockSender);
|
|
248
|
+
expect(client.sendSecondaryCount).to.throw(errors.UndefinedLookupError);
|
|
249
|
+
});
|
|
250
|
+
|
|
155
251
|
it("rejects with an exception if the principal response comes back with an error.", function () {
|
|
156
252
|
let expectedError = new Error("I'm the error.");
|
|
157
253
|
let mockSender = new MockSenderWithResponse("", expectedError);
|
|
158
254
|
let client = new Client(mockSender);
|
|
159
255
|
let lookup = new Lookup("¯\\_(ツ)_/¯");
|
|
160
256
|
|
|
161
|
-
return client.sendPrincipal(lookup).catch((e) => {
|
|
257
|
+
return client.sendPrincipal(lookup).catch((e) => {
|
|
258
|
+
expect(e).to.equal(expectedError);
|
|
259
|
+
});
|
|
162
260
|
});
|
|
163
261
|
|
|
164
262
|
it("rejects with an exception if the financial response comes back with an error.", function () {
|
|
@@ -167,7 +265,9 @@ describe("A US Enrichment Client", function () {
|
|
|
167
265
|
let client = new Client(mockSender);
|
|
168
266
|
let lookup = new Lookup("¯\\_(ツ)_/¯");
|
|
169
267
|
|
|
170
|
-
return client.sendFinancial(lookup).catch((e) => {
|
|
268
|
+
return client.sendFinancial(lookup).catch((e) => {
|
|
269
|
+
expect(e).to.equal(expectedError);
|
|
270
|
+
});
|
|
171
271
|
});
|
|
172
272
|
|
|
173
273
|
it("rejects with an exception if the geo response comes back with an error.", function () {
|
|
@@ -176,7 +276,31 @@ describe("A US Enrichment Client", function () {
|
|
|
176
276
|
let client = new Client(mockSender);
|
|
177
277
|
let lookup = new Lookup("¯\\_(ツ)_/¯");
|
|
178
278
|
|
|
179
|
-
return client.sendGeo(lookup).catch((e) => {
|
|
279
|
+
return client.sendGeo(lookup).catch((e) => {
|
|
280
|
+
expect(e).to.equal(expectedError);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("rejects with an exception if the secondary response comes back with an error.", function () {
|
|
285
|
+
let expectedError = new Error("I'm the error.");
|
|
286
|
+
let mockSender = new MockSenderWithResponse("", expectedError);
|
|
287
|
+
let client = new Client(mockSender);
|
|
288
|
+
let lookup = new Lookup("¯\\_(ツ)_/¯");
|
|
289
|
+
|
|
290
|
+
return client.sendSecondary(lookup).catch((e) => {
|
|
291
|
+
expect(e).to.equal(expectedError);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("rejects with an exception if the secondary count response comes back with an error.", function () {
|
|
296
|
+
let expectedError = new Error("I'm the error.");
|
|
297
|
+
let mockSender = new MockSenderWithResponse("", expectedError);
|
|
298
|
+
let client = new Client(mockSender);
|
|
299
|
+
let lookup = new Lookup("¯\\_(ツ)_/¯");
|
|
300
|
+
|
|
301
|
+
return client.sendSecondaryCount(lookup).catch((e) => {
|
|
302
|
+
expect(e).to.equal(expectedError);
|
|
303
|
+
});
|
|
180
304
|
});
|
|
181
305
|
|
|
182
306
|
it("returns an empty array when no principal respo are returned.", () => {
|
|
@@ -209,6 +333,26 @@ describe("A US Enrichment Client", function () {
|
|
|
209
333
|
});
|
|
210
334
|
});
|
|
211
335
|
|
|
336
|
+
it("returns an empty array when no secondary suggestions are returned.", () => {
|
|
337
|
+
let mockSender = new MockSenderWithResponse({});
|
|
338
|
+
let client = new Client(mockSender);
|
|
339
|
+
let lookup = new Lookup("smartyKey");
|
|
340
|
+
|
|
341
|
+
return client.sendSecondary(lookup).then(response => {
|
|
342
|
+
expect(lookup.response).to.deep.equal({});
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("returns an empty array when no secondary count suggestions are returned.", () => {
|
|
347
|
+
let mockSender = new MockSenderWithResponse({});
|
|
348
|
+
let client = new Client(mockSender);
|
|
349
|
+
let lookup = new Lookup("smartyKey");
|
|
350
|
+
|
|
351
|
+
return client.sendSecondaryCount(lookup).then(response => {
|
|
352
|
+
expect(lookup.response).to.deep.equal({});
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
212
356
|
it("attaches response to a principal lookup.", function () {
|
|
213
357
|
const rawMockResponse = {
|
|
214
358
|
smarty_key: "a",
|
|
@@ -268,4 +412,44 @@ describe("A US Enrichment Client", function () {
|
|
|
268
412
|
expect(lookup.response).to.deep.equal(mockResponse);
|
|
269
413
|
});
|
|
270
414
|
})
|
|
415
|
+
|
|
416
|
+
it("attaches response to a secondary lookup.", function () {
|
|
417
|
+
const rawMockResponse = {
|
|
418
|
+
smarty_key: "a",
|
|
419
|
+
data_set_name: "b",
|
|
420
|
+
data_subset_name: "c",
|
|
421
|
+
attributes: {
|
|
422
|
+
assessed_improvement_percent: "1"
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
let mockResponse = new Response(rawMockResponse);
|
|
426
|
+
|
|
427
|
+
let mockSender = new MockSenderWithResponse(mockResponse);
|
|
428
|
+
let client = new Client(mockSender);
|
|
429
|
+
let lookup = new Lookup("smartyKey");
|
|
430
|
+
|
|
431
|
+
return client.sendSecondary(lookup).then(response => {
|
|
432
|
+
expect(lookup.response).to.deep.equal(mockResponse);
|
|
433
|
+
});
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
it("attaches response to a secondary count lookup.", function () {
|
|
437
|
+
const rawMockResponse = {
|
|
438
|
+
smarty_key: "a",
|
|
439
|
+
data_set_name: "b",
|
|
440
|
+
data_subset_name: "c",
|
|
441
|
+
attributes: {
|
|
442
|
+
assessed_improvement_percent: "1"
|
|
443
|
+
},
|
|
444
|
+
};
|
|
445
|
+
let mockResponse = new Response(rawMockResponse);
|
|
446
|
+
|
|
447
|
+
let mockSender = new MockSenderWithResponse(mockResponse);
|
|
448
|
+
let client = new Client(mockSender);
|
|
449
|
+
let lookup = new Lookup("smartyKey");
|
|
450
|
+
|
|
451
|
+
return client.sendSecondaryCount(lookup).then(response => {
|
|
452
|
+
expect(lookup.response).to.deep.equal(mockResponse);
|
|
453
|
+
});
|
|
454
|
+
})
|
|
271
455
|
});
|