UNPKG

1.74 kBJavaScriptView Raw
1// Dependencies
2var nock = require('nock'),
3 solr = require('./../main'),
4 vows = require('vows'),
5 assert = require('assert');
6 mocks = require('./mocks'),
7 fs = require('fs');
8
9// Load configuration file
10var config = JSON.parse(fs.readFileSync(__dirname + '/config.json'));
11
12if(config.mocked){
13 //nock.recorder.rec();
14 mocks.group(nock);
15}
16
17// Suite Test
18
19var suite = vows.describe('Solr Client API: group command');
20
21suite.addBatch({
22 'Grouping Result' : {
23 'with a field' : {
24 topic : function(){
25 var client = solr.createClient();
26 var query = client.createQuery().q({ description : 'laptop'}).groupBy('title') ;
27 client.search(query,this.callback);
28 },
29 'should be possible' : function(err,res){
30 assertCorrectResponse(err,res);
31 }
32 },
33 'with all availables options: field, limit,offset,sort,format,main,ngroups,truncate,cache' : {
34 topic : function(){
35 var client = solr.createClient();
36 var query = client.createQuery().q({description : 'laptop'}).group({
37 field : 'title',
38 limit : 20,
39 offset : 0,
40 sort : 'score asc',
41 format : 'grouped',
42 main : false,
43 ngroups : true,
44 truncate : false,
45 cache : 0
46 });
47 client.search(query,this.callback);
48 },
49 'should be possible' :function(err,res) {
50 assertCorrectResponse(err,res)
51 }
52 }
53 }
54}).export(module);
55
56// Macro
57
58function assertCorrectResponse(err,data){
59 assert.isNull(err);
60 assert.isObject(data);
61 assert.equal(data.responseHeader.status,0);
62}