|
1
|
|
|
var chai = require('chai'); |
|
2
|
|
|
var path = require('path'); |
|
3
|
|
|
|
|
4
|
|
|
var config = require('../src/cli').config |
|
5
|
|
|
config.set({root: path.join(__dirname,'fixtures')}) |
|
6
|
|
|
|
|
7
|
|
|
var cmsOperations = require('../src/cli').cmsOperations |
|
8
|
|
|
var Manager = require('../src/cli').Manager; |
|
9
|
|
|
var fse = require('fs-extra'); |
|
10
|
|
|
|
|
11
|
|
|
describe('Create', function() { |
|
12
|
|
|
before( function(done) { |
|
13
|
|
|
Manager.instance.init() |
|
14
|
|
|
.then(function () { |
|
15
|
|
|
Manager.instance._whereKeys = ['title', 'priority', 'abe_meta', 'articles'] |
|
16
|
|
|
Manager.instance.updateList() |
|
17
|
|
|
|
|
18
|
|
|
this.fixture = { |
|
19
|
|
|
tag: fse.readFileSync(path.join(__dirname, 'fixtures/templates/article.html'), 'utf8'), |
|
20
|
|
|
jsonArticle: fse.readJsonSync(path.join(__dirname, '/fixtures/files/article-4.json')), |
|
21
|
|
|
jsonHomepage: fse.readJsonSync(path.join(__dirname, '/fixtures/data/homepage-1.json')) |
|
22
|
|
|
} |
|
23
|
|
|
done() |
|
24
|
|
|
|
|
25
|
|
|
}.bind(this)) |
|
26
|
|
|
}); |
|
27
|
|
|
|
|
28
|
|
|
it('cmsOperations.create()', function(done) { |
|
29
|
|
|
cmsOperations.create('article', '', 'article-2.html', {query: ''}, this.fixture.jsonArticle, false) |
|
30
|
|
|
.then(function(resSave) { |
|
31
|
|
|
var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
32
|
|
|
console.log(json) |
|
|
|
|
|
|
33
|
|
|
var stat = fse.statSync(json) |
|
34
|
|
|
if (stat) { |
|
35
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
fse.removeSync(json) |
|
38
|
|
|
done() |
|
39
|
|
|
}.bind(this)); |
|
|
|
|
|
|
40
|
|
|
}); |
|
41
|
|
|
|
|
42
|
|
|
it('cmsOperations.duplicate()', function(done) { |
|
43
|
|
|
cmsOperations.duplicate('article-1.html', 'article', '', 'article-2.html', {}, false) |
|
44
|
|
|
.then(function(resSave) { |
|
45
|
|
|
var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
46
|
|
|
var stat = fse.statSync(json) |
|
47
|
|
|
if (stat) { |
|
48
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
fse.removeSync(json) |
|
51
|
|
|
done() |
|
52
|
|
|
}.bind(this)) |
|
|
|
|
|
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
it('cmsOperations.duplicate() update', function(done) { |
|
56
|
|
|
cmsOperations.duplicate('article-1.html', 'article', '', 'article-1.html', {}, true) |
|
57
|
|
|
.then(function(resSave) { |
|
58
|
|
|
var json = path.join(config.root, config.data.url, resSave.abe_meta.link.replace('.html', '.json')) |
|
59
|
|
|
var stat = fse.statSync(json) |
|
60
|
|
|
if (stat) { |
|
61
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
done() |
|
64
|
|
|
}.bind(this)) |
|
|
|
|
|
|
65
|
|
|
}); |
|
66
|
|
|
}); |
|
67
|
|
|
|