forked from supercoolpeople/hatchjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.test.js
96 lines (88 loc) · 3.05 KB
/
search.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var should = require('./');
var app, compound, Content;
describe('API/search', function() {
before(function(done) {
var db = 9;
var queue = [];
app = getApp(function() {
for (var i = 0; i < db; i++) {
(function(n) {
queue.push(function() {
client.select(n, function() {
client.del('global:word:KRKSHN', function(err, x) {
next();
});
});
});
})(i);
}
next();
});
compound = app.compound;
Content = compound.models.Content;
var client = Content.schema.adapter.client;
function next() {
var fn = queue.shift();
if (fn) {
fn();
} else {
client.select(1, done);
}
}
});
it.skip('should use another database for search index', function(done) {
var client = Content.schema.adapter.client;
var db = 9;
var queue = [];
Content.create({title: 'Shiva', text: 'Krishna', createdAt: new Date}, function(err, c) {
for (var i = 0; i < db; i++) {
(function(n) {
queue.push(function() {
checkDb(n);
});
})(i);
}
setTimeout(next, 1500);
});
function checkDb(num) {
client.select(num, function() {
client.exists('global:word:KRKSHN', function(err, x) {
x.should.equal(num === 5 ? 1 : 0, 'on database ' + num);
next();
});
});
}
function next() {
var fn = queue.shift();
if (fn) {
fn();
} else {
client.select(1, done);
}
}
});
it('should reindex search data on save', function(done) {
Content.create({title: 'Tattam', text: 'Hame', createdAt: new Date}, function (err, c) {
should.not.exist(err);
setTimeout(function() {
Content.all({fulltext: 'Tattam'}, function (err, data) {
should.not.exist(err);
data.should.have.lengthOf(1);
c.title = 'Manana';
c.save(function(err) {
should.not.exist(err);
setTimeout(function() {
Content.all({fulltext: 'Tattam'}, function (err, data) {
data.should.have.lengthOf(0);
Content.all({fulltext: 'Manana'}, function (err, data) {
data.should.have.lengthOf(1);
done();
});
});
}, 500);
});
});
}, 500);
});
});
});