@@ -41,6 +41,28 @@ describe("A US Enrichment Client", function () {
4141 expect ( mockSender . request . baseUrlParam ) . to . deep . equal ( "0/geo-reference" ) ;
4242 } )
4343
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+
4466 it ( "correctly builds parameters for a smartyKey only principal lookup." , function ( ) {
4567 let mockSender = new MockSender ( ) ;
4668 let client = new Client ( mockSender ) ;
@@ -86,10 +108,40 @@ describe("A US Enrichment Client", function () {
86108 expect ( mockSender . request . parameters ) . to . deep . equal ( expectedParameters ) ;
87109 } ) ;
88110
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+
89141 it ( "correctly builds parameters for a fully-populated principal lookup." , function ( ) {
90142 let mockSender = new MockSender ( ) ;
91143 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" ) ;
93145
94146 let expectedParameters = {
95147 include : "1" ,
@@ -105,7 +157,7 @@ describe("A US Enrichment Client", function () {
105157 it ( "correctly builds parameters for a fully-populated financial lookup." , function ( ) {
106158 let mockSender = new MockSender ( ) ;
107159 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" ) ;
109161
110162 let expectedParameters = {
111163 include : "1" ,
@@ -121,7 +173,7 @@ describe("A US Enrichment Client", function () {
121173 it ( "correctly builds parameters for a fully-populated geo lookup." , function ( ) {
122174 let mockSender = new MockSender ( ) ;
123175 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" ) ;
125177
126178 let expectedParameters = {
127179 include : "1" ,
@@ -134,6 +186,38 @@ describe("A US Enrichment Client", function () {
134186 expect ( mockSender . request . parameters ) . to . deep . equal ( expectedParameters ) ;
135187 } ) ;
136188
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+
137221 it ( "throws an error if sending without a principal lookup." , function ( ) {
138222 let mockSender = new MockSender ( ) ;
139223 let client = new Client ( mockSender ) ;
@@ -152,13 +236,27 @@ describe("A US Enrichment Client", function () {
152236 expect ( client . sendGeo ) . to . throw ( errors . UndefinedLookupError ) ;
153237 } ) ;
154238
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+
155251 it ( "rejects with an exception if the principal response comes back with an error." , function ( ) {
156252 let expectedError = new Error ( "I'm the error." ) ;
157253 let mockSender = new MockSenderWithResponse ( "" , expectedError ) ;
158254 let client = new Client ( mockSender ) ;
159255 let lookup = new Lookup ( "¯\\_(ツ)_/¯" ) ;
160256
161- return client . sendPrincipal ( lookup ) . catch ( ( e ) => { expect ( e ) . to . equal ( expectedError ) ; } ) ;
257+ return client . sendPrincipal ( lookup ) . catch ( ( e ) => {
258+ expect ( e ) . to . equal ( expectedError ) ;
259+ } ) ;
162260 } ) ;
163261
164262 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 () {
167265 let client = new Client ( mockSender ) ;
168266 let lookup = new Lookup ( "¯\\_(ツ)_/¯" ) ;
169267
170- return client . sendFinancial ( lookup ) . catch ( ( e ) => { expect ( e ) . to . equal ( expectedError ) ; } ) ;
268+ return client . sendFinancial ( lookup ) . catch ( ( e ) => {
269+ expect ( e ) . to . equal ( expectedError ) ;
270+ } ) ;
171271 } ) ;
172272
173273 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 () {
176276 let client = new Client ( mockSender ) ;
177277 let lookup = new Lookup ( "¯\\_(ツ)_/¯" ) ;
178278
179- return client . sendGeo ( lookup ) . catch ( ( e ) => { expect ( e ) . to . equal ( expectedError ) ; } ) ;
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+ } ) ;
180304 } ) ;
181305
182306 it ( "returns an empty array when no principal respo are returned." , ( ) => {
@@ -209,6 +333,26 @@ describe("A US Enrichment Client", function () {
209333 } ) ;
210334 } ) ;
211335
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+
212356 it ( "attaches response to a principal lookup." , function ( ) {
213357 const rawMockResponse = {
214358 smarty_key : "a" ,
@@ -268,4 +412,44 @@ describe("A US Enrichment Client", function () {
268412 expect ( lookup . response ) . to . deep . equal ( mockResponse ) ;
269413 } ) ;
270414 } )
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+ } )
271455} ) ;
0 commit comments