Issues (791)

test/cms/operations/duplicate.js (10 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
  it('cmsOperations.duplicate()', function(done) {
39
    // stub
40
    var s = sinon.sandbox.create();
41
    s.stub(abeExtend.hooks.instance, 'trigger', function (str, obj) { return str, obj; }.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...
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...
42
    s.stub(Manager.instance, 'getList', function (str, obj) { return [this.fixture.jsonArticle]; }.bind(this));
0 ignored issues
show
The parameter str 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 parameter obj 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...
43
    s.stub(coreUtils.slug, 'clean', function (p) { return p; }.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...
44
    s.stub(coreUtils.array, 'filter', function () { return [this.fixture.jsonArticle]; }.bind(this));
45
    s.stub(cmsData.file, 'get', function () { return this.fixture.jsonArticle; }.bind(this));
46
    s.stub(cmsOperations, 'create', function () { return Promise.resolve(this.fixture.jsonArticle); }.bind(this));
47
    s.stub(cmsOperations.remove, 'remove', 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...
48
49
    // test
50
    var newPostUrl = 'article-2.html'
51
    cmsOperations.duplicate('article-1.html', 'article', '', newPostUrl, {}, false)
52
    .then(function(resSave) {
53
      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...
54
      chai.expect(resSave.abe_meta.link).to.be.equal('/article-2.html');
55
56
      cmsOperations.duplicate('article-1.html', 'article', '', newPostUrl, {}, true)
57
      .then(function(resSave2) {
58
        chai.expect(resSave2.abe_meta).to.not.be.undefined;
0 ignored issues
show
The result of the property access to chai.expect(resSave2.abe_meta).to.not.be.undefined is not used.
Loading history...
59
        chai.expect(resSave2.abe_meta.link).to.be.equal('/article-2.html');
60
61
        // unstub
62
        abeExtend.hooks.instance.trigger.restore()
63
        sinon.assert.calledTwice(Manager.instance.getList)
64
        Manager.instance.getList.restore()
65
        sinon.assert.calledTwice(coreUtils.slug.clean)
66
        coreUtils.slug.clean.restore()
67
        sinon.assert.calledTwice(coreUtils.array.filter)
68
        coreUtils.array.filter.restore()
69
        cmsData.file.get.restore()
70
        sinon.assert.calledTwice(cmsOperations.create)
71
        cmsOperations.create.restore()
72
        sinon.assert.calledOnce(cmsOperations.remove.remove)
73
        cmsOperations.remove.remove.restore()
74
        done()
75
      }.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...
76
    }.bind(this))
77
  });
78
});
79