22
33var assert = require ( 'assert' ) ;
44var watson = require ( '../lib/index' ) ;
5- var nock = require ( 'nock' ) ;
6- var fs = require ( 'fs' ) ;
7- var url = require ( 'url' ) ;
5+ var nock = require ( 'nock' ) ;
6+ var fs = require ( 'fs' ) ;
7+ var url = require ( 'url' ) ;
8+
9+ var noop = function ( ) { } ;
810
911describe ( 'retrieve_and_rank' , function ( ) {
10- var clusterId = 'scffffffff_ffff_ffff_ffff_ffffffffffff' ;
11- var configName = 'test_config' ;
12+ var clusterId = 'scffffffff_ffff_ffff_ffff_ffffffffffff' ;
13+ var configName = 'test_config' ;
1214 var collectionName = 'test_collection' ;
13- var serviceUrl = 'http://retrieve-and-rank-service.com/path/to/service' ;
15+ var serviceUrl = 'http://retrieve-and-rank-service.com/path/to/service' ;
1416
15- var solrClustersPath = '/v1/solr_clusters' ;
16- var listResponse = 'list response' ;
17+ var solrClustersPath = '/v1/solr_clusters' ;
18+ var listResponse = 'list response' ;
1719 var deleteAllResponse = 'delete all response' ;
18- var createResponse = 'create response' ;
20+ var createResponse = 'create response' ;
1921
2022 var solrClusterPath = '/v1/solr_clusters/' + clusterId ;
21- var pollResponse = 'poll response' ;
22- var deleteResponse = 'delete response' ;
23+ var pollResponse = 'poll response' ;
24+ var deleteResponse = 'delete response' ;
2325
24- var configsPath = '/v1/solr_clusters/' + clusterId + '/config' ;
25- var configPath = configsPath + '/' + configName ;
26- var configListResponse = 'config list response' ;
26+ var configsPath = '/v1/solr_clusters/' + clusterId + '/config' ;
27+ var configPath = configsPath + '/' + configName ;
28+ var configListResponse = 'config list response' ;
2729 var configUploadResponse = 'config upload response' ;
28- var configGetResponse = 'config get response' ;
30+ var configGetResponse = 'config get response' ;
2931 var configDeleteResponse = 'config delete response' ;
3032
31- var collectionsPath = '/v1/solr_clusters/' + clusterId + '/solr/admin/collections' ;
33+ var collectionsPath = '/v1/solr_clusters/' + clusterId + '/solr/admin/collections' ;
3234 var collectionCreateResponse = 'collection create' ;
33- var collectionListResponse = 'collection list' ;
35+ var collectionListResponse = 'collection list' ;
3436 var collectionDeleteResponse = 'collection delete' ;
3537
3638 var service = {
@@ -62,19 +64,19 @@ describe('retrieve_and_rank', function() {
6264 . delete ( solrClustersPath ) . reply ( 200 , deleteAllResponse )
6365 . post ( solrClustersPath ) . reply ( 200 , createResponse )
6466
65- . get ( solrClusterPath ) . reply ( 200 , pollResponse )
67+ . get ( solrClusterPath ) . reply ( 200 , pollResponse )
6668 . delete ( solrClusterPath ) . reply ( 200 , deleteResponse )
6769
68- . get ( configsPath ) . reply ( 200 , configListResponse )
70+ . get ( configsPath ) . reply ( 200 , configListResponse )
6971 . post ( configPath ) . reply ( 200 , configUploadResponse )
7072 . get ( configPath ) . reply ( 200 , configGetResponse )
7173 . delete ( configPath ) . reply ( 200 , configDeleteResponse )
7274
73- . get ( collectionsPath + '?action=CREATE&name=' + collectionName + '&collection.configName=' + configName )
74- . reply ( 200 , collectionCreateResponse )
75+ . get ( collectionsPath + '?action=CREATE&name=' + collectionName + '&collection.configName=' + configName )
76+ . reply ( 200 , collectionCreateResponse )
7577 . get ( collectionsPath + '?action=LIST' ) . reply ( 200 , collectionListResponse )
7678 . get ( collectionsPath + '?action=DELETE&name=' + collectionName )
77- . reply ( 200 , collectionDeleteResponse ) ;
79+ . reply ( 200 , collectionDeleteResponse ) ;
7880 } ) ;
7981
8082 after ( function ( ) {
@@ -109,15 +111,17 @@ describe('retrieve_and_rank', function() {
109111 some_other_option : 'some_other_value'
110112 } ;
111113
112- var response = search . createCluster ( createParams , function ( error , data ) { } ) ;
114+ var response = search . createCluster ( createParams , noop ) ;
113115
114116 assert . equal ( response . headers [ 'Content-Type' ] , 'application/json' ) ;
115117 assert . deepEqual ( JSON . parse ( response . body ) , createParams ) ;
116118 done ( ) ;
117119 } ) ;
118120
119121 it ( 'can poll a Solr cluster' , function ( done ) {
120- search . pollCluster ( { clusterId : clusterId } , function ( error , data ) {
122+ search . pollCluster ( {
123+ clusterId : clusterId
124+ } , function ( error , data ) {
121125 assert . equal ( data , pollResponse ) ;
122126 done ( ) ;
123127 } ) ;
@@ -128,7 +132,9 @@ describe('retrieve_and_rank', function() {
128132 } ) ;
129133
130134 it ( 'can delete a Solr cluster' , function ( done ) {
131- search . deleteCluster ( { clusterId : clusterId } , function ( error , data ) {
135+ search . deleteCluster ( {
136+ clusterId : clusterId
137+ } , function ( error , data ) {
132138 assert . equal ( data , deleteResponse ) ;
133139 done ( ) ;
134140 } ) ;
@@ -139,7 +145,9 @@ describe('retrieve_and_rank', function() {
139145 } ) ;
140146
141147 it ( 'can list Solr configs' , function ( done ) {
142- search . listConfigs ( { clusterId : clusterId } , function ( error , data ) {
148+ search . listConfigs ( {
149+ clusterId : clusterId
150+ } , function ( error , data ) {
143151 assert . equal ( data , configListResponse ) ;
144152 done ( ) ;
145153 } ) ;
@@ -151,17 +159,24 @@ describe('retrieve_and_rank', function() {
151159
152160 it ( 'can upload a Solr config' , function ( done ) {
153161 var mockConfigFile = 'test/resources/mock_solr_config_file.zip' ;
154- var response = search . uploadConfig ( { clusterId : clusterId , configName : configName , configZipPath : mockConfigFile } ,
162+ search . uploadConfig ( {
163+ clusterId : clusterId ,
164+ configName : configName ,
165+ configZipPath : mockConfigFile
166+ } ,
155167 function ( error , data ) {
156- assert . equal ( data , configUploadResponse ) ;
157- done ( ) ;
158- } ) ;
168+ assert . equal ( data , configUploadResponse ) ;
169+ done ( ) ;
170+ } ) ;
159171 } ) ;
160172
161173 it ( 'sets headers and body of request when uploading a Solr config' , function ( done ) {
162174 var mockConfigFile = 'test/resources/mock_solr_config_file.zip' ;
163- var response = search . uploadConfig ( { clusterId : clusterId , configName : configName , configZipPath : mockConfigFile } ,
164- function ( error , data ) { } ) ;
175+ var response = search . uploadConfig ( {
176+ clusterId : clusterId ,
177+ configName : configName ,
178+ configZipPath : mockConfigFile
179+ } , noop ) ;
165180
166181 assert . equal ( response . headers [ 'Content-Type' ] , 'application/zip' ) ;
167182 assert . deepEqual ( response . body , fs . readFileSync ( mockConfigFile ) ) ;
@@ -173,15 +188,23 @@ describe('retrieve_and_rank', function() {
173188 } ) ;
174189
175190 it ( 'returns error when configName is not specified on upload config request' , function ( ) {
176- search . uploadConfig ( { clusterId : clusterId } , missingConfigName ) ;
191+ search . uploadConfig ( {
192+ clusterId : clusterId
193+ } , missingConfigName ) ;
177194 } ) ;
178195
179196 it ( 'returns error when configZipPath is not specified on upload config request' , function ( ) {
180- search . uploadConfig ( { clusterId : clusterId , configName : configName } , missingConfigZipPath ) ;
197+ search . uploadConfig ( {
198+ clusterId : clusterId ,
199+ configName : configName
200+ } , missingConfigZipPath ) ;
181201 } ) ;
182202
183203 it ( 'can get a Solr config' , function ( done ) {
184- search . getConfig ( { clusterId : clusterId , configName : configName } , function ( error , data ) {
204+ search . getConfig ( {
205+ clusterId : clusterId ,
206+ configName : configName
207+ } , function ( error , data ) {
185208 assert . equal ( data , configGetResponse ) ;
186209 done ( ) ;
187210 } ) ;
@@ -192,11 +215,16 @@ describe('retrieve_and_rank', function() {
192215 } ) ;
193216
194217 it ( 'returns error when configName is not specified on get config request' , function ( ) {
195- search . getConfig ( { clusterId : clusterId } , missingConfigName ) ;
218+ search . getConfig ( {
219+ clusterId : clusterId
220+ } , missingConfigName ) ;
196221 } ) ;
197222
198223 it ( 'can delete a Solr config' , function ( done ) {
199- search . deleteConfig ( { clusterId : clusterId , configName : configName } , function ( error , data ) {
224+ search . deleteConfig ( {
225+ clusterId : clusterId ,
226+ configName : configName
227+ } , function ( error , data ) {
200228 assert . equal ( data , configDeleteResponse ) ;
201229 done ( ) ;
202230 } ) ;
@@ -207,31 +235,44 @@ describe('retrieve_and_rank', function() {
207235 } ) ;
208236
209237 it ( 'returns error when configName is not specified on delete config request' , function ( ) {
210- search . deleteConfig ( { clusterId : clusterId } , missingConfigName ) ;
238+ search . deleteConfig ( {
239+ clusterId : clusterId
240+ } , missingConfigName ) ;
211241 } ) ;
212242
213243 it ( 'can create a Solr collection' , function ( done ) {
214- search . createCollection ( { clusterId : clusterId , collectionName : collectionName , configName : configName } ,
244+ search . createCollection ( {
245+ clusterId : clusterId ,
246+ collectionName : collectionName ,
247+ configName : configName
248+ } ,
215249 function ( error , data ) {
216- assert . equal ( data , collectionCreateResponse ) ;
217- done ( ) ;
218- } ) ;
250+ assert . equal ( data , collectionCreateResponse ) ;
251+ done ( ) ;
252+ } ) ;
219253 } ) ;
220254
221255 it ( 'returns error when clusterId is not specified on create collection request' , function ( ) {
222256 search . createCollection ( { } , missingClusterId ) ;
223257 } ) ;
224258
225259 it ( 'returns error when collectionName is not specified on create collection request' , function ( ) {
226- search . createCollection ( { clusterId : clusterId } , missingCollectionName ) ;
260+ search . createCollection ( {
261+ clusterId : clusterId
262+ } , missingCollectionName ) ;
227263 } ) ;
228264
229265 it ( 'returns error when configName is not specified on create collection request' , function ( ) {
230- search . createCollection ( { clusterId : clusterId , collectionName : collectionName } , missingConfigName ) ;
266+ search . createCollection ( {
267+ clusterId : clusterId ,
268+ collectionName : collectionName
269+ } , missingConfigName ) ;
231270 } ) ;
232271
233272 it ( 'can list Solr collections' , function ( done ) {
234- search . listCollections ( { clusterId : clusterId } , function ( error , data ) {
273+ search . listCollections ( {
274+ clusterId : clusterId
275+ } , function ( error , data ) {
235276 assert . equal ( data , collectionListResponse ) ;
236277 done ( ) ;
237278 } ) ;
@@ -242,7 +283,10 @@ describe('retrieve_and_rank', function() {
242283 } ) ;
243284
244285 it ( 'can delete a Solr collection' , function ( done ) {
245- search . deleteCollection ( { clusterId : clusterId , collectionName : collectionName } , function ( error , data ) {
286+ search . deleteCollection ( {
287+ clusterId : clusterId ,
288+ collectionName : collectionName
289+ } , function ( error , data ) {
246290 assert . equal ( data , collectionDeleteResponse ) ;
247291 done ( ) ;
248292 } ) ;
@@ -253,11 +297,16 @@ describe('retrieve_and_rank', function() {
253297 } ) ;
254298
255299 it ( 'returns error when collectionName is not specified on delete collection request' , function ( ) {
256- search . deleteCollection ( { clusterId : clusterId } , missingCollectionName ) ;
300+ search . deleteCollection ( {
301+ clusterId : clusterId
302+ } , missingCollectionName ) ;
257303 } ) ;
258304
259305 it ( 'can create a Solr client using passed in params' , function ( ) {
260- var solrClient = search . createSolrClient ( { clusterId : clusterId , collectionName : collectionName } ) ;
306+ var solrClient = search . createSolrClient ( {
307+ clusterId : clusterId ,
308+ collectionName : collectionName
309+ } ) ;
261310 var parsedUrl = url . parse ( serviceUrl ) ;
262311
263312 assert . equal ( solrClient . options . host , parsedUrl . hostname ) ;
@@ -279,10 +328,12 @@ describe('retrieve_and_rank', function() {
279328 it ( 'returns error when collectionName is not specified when building Solr client' , function ( ) {
280329 assert . throws (
281330 function ( ) {
282- search . createSolrClient ( { clusterId : clusterId } ) ;
331+ search . createSolrClient ( {
332+ clusterId : clusterId
333+ } ) ;
283334 } ,
284335 / r e q u i r e d p a r a m e t e r : c o l l e c t i o n N a m e /
285336 ) ;
286337 } ) ;
287338
288- } ) ;
339+ } ) ;
0 commit comments