Completed
Push — master ( a00f3d...6cfb01 )
by greg
01:46
created

test/manager.js   A

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 80
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 0
wmc 12
nc 1
mnd 0
bc 12
fnc 12
dl 0
loc 80
rs 10
bpm 1
cpm 1
noi 6
c 2
b 1
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A manager.js ➔ describe(ꞌManagerꞌ) 0 68 1
1
var chai = require('chai');
2
var path = require('path');
3
4
var Manager = require('../src/cli').Manager
5
var config = require('../src/cli').config
6
var cmsOperations = require('../src/cli').cmsOperations
7
config.set({root: __dirname + '/fixtures/'})
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
8
9
var cmsData = require('../src/cli').cmsData;
10
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 4. 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...
11
var fse = require('fs-extra');
12
13
describe('Manager', function() {
14
  before( function(done) {
15
    Manager.instance.init()
16
      .then(function () {
17
18
        this.fixture = {
19
          tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
20
          jsonArticle: fse.readJsonSync(__dirname + '/fixtures/files/article-4.json'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
21
          jsonArticle1: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json')
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
22
        }
23
        done()
24
        
25
      }.bind(this))
26
  });
27
28
  it('getStructureAndTemplates()', function() {
29
    const data = Manager.instance.getStructureAndTemplates()
30
    chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !')
31
    chai.assert.equal(data['templates'].length, 7, 'failed !')
32
  });
33
34
  it('updateStructureAndTemplates()', function() {
35
    Manager.instance.updateStructureAndTemplates()
36
    const data = Manager.instance.getStructureAndTemplates()
37
    chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !')
38
    chai.assert.equal(data['templates'].length, 7, 'failed !')
39
  });
40
41
  it('getList()', function() {
42
    const list = Manager.instance.getList()
43
    chai.assert.equal(list[0].name, 'article-1.json', 'failed !')
44
    chai.assert.equal(list.length, 3, 'failed !')
45
  });
46
47
  it('getListWithStatusOnFolder() status publish', function() {
48
    const list = Manager.instance.getListWithStatusOnFolder('publish')
49
    chai.assert.equal(list[0].name, 'article-1.json', 'failed !')
50
    chai.assert.equal(list.length, 2, 'failed !')
51
  });
52
53
  it('getListWithStatusOnFolder() status draft', function() {
54
    const list = Manager.instance.getListWithStatusOnFolder('draft')
55
    chai.assert.equal(list.length, 2, 'failed !')
56
  });
57
58
  it('getListWithStatusOnFolder() status review', function() {
59
    const list = Manager.instance.getListWithStatusOnFolder('review')
60
    chai.assert.equal(list.length, 0, 'failed !')
61
  });
62
63
  it('getListWithStatusOnFolder() status publish /0-1', function() {
64
    const list = Manager.instance.getListWithStatusOnFolder('draft', '0-1')
65
    chai.assert.equal(list[0].name, 'article-2.json', 'failed !')
66
    chai.assert.equal(list.length, 1, 'failed !')
67
  });
68
69
  it('updatePostInList() with new post', function(done) {
70
    const len = Manager.instance.getList().length
71
    cmsOperations.create('article', '', 'article-4.html', {query: ''}, this.fixture.jsonArticle, false)
72
      .then(function(resSave) {
73
        const json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json'))
74
        const list = Manager.instance.getList()
75
        fse.removeSync(json)
76
        chai.assert.equal(list.length, len + 1, 'failed !')
77
        done()
78
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
79
  });
80
});
81