|
1
|
|
|
var chai = require('chai'); |
|
2
|
|
|
|
|
3
|
|
|
var config = require('../src/cli').config |
|
4
|
|
|
config.set({root: __dirname + '/fixtures'}) |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
var Sql = require('../src/cli').Sql |
|
7
|
|
|
var Util = require('../src/cli').Util |
|
8
|
|
|
var fileAttr = require('../src/cli').fileAttr |
|
9
|
|
|
var Manager = require('../src/cli').Manager; |
|
10
|
|
|
var fse = require('fs-extra'); |
|
11
|
|
|
|
|
12
|
|
|
describe('Request', function() { |
|
13
|
|
|
before( function(done) { |
|
14
|
|
|
Manager.instance.init() |
|
15
|
|
|
.then(function () { |
|
16
|
|
|
this.fixture = { |
|
17
|
|
|
tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'), |
|
|
|
|
|
|
18
|
|
|
json: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json') |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
done() |
|
21
|
|
|
|
|
22
|
|
|
}.bind(this)) |
|
23
|
|
|
}); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Sql.getAllAttributes |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
it('Util.getAllAttributes()', function(done) { |
|
30
|
|
|
var attributes = Util.getAllAttributes(this.fixture.tag, this.fixture.json) |
|
31
|
|
|
chai.assert.equal(attributes.sourceString, 'select abe_meta from ./', 'sourceString is ok') |
|
32
|
|
|
done(); |
|
33
|
|
|
}); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Sql.executeQuery |
|
37
|
|
|
* |
|
38
|
|
|
*/ |
|
39
|
|
|
it('Sql.executeQuery()', function(done) { |
|
40
|
|
|
try { |
|
41
|
|
|
var match = 'select * from ../' |
|
42
|
|
|
var jsonPage = {} |
|
|
|
|
|
|
43
|
|
|
var res = Sql.handleSqlRequest(match, {}) |
|
44
|
|
|
|
|
45
|
|
|
chai.assert.equal(res.string, 'select ["*"] from ["___abe_dot______abe_dot______abe___"] ', 'select not well formatted') |
|
46
|
|
|
done(); |
|
47
|
|
|
} catch (x) { |
|
48
|
|
|
done(x); |
|
49
|
|
|
} |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Sql.executeFromClause |
|
54
|
|
|
* |
|
55
|
|
|
*/ |
|
56
|
|
|
it('Sql.executeFromClause()', function() { |
|
57
|
|
|
var res = Sql.executeFromClause(['/'], ['/']) |
|
58
|
|
|
chai.expect(res).to.have.length(2); |
|
59
|
|
|
}); |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Sql.executeWhereClause |
|
63
|
|
|
* |
|
64
|
|
|
*/ |
|
65
|
|
|
it('Sql.executeWhereClause()', function() { |
|
66
|
|
|
var where = [{ left: 'template', right: 'article', compare: '=', operator: '' }] |
|
67
|
|
|
|
|
68
|
|
|
var res = Sql.executeWhereClause(Manager.instance.getList(), where, -1, ['*'], {}) |
|
69
|
|
|
|
|
70
|
|
|
chai.expect(res).to.have.length(1); |
|
71
|
|
|
}); |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Sql.whereEquals |
|
75
|
|
|
* |
|
76
|
|
|
*/ |
|
77
|
|
|
it('Sql.whereEquals()', function() { |
|
78
|
|
|
var article = fileAttr.getDocumentRevision('article-1.json') |
|
79
|
|
|
|
|
80
|
|
|
chai.expect(article) |
|
81
|
|
|
.to.deep.equal( |
|
82
|
|
|
Sql.whereEquals( |
|
83
|
|
|
[{ left: 'template' }], |
|
84
|
|
|
article.abe_meta.template, |
|
85
|
|
|
"article", |
|
86
|
|
|
article |
|
87
|
|
|
) |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
chai.expect(article) |
|
91
|
|
|
.to.not.deep.equal( |
|
92
|
|
|
Sql.whereEquals( |
|
93
|
|
|
[{ left: 'template' }], |
|
94
|
|
|
article.abe_meta.template, |
|
95
|
|
|
"homepage", |
|
96
|
|
|
article |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
}); |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Sql.whereNotEquals |
|
103
|
|
|
* |
|
104
|
|
|
*/ |
|
105
|
|
|
it('Sql.whereNotEquals()', function() { |
|
106
|
|
|
var article = fileAttr.getDocumentRevision('article-1.json') |
|
107
|
|
|
|
|
108
|
|
|
chai.expect(article) |
|
109
|
|
|
.to.deep.equal( |
|
110
|
|
|
Sql.whereNotEquals( |
|
111
|
|
|
[{ left: 'template' }], |
|
112
|
|
|
article.abe_meta.template, |
|
113
|
|
|
"homepage", |
|
114
|
|
|
article |
|
115
|
|
|
) |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
chai.expect(article) |
|
119
|
|
|
.to.not.deep.equal( |
|
120
|
|
|
Sql.whereNotEquals( |
|
121
|
|
|
[{ left: 'template' }], |
|
122
|
|
|
article.abe_meta.template, |
|
123
|
|
|
"article", |
|
124
|
|
|
article |
|
125
|
|
|
) |
|
126
|
|
|
); |
|
127
|
|
|
}); |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Sql.whereLike |
|
131
|
|
|
* |
|
132
|
|
|
*/ |
|
133
|
|
|
it('Sql.whereLike()', function() { |
|
134
|
|
|
var article = fileAttr.getDocumentRevision('article-1.json') |
|
135
|
|
|
|
|
136
|
|
|
chai.expect(article) |
|
137
|
|
|
.to.deep.equal( |
|
138
|
|
|
Sql.whereLike( |
|
139
|
|
|
[{ left: 'template' }], |
|
140
|
|
|
article.abe_meta.template, |
|
141
|
|
|
"art", |
|
142
|
|
|
article |
|
143
|
|
|
) |
|
144
|
|
|
); |
|
145
|
|
|
|
|
146
|
|
|
chai.expect(article) |
|
147
|
|
|
.to.not.deep.equal( |
|
148
|
|
|
Sql.whereLike( |
|
149
|
|
|
[{ left: 'template' }], |
|
150
|
|
|
article.abe_meta.template, |
|
151
|
|
|
"hom", |
|
152
|
|
|
article |
|
153
|
|
|
) |
|
154
|
|
|
); |
|
155
|
|
|
}); |
|
156
|
|
|
}); |
|
157
|
|
|
|