Issues (791)

test/cms/operations/post.js (33 issues)

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
Comprehensibility Naming Best Practice introduced by
The variable Manager already seems to be declared on line 14. Consider using another variable name or omitting the var keyword.

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.

Loading history...
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
  /**
39
   * cmsOperations.post.publish
40
   * 
41
   */
42
  it('cmsOperations.post.publish()', function(done) {
43
    // stub
44
    var s = sinon.sandbox.create();
45
    s.stub(abeExtend.hooks.instance, 'trigger', function (str, obj) { return str, obj; }.bind(this));
0 ignored issues
show
Comprehensibility introduced by
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 for statements.

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.

Loading history...
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
46
    s.stub(cmsTemplates.template, 'getTemplate', function () { return this.fixture.htmlArticle; }.bind(this));
47
    s.stub(cmsData.source, 'getDataList', function () {
48
      return Promise.resolve(JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
49
    }.bind(this));
50
    s.stub(cmsData.utils, 'getPercentOfRequiredTagsFilled', function () { return 100; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
51
    // s.stub(Page, 'getPercentOfRequiredTagsFilled', function () { return 100; }.bind(this));
52
    s.stub(cmsOperations.save, 'saveHtml', function () { return 100; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
53
    s.stub(cmsOperations.save, 'saveJson', function () { return 100; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
54
    s.stub(Manager.instance, 'updatePostInList', function () { return null; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
55
56
    // test
57
    cmsOperations.post.publish('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
58
      .then(function(resSave) {
0 ignored issues
show
The parameter resSave is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
59
      // unstub
60
      abeExtend.hooks.instance.trigger.restore()
61
      cmsTemplates.template.getTemplate.restore()
62
      cmsData.source.getDataList.restore()
63
      cmsData.utils.getPercentOfRequiredTagsFilled.restore()
64
      cmsOperations.save.saveHtml.restore()
65
      cmsOperations.save.saveJson.restore()
66
      Manager.instance.updatePostInList.restore()
67
      done()
68
      }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
69
  });
70
71
  /**
72
   * cmsOperations.post.unpublish
73
   * 
74
   */
75
  it('cmsOperations.post.unpublish()', function(done) {
76
    // stub
77
    var s = sinon.sandbox.create();
78
    s.stub(abeExtend.hooks.instance, 'trigger', function (str, obj) { return str, obj; }.bind(this));
0 ignored issues
show
Comprehensibility introduced by
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 for statements.

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.

Loading history...
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
79
    s.stub(coreUtils.file, 'exist', function (revisionPath) { return true; }.bind(this));
0 ignored issues
show
The parameter revisionPath is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
80
    s.stub(cmsData.file, 'get', function () { return JSON.parse(JSON.stringify(this.fixture.jsonArticle)); }.bind(this));
81
    s.stub(cmsOperations.post, 'draft', function () {
82
      return Promise.resolve({json: JSON.parse(JSON.stringify(this.fixture.jsonArticle))})
83
    }.bind(this));
84
    s.stub(cmsOperations.remove, 'removeFile', function () { return null; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
85
    s.stub(Manager.instance, 'updatePostInList', function () { return null; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
86
87
    // test
88
    cmsOperations.post.unpublish('article-2.html')
89
    .then(function(resSave) {
0 ignored issues
show
The parameter resSave is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
90
      
91
      // unstub
92
      abeExtend.hooks.instance.trigger.restore()
93
      coreUtils.file.exist.restore()
94
      cmsData.file.get.restore()
95
      cmsOperations.post.draft.restore()
96
      cmsOperations.remove.removeFile.restore()
97
      Manager.instance.updatePostInList.restore()
98
      done()
99
    }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
100
  });
101
102
  /**
103
   * cmsOperations.post.draft
104
   * 
105
   */
106
  it('cmsOperations.post.draft()', function(done) {
107
    var json = JSON.parse(JSON.stringify(this.fixture.jsonArticle))
108
    var meta = json.abe_meta
109
    delete json.abe_meta
110
111
    // stub
112
    var s = sinon.sandbox.create();
113
    s.stub(abeExtend.hooks.instance, 'trigger', function (str, obj) { return str, obj; }.bind(this));
0 ignored issues
show
Comprehensibility introduced by
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 for statements.

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.

Loading history...
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
114
    s.stub(coreUtils.file, 'addDateIsoToRevisionPath', function (revisionPath) { return revisionPath; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
115
    s.stub(cmsData.metas, 'add', function (json) {
116
      json.abe_meta = meta
117
      return json;
118
    }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
119
    s.stub(cmsTemplates.template, 'getTemplate', function () { return this.fixture.htmlArticle; }.bind(this));
120
    s.stub(cmsData.source, 'getDataList', function () {
121
      return Promise.resolve(JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
122
    }.bind(this));
123
    s.stub(cmsOperations.save, 'saveJson', function () { return true; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
124
    s.stub(Manager.instance, 'updatePostInList', function () { return null; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
125
    s.stub(cmsData.utils, 'getPercentOfRequiredTagsFilled', function () { return 100; }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
126
127
    // test
128
    cmsOperations.post.draft('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle)))
129
      .then(function(resSave) {
130
        chai.expect(resSave.success).to.be.equal(1);
131
        chai.expect(resSave.json.abe_meta).to.not.be.undefined;
0 ignored issues
show
The result of the property access to chai.expect(resSave.json...ta).to.not.be.undefined is not used.
Loading history...
132
        
133
        // unstub
134
        abeExtend.hooks.instance.trigger.restore()
135
        coreUtils.file.addDateIsoToRevisionPath.restore()
136
        cmsData.utils.getPercentOfRequiredTagsFilled.restore()
137
        cmsData.metas.add.restore()
138
        cmsTemplates.template.getTemplate.restore()
139
        cmsData.source.getDataList.restore()
140
        cmsOperations.save.saveJson.restore()
141
        Manager.instance.updatePostInList.restore()
142
143
        done()
144
      }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
145
  });
146
147
  /**
148
   * cmsOperations.post.submit
149
   * 
150
   */
151
  it('cmsOperations.post.submit()', function(done) {
152
    // stub
153
    var s = sinon.sandbox.create();
154
    s.stub(cmsOperations.post, 'draft', function (filePath, json, rejectToWorkflow) {
0 ignored issues
show
The parameter rejectToWorkflow is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
155
      return Promise.resolve({
156
          success: 1,
157
          json: this.fixture.jsonArticle
158
        });
159
    }.bind(this));
160
161
    // test
162
    var json = JSON.parse(JSON.stringify(this.fixture.jsonArticle))
163
    json.abe_meta.status = 'publish'
164
    cmsOperations.post.submit('article-2.html', json)
165
      .then(function(resSave) {
166
        chai.expect(resSave.json.abe_meta).to.not.be.undefined;
0 ignored issues
show
The result of the property access to chai.expect(resSave.json...ta).to.not.be.undefined is not used.
Loading history...
167
168
        // unstub
169
        cmsOperations.post.draft.restore()
170
        done()
171
      }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
172
  });
173
174
  /**
175
   * cmsOperations.post.reject
176
   * 
177
   */
178
  it('cmsOperations.post.reject()', function(done) {
179
    // stub
180
    var s = sinon.sandbox.create();
181
    s.stub(abeExtend.hooks.instance, 'trigger', function (str, obj) { return str, obj; }.bind(this));
0 ignored issues
show
Comprehensibility introduced by
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 for statements.

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.

Loading history...
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
182
    s.stub(cmsOperations.post, 'draft', function (filePath, json, rejectToWorkflow) {
183
      chai.expect(rejectToWorkflow).to.be.equal("draft");
184
      return Promise.resolve(this.fixture.jsonArticle);
185
    }.bind(this));
186
187
    // test
188
    var json = JSON.parse(JSON.stringify(this.fixture.jsonArticle))
189
    json.abe_meta.status = 'publish'
190
    cmsOperations.post.reject('article-2.html', json)
191
      .then(function(resSave) {
192
        chai.expect(resSave.abe_meta).to.not.be.undefined;
0 ignored issues
show
The result of the property access to chai.expect(resSave.abe_meta).to.not.be.undefined is not used.
Loading history...
193
194
        // unstub
195
        abeExtend.hooks.instance.trigger.restore()
196
        cmsOperations.post.draft.restore()
197
        done()
198
      }.bind(this));
0 ignored issues
show
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
199
  });
200
});
201