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 Manager = require('../../../src/cli').Manager |
||
15 | var coreUtils = require('../../../src/cli').coreUtils |
||
16 | var cmsOperations = require('../../../src/cli').cmsOperations |
||
17 | var cmsTemplates = require('../../../src/cli').cmsTemplates |
||
18 | var Manager = require('../../../src/cli').Manager; |
||
0 ignored issues
–
show
|
|||
19 | var Page = require('../../../src/cli').Page; |
||
20 | |||
21 | describe('cmsOperations', function() { |
||
22 | before( function(done) { |
||
23 | Manager.instance.init() |
||
24 | .then(function () { |
||
25 | Manager.instance._whereKeys = ['title', 'priority', 'abe_meta', 'articles'] |
||
26 | Manager.instance.updateList() |
||
27 | |||
28 | this.fixture = { |
||
29 | htmlArticle: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article.html'), 'utf8'), |
||
30 | jsonArticle: fse.readJsonSync(path.join(process.cwd(), 'test', 'fixtures', 'files', 'article-2.json')), |
||
31 | jsonHomepage: fse.readJsonSync(path.join(process.cwd(), 'test', 'fixtures', 'data', 'homepage-1.json')) |
||
32 | } |
||
33 | done() |
||
34 | |||
35 | }.bind(this)) |
||
36 | }); |
||
37 | |||
38 | it('cmsOperations.create()', function(done) { |
||
39 | // stub |
||
40 | var s = sinon.sandbox.create(); |
||
41 | s.stub(abeExtend.hooks.instance, 'trigger', function (str, obj, body, json) { |
||
42 | if (str == 'beforeFirstSave') { |
||
43 | return { |
||
44 | postUrl: obj, |
||
45 | json: json |
||
46 | } |
||
47 | } |
||
48 | return str, obj; |
||
0 ignored issues
–
show
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.
The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression. This operator is most often used in Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator. This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements. var a,b,c;
a = 1, b = 1, c= 3;
could just as well be written as: var a,b,c;
a = 1;
b = 1;
c = 3;
To learn more about the sequence operator, please refer to the MDN. ![]() |
|||
49 | }.bind(this)); |
||
0 ignored issues
–
show
|
|||
50 | s.stub(coreUtils.slug, 'clean', function (p) { return p; }.bind(this)); |
||
0 ignored issues
–
show
|
|||
51 | s.stub(Manager.instance, 'postExist', function (p) { return false; }.bind(this)); |
||
0 ignored issues
–
show
|
|||
52 | s.stub(cmsData.metas, 'create', function (json, template, postUrl) { return json; }.bind(this)); |
||
0 ignored issues
–
show
|
|||
53 | s.stub(cmsTemplates.template, 'getTemplate', function () { return this.fixture.htmlArticle; }.bind(this)); |
||
54 | s.stub(cmsData.values, 'removeDuplicate', function (templateText, json) { return json; }.bind(this)); |
||
0 ignored issues
–
show
|
|||
55 | s.stub(cmsOperations.post, 'draft', function () { |
||
56 | return Promise.resolve({json: JSON.parse(JSON.stringify(this.fixture.jsonArticle))}) |
||
57 | }.bind(this)); |
||
58 | |||
59 | cmsOperations.create('article', '', 'article-2.html', {query: ''}, JSON.parse(JSON.stringify(this.fixture.jsonArticle)), false) |
||
60 | .then(function(resSave) { |
||
61 | var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
||
0 ignored issues
–
show
|
|||
62 | |||
63 | abeExtend.hooks.instance.trigger.restore() |
||
64 | coreUtils.slug.clean.restore() |
||
65 | Manager.instance.postExist.restore() |
||
66 | cmsData.metas.create.restore() |
||
67 | cmsTemplates.template.getTemplate.restore() |
||
68 | cmsData.values.removeDuplicate.restore() |
||
69 | cmsOperations.post.draft.restore() |
||
70 | |||
71 | done() |
||
72 | }.bind(this)); |
||
0 ignored issues
–
show
|
|||
73 | }); |
||
74 | }); |
||
75 |
This check looks for variables that are declared in multiple lines. There may be several reasons for this.
In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.
If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.