smartystreets-javascript-sdk 5.0.1 → 5.1.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.
@@ -0,0 +1,238 @@
1
+ const chai = require("chai");
2
+ const expect = chai.expect;
3
+ const Client = require("../../src/us_enrichment/Client");
4
+ const Lookup = require("../../src/us_enrichment/Lookup");
5
+ const errors = require("../../src/Errors");
6
+ const MockSender = require("../fixtures/mock_senders").MockSender;
7
+ const MockSenderWithResponse = require("../fixtures/mock_senders").MockSenderWithResponse;
8
+ const {Response, FinancialResponse, GeoResponse} = require("../../src/us_enrichment/Response");
9
+
10
+ describe("A US Enrichment Client", function () {
11
+ it("correctly builds parameters for a smartyKey only principal lookup.", function () {
12
+ let mockSender = new MockSender();
13
+ let client = new Client(mockSender);
14
+ let smartyKey = '(>")>#';
15
+ let include = "1";
16
+ let lookup = new Lookup(smartyKey, include);
17
+ let expectedParameters = {
18
+ include: include,
19
+ };
20
+
21
+ client.sendPrincipal(lookup);
22
+
23
+ expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
24
+ });
25
+
26
+ it("correctly builds parameters for a smartyKey only financial lookup.", function () {
27
+ let mockSender = new MockSender();
28
+ let client = new Client(mockSender);
29
+ let smartyKey = '(>")>#';
30
+ let include = "1";
31
+ let lookup = new Lookup(smartyKey, include);
32
+ let expectedParameters = {
33
+ include: include,
34
+ };
35
+
36
+ client.sendFinancial(lookup);
37
+
38
+ expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
39
+ });
40
+
41
+ it("correctly builds parameters for a smartyKey only geo lookup.", function () {
42
+ let mockSender = new MockSender();
43
+ let client = new Client(mockSender);
44
+ let smartyKey = '(>")>#';
45
+ let include = "1";
46
+ let lookup = new Lookup(smartyKey, include);
47
+ let expectedParameters = {
48
+ include: include,
49
+ };
50
+
51
+ client.sendGeo(lookup);
52
+
53
+ expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
54
+ });
55
+
56
+ it("correctly builds parameters for a fully-populated principal lookup.", function () {
57
+ let mockSender = new MockSender();
58
+ let client = new Client(mockSender);
59
+ let lookup = new Lookup("0","1","2","3","4");
60
+
61
+ let expectedParameters = {
62
+ include: "1",
63
+ exclude: "2",
64
+ dataset: "3",
65
+ data_subset: "4",
66
+ };
67
+
68
+ client.sendPrincipal(lookup);
69
+ expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
70
+ });
71
+
72
+ it("correctly builds parameters for a fully-populated financial lookup.", function () {
73
+ let mockSender = new MockSender();
74
+ let client = new Client(mockSender);
75
+ let lookup = new Lookup("0","1","2","3","4");
76
+
77
+ let expectedParameters = {
78
+ include: "1",
79
+ exclude: "2",
80
+ dataset: "3",
81
+ data_subset: "4",
82
+ };
83
+
84
+ client.sendFinancial(lookup);
85
+ expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
86
+ });
87
+
88
+ it("correctly builds parameters for a fully-populated geo lookup.", function () {
89
+ let mockSender = new MockSender();
90
+ let client = new Client(mockSender);
91
+ let lookup = new Lookup("0","1","2","3","4");
92
+
93
+ let expectedParameters = {
94
+ include: "1",
95
+ exclude: "2",
96
+ dataset: "3",
97
+ data_subset: "4",
98
+ };
99
+
100
+ client.sendGeo(lookup);
101
+ expect(mockSender.request.parameters).to.deep.equal(expectedParameters);
102
+ });
103
+
104
+ it("throws an error if sending without a principal lookup.", function () {
105
+ let mockSender = new MockSender();
106
+ let client = new Client(mockSender);
107
+ expect(client.sendPrincipal).to.throw(errors.UndefinedLookupError);
108
+ });
109
+
110
+ it("throws an error if sending without a financial lookup.", function () {
111
+ let mockSender = new MockSender();
112
+ let client = new Client(mockSender);
113
+ expect(client.sendFinancial).to.throw(errors.UndefinedLookupError);
114
+ });
115
+
116
+ it("throws an error if sending without a geo lookup.", function () {
117
+ let mockSender = new MockSender();
118
+ let client = new Client(mockSender);
119
+ expect(client.sendGeo).to.throw(errors.UndefinedLookupError);
120
+ });
121
+
122
+ it("rejects with an exception if the principal response comes back with an error.", function () {
123
+ let expectedError = new Error("I'm the error.");
124
+ let mockSender = new MockSenderWithResponse("", expectedError);
125
+ let client = new Client(mockSender);
126
+ let lookup = new Lookup("¯\\_(ツ)_/¯");
127
+
128
+ return client.sendPrincipal(lookup).catch((e) => {expect(e).to.equal(expectedError);});
129
+ });
130
+
131
+ it("rejects with an exception if the financial response comes back with an error.", function () {
132
+ let expectedError = new Error("I'm the error.");
133
+ let mockSender = new MockSenderWithResponse("", expectedError);
134
+ let client = new Client(mockSender);
135
+ let lookup = new Lookup("¯\\_(ツ)_/¯");
136
+
137
+ return client.sendFinancial(lookup).catch((e) => {expect(e).to.equal(expectedError);});
138
+ });
139
+
140
+ it("rejects with an exception if the geo response comes back with an error.", function () {
141
+ let expectedError = new Error("I'm the error.");
142
+ let mockSender = new MockSenderWithResponse("", expectedError);
143
+ let client = new Client(mockSender);
144
+ let lookup = new Lookup("¯\\_(ツ)_/¯");
145
+
146
+ return client.sendGeo(lookup).catch((e) => {expect(e).to.equal(expectedError);});
147
+ });
148
+
149
+ it("returns an empty array when no principal respo are returned.", () => {
150
+ let mockSender = new MockSenderWithResponse({});
151
+ let client = new Client(mockSender);
152
+ let lookup = new Lookup("smartyKey");
153
+
154
+ return client.sendPrincipal(lookup).then(response => {
155
+ expect(lookup.response).to.deep.equal({});
156
+ });
157
+ });
158
+
159
+ it("returns an empty array when no financial suggestions are returned.", () => {
160
+ let mockSender = new MockSenderWithResponse({});
161
+ let client = new Client(mockSender);
162
+ let lookup = new Lookup("smartyKey");
163
+
164
+ return client.sendFinancial(lookup).then(response => {
165
+ expect(lookup.response).to.deep.equal({});
166
+ });
167
+ });
168
+
169
+ it("returns an empty array when no geo suggestions are returned.", () => {
170
+ let mockSender = new MockSenderWithResponse({});
171
+ let client = new Client(mockSender);
172
+ let lookup = new Lookup("smartyKey");
173
+
174
+ return client.sendGeo(lookup).then(response => {
175
+ expect(lookup.response).to.deep.equal({});
176
+ });
177
+ });
178
+
179
+ it("attaches response to a principal lookup.", function () {
180
+ const rawMockResponse = {
181
+ smarty_key: "a",
182
+ data_set_name: "b",
183
+ data_subset_name: "c",
184
+ attributes: {
185
+ assessed_improvement_percent: "1"
186
+ },
187
+ };
188
+ let mockResponse = new Response(rawMockResponse);
189
+
190
+ let mockSender = new MockSenderWithResponse(mockResponse);
191
+ let client = new Client(mockSender);
192
+ let lookup = new Lookup("smartyKey");
193
+
194
+ return client.sendPrincipal(lookup).then(response => {
195
+ expect(lookup.response).to.deep.equal(mockResponse);
196
+ });
197
+ })
198
+
199
+ it("attaches response to a financial lookup.", function () {
200
+ const rawMockResponse = {
201
+ smarty_key: "a",
202
+ data_set_name: "b",
203
+ data_subset_name: "c",
204
+ attributes: {
205
+ assessed_improvement_percent: "1"
206
+ },
207
+ };
208
+ let mockResponse = new FinancialResponse(rawMockResponse);
209
+
210
+ let mockSender = new MockSenderWithResponse(mockResponse);
211
+ let client = new Client(mockSender);
212
+ let lookup = new Lookup("smartyKey");
213
+
214
+ return client.sendFinancial(lookup).then(response => {
215
+ expect(lookup.response).to.deep.equal(mockResponse);
216
+ });
217
+ })
218
+
219
+ it("attaches response to a geo lookup.", function () {
220
+ const rawMockResponse = {
221
+ smarty_key: "a",
222
+ data_set_name: "b",
223
+ data_subset_name: "c",
224
+ attributes: {
225
+ assessed_improvement_percent: "1"
226
+ },
227
+ };
228
+ let mockResponse = new GeoResponse(rawMockResponse);
229
+
230
+ let mockSender = new MockSenderWithResponse(mockResponse);
231
+ let client = new Client(mockSender);
232
+ let lookup = new Lookup("smartyKey");
233
+
234
+ return client.sendGeo(lookup).then(response => {
235
+ expect(lookup.response).to.deep.equal(mockResponse);
236
+ });
237
+ })
238
+ });
@@ -0,0 +1,22 @@
1
+ const chai = require("chai");
2
+ const expect = chai.expect;
3
+ const Lookup = require("../../src/us_enrichment/Lookup");
4
+
5
+ describe("A US Enrichment Lookup", function () {
6
+ it("can be newed up with all basic fields.", function () {
7
+ const expectedSmartyKey = "a";
8
+ const expectedInclude = "b";
9
+ const expectedExclude = "c";
10
+ const expectedDataset = "d";
11
+ const expectedDataSubset = "e";
12
+
13
+ let lookup = new Lookup(expectedSmartyKey, expectedInclude, expectedExclude, expectedDataset, expectedDataSubset);
14
+ expect(lookup.smartyKey).to.equal(expectedSmartyKey);
15
+ expect(lookup.include).to.equal(expectedInclude);
16
+ expect(lookup.exclude).to.equal(expectedExclude);
17
+ expect(lookup.dataset).to.equal(expectedDataset);
18
+ expect(lookup.dataSubset).to.equal(expectedDataSubset);
19
+ });
20
+
21
+
22
+ });