|
1
|
|
|
var chai = require('chai'); |
|
2
|
|
|
var sinonChai = require('sinon-chai') |
|
3
|
|
|
var expect = chai.expect |
|
4
|
|
|
chai.use(sinonChai) |
|
5
|
|
|
var sinon = require('sinon'); |
|
6
|
|
|
var path = require('path'); |
|
7
|
|
|
var fse = require('fs-extra'); |
|
8
|
|
|
|
|
9
|
|
|
var config = require('../../../src/cli').config |
|
10
|
|
|
config.set({root: path.join(process.cwd(), 'test', 'fixtures')}) |
|
11
|
|
|
|
|
12
|
|
|
var abeExtend = require('../../../src/cli').abeExtend; |
|
13
|
|
|
var cmsData = require('../../../src/cli').cmsData; |
|
14
|
|
|
var cmsTemplates = require('../../../src/cli').cmsTemplates; |
|
15
|
|
|
var coreUtils = require('../../../src/cli').coreUtils; |
|
16
|
|
|
var Manager = require('../../../src/cli').Manager; |
|
17
|
|
|
|
|
18
|
|
|
describe('cmsTemplates', function() { |
|
19
|
|
|
before( function(done) { |
|
20
|
|
|
Manager.instance.init() |
|
21
|
|
|
.then(function () { |
|
22
|
|
|
this.fixture = { |
|
23
|
|
|
slug: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'slug.html'), 'utf-8'), |
|
24
|
|
|
article: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article.html'), 'utf-8'), |
|
25
|
|
|
local: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'local.html'), 'utf-8'), |
|
26
|
|
|
articleSingleAbe: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-single-abe.html'), 'utf-8'), |
|
27
|
|
|
articleRequest: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-request.html'), 'utf-8'), |
|
28
|
|
|
template: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'import.html'), 'utf-8'), |
|
29
|
|
|
articleEach: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-each-abe.html'), 'utf-8'), |
|
30
|
|
|
articlePrecontrib: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-precontribution.html'), 'utf-8'), |
|
31
|
|
|
templateKeys: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-keys.html'), 'utf-8'), |
|
32
|
|
|
templatePaths: path.join(process.cwd(), 'test', 'fixtures', 'templates', 'templates/article.html'), |
|
33
|
|
|
structurePaths: path.join(process.cwd(), 'test', 'fixtures', 'templates', 'templates/structure/0-1'), |
|
34
|
|
|
import: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'import.html'), 'utf-8'), |
|
35
|
|
|
count: 0 |
|
36
|
|
|
} |
|
37
|
|
|
done() |
|
38
|
|
|
|
|
39
|
|
|
}.bind(this)) |
|
40
|
|
|
}); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* cmsTemplates.template.getTemplatesAndPartials |
|
44
|
|
|
* |
|
45
|
|
|
*/ |
|
46
|
|
|
it('cmsTemplates.template.getTemplatesAndPartials()', function(done) { |
|
47
|
|
|
// stub |
|
48
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
49
|
|
|
var getFilesAsync = sinonInstance.stub(coreUtils.file, 'getFilesAsync'); |
|
50
|
|
|
getFilesAsync.returns(Promise.resolve([this.fixture.article])) |
|
51
|
|
|
|
|
52
|
|
|
// test |
|
53
|
|
|
cmsTemplates.template.getTemplatesAndPartials(this._pathTemplate) |
|
54
|
|
|
.then((templatesList) => { |
|
55
|
|
|
chai.expect(templatesList.length).to.be.equal(1); |
|
56
|
|
|
done() |
|
57
|
|
|
|
|
58
|
|
|
// unstub |
|
59
|
|
|
sinon.assert.calledOnce(coreUtils.file.getFilesAsync) |
|
60
|
|
|
coreUtils.file.getFilesAsync.restore() |
|
61
|
|
|
}) |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* |
|
66
|
|
|
* |
|
67
|
|
|
*/ |
|
68
|
|
|
it('cmsTemplates.template.addOrder()', function() { |
|
69
|
|
|
// stub |
|
70
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
71
|
|
|
var getAttr = sinonInstance.stub(cmsData.regex, 'getAttr'); |
|
72
|
|
|
getAttr.returns(null) |
|
73
|
|
|
|
|
74
|
|
|
// test |
|
75
|
|
|
var html = cmsTemplates.template.addOrder(this.fixture.articleSingleAbe) |
|
76
|
|
|
chai.expect(html).to.not.be.equal(this.fixture.articleSingleAbe); |
|
77
|
|
|
chai.expect(html.indexOf('order')).to.above(-1); |
|
78
|
|
|
|
|
79
|
|
|
// unstub |
|
80
|
|
|
sinon.assert.calledOnce(cmsData.regex.getAttr) |
|
81
|
|
|
cmsData.regex.getAttr.restore() |
|
82
|
|
|
}); |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* cmsTemplates.template.getStructureAndTemplates |
|
86
|
|
|
* |
|
87
|
|
|
*/ |
|
88
|
|
|
it('cmsTemplates.template.getStructureAndTemplates()', function() { |
|
89
|
|
|
// stub |
|
90
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
91
|
|
|
var stubGetFoldersSync = sinonInstance.stub(coreUtils.file, 'getFoldersSync'); |
|
92
|
|
|
stubGetFoldersSync.returns({path: this.fixture.structurePaths, folders: []}) |
|
93
|
|
|
var stubGetFilesSync = sinonInstance.stub(coreUtils.file, 'getFilesSync'); |
|
94
|
|
|
stubGetFilesSync.returns([this.fixture.templatePaths]) |
|
95
|
|
|
|
|
96
|
|
|
// test |
|
97
|
|
|
var res = cmsTemplates.template.getStructureAndTemplates() |
|
98
|
|
|
chai.expect(res.templates.length).to.be.equal(1); |
|
99
|
|
|
|
|
100
|
|
|
// unstub |
|
101
|
|
|
sinon.assert.calledOnce(coreUtils.file.getFoldersSync) |
|
102
|
|
|
coreUtils.file.getFoldersSync.restore() |
|
103
|
|
|
sinon.assert.calledOnce(coreUtils.file.getFilesSync) |
|
104
|
|
|
coreUtils.file.getFilesSync.restore() |
|
105
|
|
|
}); |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* getAbeImport |
|
109
|
|
|
* |
|
110
|
|
|
*/ |
|
111
|
|
|
it('cmsTemplates.template.getAbeImport()', function() { |
|
112
|
|
|
var res = cmsTemplates.template.getAbeImport(this.fixture.template) |
|
113
|
|
|
chai.expect(res).to.have.length(1); |
|
114
|
|
|
}); |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* translate |
|
118
|
|
|
* |
|
119
|
|
|
*/ |
|
120
|
|
|
it('cmsTemplates.template.translate()', function() { |
|
121
|
|
|
// stub |
|
122
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
123
|
|
|
var getAttr = sinonInstance.stub(cmsData.regex, 'getAttr', function (math, type) { |
|
124
|
|
|
if (type === 'locale') { |
|
125
|
|
|
return 'gb' |
|
126
|
|
|
} |
|
127
|
|
|
if (type === 'source') { |
|
|
|
|
|
|
128
|
|
|
return 'test' |
|
129
|
|
|
} |
|
130
|
|
|
}); |
|
131
|
|
|
var escapeTextToRegex = sinonInstance.stub(cmsData.regex, 'escapeTextToRegex'); |
|
132
|
|
|
escapeTextToRegex.returns(new RegExp(this.fixture.local, 'g')) |
|
133
|
|
|
|
|
134
|
|
|
// test |
|
135
|
|
|
var res = cmsTemplates.template.translate(this.fixture.local) |
|
136
|
|
|
chai.expect(res.indexOf('i18nAbe')).to.above(-1); |
|
137
|
|
|
|
|
138
|
|
|
// unstub |
|
139
|
|
|
cmsData.regex.getAttr.restore() |
|
140
|
|
|
sinon.assert.calledOnce(cmsData.regex.escapeTextToRegex) |
|
141
|
|
|
cmsData.regex.escapeTextToRegex.restore() |
|
142
|
|
|
}); |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* getVariablesInWhere |
|
146
|
|
|
* |
|
147
|
|
|
*/ |
|
148
|
|
|
it('cmsTemplates.template.getVariablesInWhere()', function() { |
|
149
|
|
|
// stub |
|
150
|
|
|
|
|
151
|
|
|
// test |
|
152
|
|
|
var res = cmsTemplates.template.getVariablesInWhere({left: {column: 'title'}, right: {value: "test"}, operator: 'AND'}) |
|
153
|
|
|
chai.expect(res.length).to.above(-1); |
|
154
|
|
|
|
|
155
|
|
|
// unstub |
|
156
|
|
|
}); |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* recurseWhereVariables |
|
160
|
|
|
* |
|
161
|
|
|
*/ |
|
162
|
|
|
it('cmsTemplates.template.recurseWhereVariables()', function() { |
|
163
|
|
|
// stub |
|
164
|
|
|
|
|
165
|
|
|
// test |
|
166
|
|
|
var res = cmsTemplates.template.recurseWhereVariables({left: {column: 'title'}, right: {value: "test"}}) |
|
167
|
|
|
chai.expect(res.length).to.above(-1); |
|
168
|
|
|
|
|
169
|
|
|
// unstub |
|
170
|
|
|
}); |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* getTemplatesTexts |
|
174
|
|
|
* |
|
175
|
|
|
*/ |
|
176
|
|
|
it('cmsTemplates.template.getTemplatesTexts()', function(done) { |
|
177
|
|
|
// stub |
|
178
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
179
|
|
|
var readFileSync = sinonInstance.stub(fse, 'readFileSync'); |
|
180
|
|
|
readFileSync.returns("test") |
|
181
|
|
|
|
|
182
|
|
|
// test |
|
183
|
|
|
cmsTemplates.template.getTemplatesTexts(['test']) |
|
184
|
|
|
.then(function (res) { |
|
185
|
|
|
chai.expect(res[0].name).to.be.equal('test'); |
|
186
|
|
|
|
|
187
|
|
|
// unstub |
|
188
|
|
|
sinon.assert.calledOnce(fse.readFileSync) |
|
189
|
|
|
fse.readFileSync.restore() |
|
190
|
|
|
done() |
|
191
|
|
|
}) |
|
192
|
|
|
}); |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* includePartials |
|
196
|
|
|
* |
|
197
|
|
|
*/ |
|
198
|
|
|
it('cmsTemplates.template.includePartials()', function() { |
|
199
|
|
|
// stub |
|
200
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
201
|
|
|
var stubReadFileSync = sinonInstance.stub(fse, 'readFileSync'); |
|
202
|
|
|
stubReadFileSync.returns("test") |
|
203
|
|
|
var stubGetAbeImport = sinonInstance.stub(cmsTemplates.template, 'getAbeImport', function () { |
|
|
|
|
|
|
204
|
|
|
if (this.fixture.count === 0) { |
|
205
|
|
|
this.fixture.count++ |
|
206
|
|
|
return [this.fixture.import] |
|
207
|
|
|
} |
|
208
|
|
|
return [] |
|
209
|
|
|
}.bind(this)); |
|
210
|
|
|
var stubGetAll = sinonInstance.stub(cmsData.attributes, 'getAll'); |
|
211
|
|
|
stubGetAll.returns({file: 'import.html'}) |
|
212
|
|
|
var stubEscapeTextToRegex = sinonInstance.stub(cmsData.regex, 'escapeTextToRegex'); |
|
213
|
|
|
stubEscapeTextToRegex.returns(new RegExp(this.fixture.import, 'g')) |
|
214
|
|
|
var stubFile = sinonInstance.stub(coreUtils.file, 'exist', function () { |
|
|
|
|
|
|
215
|
|
|
return true |
|
216
|
|
|
}.bind(this)); |
|
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
// test |
|
219
|
|
|
var template = cmsTemplates.template.includePartials(this.fixture.template) |
|
220
|
|
|
chai.expect(template).to.be.equal("test"); |
|
221
|
|
|
|
|
222
|
|
|
// unstub |
|
223
|
|
|
sinon.assert.calledOnce(fse.readFileSync) |
|
224
|
|
|
fse.readFileSync.restore() |
|
225
|
|
|
sinon.assert.calledTwice(cmsTemplates.template.getAbeImport) |
|
226
|
|
|
cmsTemplates.template.getAbeImport.restore() |
|
227
|
|
|
sinon.assert.calledOnce(cmsData.attributes.getAll) |
|
228
|
|
|
cmsData.attributes.getAll.restore() |
|
229
|
|
|
sinon.assert.calledOnce(coreUtils.file.exist) |
|
230
|
|
|
coreUtils.file.exist.restore() |
|
231
|
|
|
sinon.assert.calledOnce(cmsData.regex.escapeTextToRegex) |
|
232
|
|
|
cmsData.regex.escapeTextToRegex.restore() |
|
233
|
|
|
}); |
|
234
|
|
|
|
|
235
|
|
|
it('cmsTemplates.template.includePartials()', function() { |
|
236
|
|
|
// stub |
|
237
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
238
|
|
|
var stubReadFileSync = sinonInstance.stub(fse, 'readFileSync'); |
|
239
|
|
|
stubReadFileSync.returns("test") |
|
240
|
|
|
|
|
241
|
|
|
var template = cmsTemplates.template.includePartials("{{test}}", {"test" : "ok.html"}) |
|
242
|
|
|
console.log(template) |
|
|
|
|
|
|
243
|
|
|
chai.expect(template).to.be.equal("test") |
|
244
|
|
|
}); |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* cmsTemplates.template.getTemplate |
|
248
|
|
|
* |
|
249
|
|
|
*/ |
|
250
|
|
|
it('cmsTemplates.template.getTemplate()', function() { |
|
251
|
|
|
// stub |
|
252
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
253
|
|
|
var stubReadFileSync = sinonInstance.stub(fse, 'readFileSync'); |
|
254
|
|
|
stubReadFileSync.returns(this.fixture.article) |
|
255
|
|
|
var stubTrigger = sinonInstance.stub(abeExtend.hooks.instance, 'trigger', function (p1, p2) { |
|
|
|
|
|
|
256
|
|
|
return p2 |
|
257
|
|
|
}) |
|
258
|
|
|
var stubExist = sinonInstance.stub(coreUtils.file, 'exist'); |
|
259
|
|
|
stubExist.returns(true) |
|
260
|
|
|
var stubIncludePartials = sinonInstance.stub(cmsTemplates.template, 'includePartials'); |
|
261
|
|
|
stubIncludePartials.returns(this.fixture.article) |
|
262
|
|
|
var stubTranslate = sinonInstance.stub(cmsTemplates.template, 'translate'); |
|
263
|
|
|
stubTranslate.returns(this.fixture.article) |
|
264
|
|
|
var stubAddOrder = sinonInstance.stub(cmsTemplates.template, 'addOrder'); |
|
265
|
|
|
stubAddOrder.returns(this.fixture.article) |
|
266
|
|
|
|
|
267
|
|
|
var template = cmsTemplates.template.getTemplate('article') |
|
268
|
|
|
chai.expect(template).to.be.equal(this.fixture.article); |
|
269
|
|
|
|
|
270
|
|
|
sinon.assert.calledOnce(fse.readFileSync) |
|
271
|
|
|
fse.readFileSync.restore() |
|
272
|
|
|
sinon.assert.calledTwice(abeExtend.hooks.instance.trigger) |
|
273
|
|
|
abeExtend.hooks.instance.trigger.restore() |
|
274
|
|
|
sinon.assert.calledOnce(coreUtils.file.exist) |
|
275
|
|
|
coreUtils.file.exist.restore() |
|
276
|
|
|
sinon.assert.calledOnce(cmsTemplates.template.includePartials) |
|
277
|
|
|
cmsTemplates.template.includePartials.restore() |
|
278
|
|
|
sinon.assert.calledOnce(cmsTemplates.template.translate) |
|
279
|
|
|
cmsTemplates.template.translate.restore() |
|
280
|
|
|
sinon.assert.calledOnce(cmsTemplates.template.addOrder) |
|
281
|
|
|
cmsTemplates.template.addOrder.restore() |
|
282
|
|
|
}); |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist |
|
286
|
|
|
* |
|
287
|
|
|
*/ |
|
288
|
|
|
it('cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist()', function() { |
|
289
|
|
|
// stub |
|
290
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
291
|
|
|
var stubGetTagAbeWithType = sinonInstance.stub(cmsData.regex, 'getTagAbeWithType'); |
|
292
|
|
|
stubGetTagAbeWithType.returns(null) |
|
293
|
|
|
|
|
294
|
|
|
// test |
|
295
|
|
|
var text = cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist(this.fixture.slug) |
|
296
|
|
|
chai.expect(text).to.not.be.equal(this.fixture.slug); |
|
297
|
|
|
|
|
298
|
|
|
// unstub |
|
299
|
|
|
sinon.assert.calledOnce(cmsData.regex.getTagAbeWithType) |
|
300
|
|
|
cmsData.regex.getTagAbeWithType.restore() |
|
301
|
|
|
}); |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist |
|
305
|
|
|
* |
|
306
|
|
|
*/ |
|
307
|
|
|
it('cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist()', function() { |
|
308
|
|
|
// stub |
|
309
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
310
|
|
|
var stubGetTagAbeWithTab = sinonInstance.stub(cmsData.regex, 'getTagAbeWithTab'); |
|
311
|
|
|
stubGetTagAbeWithTab.returns(null) |
|
312
|
|
|
|
|
313
|
|
|
// test |
|
314
|
|
|
var text = cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist(this.fixture.slug) |
|
315
|
|
|
chai.expect(text).to.not.be.equal(this.fixture.slug); |
|
316
|
|
|
|
|
317
|
|
|
// unstub |
|
318
|
|
|
sinon.assert.calledOnce(cmsData.regex.getTagAbeWithTab) |
|
319
|
|
|
cmsData.regex.getTagAbeWithTab.restore() |
|
320
|
|
|
}); |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* cmsTemplates.template.getAbePrecontribFromTemplates |
|
324
|
|
|
* |
|
325
|
|
|
*/ |
|
326
|
|
|
it('cmsTemplates.template.getAbePrecontribFromTemplates()', function() { |
|
327
|
|
|
// stub |
|
328
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
329
|
|
|
var stubGetTagAbeWithTab = sinonInstance.stub(cmsData.regex, 'getTagAbeWithTab'); |
|
330
|
|
|
stubGetTagAbeWithTab.returns(['{{abe type="slug" source="{{name}}"}}']) |
|
331
|
|
|
|
|
332
|
|
|
var stubGetAll = sinonInstance.stub(cmsData.attributes, 'getAll'); |
|
333
|
|
|
stubGetAll.returns({name: 'test.html'}) |
|
334
|
|
|
|
|
335
|
|
|
var stubAddOrder = sinonInstance.stub(cmsTemplates.template, 'addOrder', function (text) { |
|
|
|
|
|
|
336
|
|
|
return text |
|
337
|
|
|
}); |
|
338
|
|
|
|
|
339
|
|
|
// test |
|
340
|
|
|
var precontrib = cmsTemplates.template.getAbePrecontribFromTemplates([{name: 'slug', template: this.fixture.slug}]) |
|
341
|
|
|
chai.expect(precontrib.fields[0]).to.not.be.undefined; |
|
|
|
|
|
|
342
|
|
|
|
|
343
|
|
|
// unstub |
|
344
|
|
|
sinon.assert.calledOnce(cmsData.regex.getTagAbeWithTab) |
|
345
|
|
|
cmsData.regex.getTagAbeWithTab.restore() |
|
346
|
|
|
sinon.assert.calledOnce(cmsData.attributes.getAll) |
|
347
|
|
|
cmsData.attributes.getAll.restore() |
|
348
|
|
|
sinon.assert.calledOnce(cmsTemplates.template.addOrder) |
|
349
|
|
|
cmsTemplates.template.addOrder.restore() |
|
350
|
|
|
}); |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* cmsTemplates.template.getAbeSlugFromTemplates |
|
354
|
|
|
* |
|
355
|
|
|
*/ |
|
356
|
|
|
it('cmsTemplates.template.getAbeSlugFromTemplates()', function() { |
|
357
|
|
|
// stub |
|
358
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
359
|
|
|
var setAbeSlugDefaultValueIfDoesntExist = sinonInstance.stub(cmsTemplates.template, 'setAbeSlugDefaultValueIfDoesntExist'); |
|
360
|
|
|
setAbeSlugDefaultValueIfDoesntExist.returns(this.fixture.slug) |
|
361
|
|
|
var getTagAbeWithType = sinonInstance.stub(cmsData.regex, 'getTagAbeWithType'); |
|
362
|
|
|
getTagAbeWithType.returns(['{{abe type="slug" source="{{name}}"}}']) |
|
363
|
|
|
var getAll = sinonInstance.stub(cmsData.attributes, 'getAll'); |
|
364
|
|
|
getAll.returns({sourceString: 'test.html', name: 'test'}) |
|
365
|
|
|
|
|
366
|
|
|
var slug = cmsTemplates.template.getAbeSlugFromTemplates([{name: 'slug', template: this.fixture.slug}]) |
|
367
|
|
|
chai.expect(slug.slug).to.not.be.undefined; |
|
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
// unstub |
|
370
|
|
|
sinon.assert.calledOnce(cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist) |
|
371
|
|
|
cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist.restore() |
|
372
|
|
|
sinon.assert.calledOnce(cmsData.regex.getTagAbeWithType) |
|
373
|
|
|
cmsData.regex.getTagAbeWithType.restore() |
|
374
|
|
|
sinon.assert.calledOnce(cmsData.attributes.getAll) |
|
375
|
|
|
cmsData.attributes.getAll.restore() |
|
376
|
|
|
}); |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* getTemplate |
|
380
|
|
|
* |
|
381
|
|
|
*/ |
|
382
|
|
|
it('cmsTemplates.template.execRequestColumns()', function() { |
|
383
|
|
|
// stub |
|
384
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
385
|
|
|
var getTagAbeTypeRequest = sinonInstance.stub(cmsData.regex, 'getTagAbeTypeRequest'); |
|
386
|
|
|
getTagAbeTypeRequest.returns([this.fixture.articleRequest]) |
|
387
|
|
|
var getSourceType = sinonInstance.stub(cmsData.sql, 'getSourceType'); |
|
388
|
|
|
getSourceType.returns('request') |
|
389
|
|
|
var handleSqlRequest = sinonInstance.stub(cmsData.sql, 'handleSqlRequest'); |
|
390
|
|
|
handleSqlRequest.returns({columns: ['title'], where: {left: 'title'}}) |
|
391
|
|
|
var recurseWhereVariables = sinonInstance.stub(cmsTemplates.template, 'recurseWhereVariables'); |
|
392
|
|
|
recurseWhereVariables.returns('title2') |
|
393
|
|
|
|
|
394
|
|
|
// test |
|
395
|
|
|
const pathTemplate = path.join(config.root, config.templates.url) |
|
|
|
|
|
|
396
|
|
|
var ar = cmsTemplates.template.execRequestColumns(this.fixture.templateKeys) |
|
397
|
|
|
chai.expect(ar.indexOf('title')).to.be.above(-1); |
|
398
|
|
|
|
|
399
|
|
|
// unstub |
|
400
|
|
|
sinon.assert.calledOnce(cmsData.regex.getTagAbeTypeRequest) |
|
401
|
|
|
cmsData.regex.getTagAbeTypeRequest.restore() |
|
402
|
|
|
sinon.assert.calledOnce(cmsData.sql.getSourceType) |
|
403
|
|
|
cmsData.sql.getSourceType.restore() |
|
404
|
|
|
sinon.assert.calledOnce(cmsData.sql.handleSqlRequest) |
|
405
|
|
|
cmsData.sql.handleSqlRequest.restore() |
|
406
|
|
|
sinon.assert.calledOnce(cmsTemplates.template.recurseWhereVariables) |
|
407
|
|
|
cmsTemplates.template.recurseWhereVariables.restore() |
|
408
|
|
|
}); |
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* getTemplate |
|
412
|
|
|
* |
|
413
|
|
|
*/ |
|
414
|
|
|
it('cmsTemplates.template.getAbeRequestWhereKeysFromTemplates()', function(done) { |
|
415
|
|
|
// stub |
|
416
|
|
|
var sinonInstance = sinon.sandbox.create(); |
|
417
|
|
|
var execRequestColumns = sinonInstance.stub(cmsTemplates.template, 'execRequestColumns'); |
|
418
|
|
|
execRequestColumns.returns(['title']) |
|
419
|
|
|
|
|
420
|
|
|
// test |
|
421
|
|
|
const pathTemplate = path.join(config.root, config.templates.url) |
|
|
|
|
|
|
422
|
|
|
cmsTemplates.template.getAbeRequestWhereKeysFromTemplates([this.fixture.articleRequest]) |
|
423
|
|
|
.then(function (ar) { |
|
424
|
|
|
chai.expect(ar.indexOf('title')).to.be.above(-1); |
|
425
|
|
|
|
|
426
|
|
|
// unstub |
|
427
|
|
|
sinon.assert.calledOnce(cmsTemplates.template.execRequestColumns) |
|
428
|
|
|
cmsTemplates.template.execRequestColumns.restore() |
|
429
|
|
|
done() |
|
430
|
|
|
}) |
|
431
|
|
|
}); |
|
432
|
|
|
|
|
433
|
|
|
/** |
|
434
|
|
|
* cmsTemplates.encodeAbeTagAsComment |
|
435
|
|
|
* |
|
436
|
|
|
*/ |
|
437
|
|
|
it('cmsTemplates.encodeAbeTagAsComment()', function() { |
|
438
|
|
|
var txt = cmsTemplates.encodeAbeTagAsComment(this.fixture.articleEach); |
|
439
|
|
|
chai.expect(txt.indexOf('{')).to.equal(-1); |
|
440
|
|
|
}); |
|
441
|
|
|
}); |
|
442
|
|
|
|
This check looks for functions where a
returnstatement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBigwill only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined.This behaviour may not be what you had intended. In any case, you can add a
return undefinedto the other execution path to make the return value explicit.