1 |
|
2 | var nock = require('nock'),
|
3 | solr = require('./../main'),
|
4 | vows = require('vows'),
|
5 | assert = require('assert'),
|
6 | fs = require('fs'),
|
7 | mocks = require('./mocks');
|
8 |
|
9 |
|
10 | var config = JSON.parse(fs.readFileSync(__dirname + '/config.json'));
|
11 |
|
12 | if(config.mocked){
|
13 |
|
14 | mocks.deleteByRange(nock);
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var suite = vows.describe('Solr Client API: deleteByRange command');
|
32 |
|
33 |
|
34 | var today = new Date('2012-05-07T21:50:08.309Z');
|
35 | var yesterday = new Date('2012-05-06T21:50:08.309Z');
|
36 | var beforeYesterday = new Date('2012-05-05T21:50:08.309Z');
|
37 |
|
38 | suite.addBatch({
|
39 | 'Add 20 documents' : {
|
40 | 'with fields last_update_dt and title_t' : {
|
41 | topic : function(){
|
42 | var client = solr.createClient();
|
43 | client.autoCommit = true;
|
44 | var date = today;
|
45 | var docs = new Array(20);
|
46 | for( var i = 0; i < 20 ; i++){
|
47 | if( i >= 10){
|
48 | date = beforeYesterday;
|
49 | }
|
50 | docs[i] = {
|
51 | id : i,
|
52 | title_t : 'test',
|
53 | last_update_dt : date
|
54 | }
|
55 | }
|
56 | client.add(docs,this.callback);
|
57 | },
|
58 | 'should works' : function(err,res){
|
59 | assertCorrectResponse(err,res);
|
60 | }
|
61 | }
|
62 | }
|
63 | }).addBatch({
|
64 | 'Delete documents' : {
|
65 | 'between yesterday and today' : {
|
66 | topic : function(){
|
67 | var client = solr.createClient();
|
68 | client.deleteByRange('last_update_dt',yesterday,today,this.callback);
|
69 | },
|
70 | 'should works' : function(err,res){
|
71 | assertCorrectResponse(err,res);
|
72 | }
|
73 | }
|
74 | }
|
75 | }).addBatch({
|
76 | 'Commit change' : {
|
77 | 'to see effect of the deleteByRange command' : {
|
78 | topic : function(){
|
79 | var client = solr.createClient();
|
80 | client.commit(this.callback);
|
81 | },
|
82 | 'should works' : function(err,res){
|
83 | assertCorrectResponse(err,res);
|
84 | }
|
85 | }
|
86 | }
|
87 | }).addBatch({
|
88 | 'Query all documents' : {
|
89 | 'where title_t === `test`' : {
|
90 | topic : function(){
|
91 | var client = solr.createClient();
|
92 | var query = client.createQuery().q({title_t : 'test'}).start(0).rows(10);
|
93 | client.search(query,this.callback);
|
94 | },
|
95 | 'should find 10 documents' : function(err,data){
|
96 | assert.isNull(err);
|
97 | assert.equal(data.response.numFound,10);
|
98 | }
|
99 | }
|
100 | }
|
101 | }).export(module);
|
102 |
|
103 |
|
104 |
|
105 | function assertCorrectResponse(err,data){
|
106 | assert.isNull(err);
|
107 | assert.isObject(data);
|
108 | assert.equal(data.responseHeader.status,0);
|
109 | }
|