// Dependencies 
var nock = require('nock'), 
   solr = require('./../main'),
   vows = require('vows'),
   assert = require('assert'),
   mocks = require('./mocks'),
   fs = require('fs');

// Load configuration file
var config = JSON.parse(fs.readFileSync(__dirname + '/config.json'));

if(config.mocked){
   //nock.recorder.rec();
   mocks.facet(nock);
}

// Suite Test

var suite = vows.describe('Solr Client API: facet');

suite.addBatch({
   'Create a facet' : {
      'with the following options: `field`, `prefix`, `query`, `limit`, `offset`, `sort`, `limit`, `mincount`, `missing`, `method`' : {
         topic : function(){
            var client = solr.createClient();
            var query = client.createQuery()
                           .q({'*' : '*'})
                           .rows(0)
                           .facet({
                              field : 'title',
                              prefix : 'Ipa',
                              query : 'title:Ipad',
                              limit : 20,
                              offset : 0,
                              sort : 'count',
                              mincount : 0,
                              missing : false,
                              method : 'fc' ,
                           }); 
            client.search(query,this.callback);
         },
         'should return a correct response without error' :function(err,res) {
            assertCorrectResponse(err,res)
         }
      }
   }
}).export(module);

// Macro

function assertCorrectResponse(err,data){
   assert.isNull(err);
   assert.isObject(data);
   assert.equal(data.responseHeader.status,0);  
}

// Dependencies 
var nock = require('nock'), 
   solr = require('./../main'),
   vows = require('vows'),
   assert = require('assert'),
   mocks = require('./mocks'),
   fs = require('fs');

// Load configuration file
var config = JSON.parse(fs.readFileSync(__dirname + '/config.json'));

if(config.mocked){
   //nock.recorder.rec();
   mocks.facet(nock);
}

// Suite Test

var suite = vows.describe('Solr Client API: facet');

suite.addBatch({
   'Create a facet' : {
      'with the following options: `field`, `prefix`, `query`, `limit`, `offset`, `sort`, `limit`, `mincount`, `missing`, `method`' : {
         topic : function(){
            var client = solr.createClient();
            var query = client.createQuery()
                           .q('*:*')
                           .rows(0)
                           .facet({
                              field : 'title',
                              prefix : 'Ipa',
                              query : 'title:Ipad',
                              limit : 20,
                              offset : 0,
                              sort : 'count',
                              mincount : 0,
                              missing : false,
                              method : 'fc' ,
                           });
            client.search(query,this.callback);
         },
         'should return a correct response without error' :function(err,res) {
            assertCorrectResponse(err,res)
         }
      }
   }
}).export(module);

// Macro

function assertCorrectResponse(err,data){
   assert.isNull(err);
   assert.isObject(data);
   assert.equal(data.responseHeader.status,0);  
}

Use a string in `q` instead of an object because special characters in the values of each key of an object are now escaped as expected.
FIX: Use a string in `q` instead of an object because special characters in the values of each key of an object are now escaped as expected.
