1 | var path = require('path');
|
2 | var should = require('should');
|
3 |
|
4 | var manager = require('../lib');
|
5 |
|
6 | describe('Versions', function() {
|
7 | this.timeout(100000);
|
8 |
|
9 | describe('.available()', function() {
|
10 | var result;
|
11 |
|
12 | before(function() {
|
13 | return manager.available()
|
14 | .then(function(versions) {
|
15 | result = versions;
|
16 | });
|
17 | });
|
18 |
|
19 | it('should correctly return a list of versions', function() {
|
20 | result.should.have.properties('versions');
|
21 | result.versions.should.be.an.Array();
|
22 | });
|
23 |
|
24 | it('should correctly return a map of tags', function() {
|
25 | result.should.have.properties('tags');
|
26 | result.tags.should.have.properties('latest');
|
27 | });
|
28 | });
|
29 |
|
30 | describe('.install()', function() {
|
31 | var result;
|
32 |
|
33 | before(function() {
|
34 | return manager.install('2.0.0')
|
35 | .then(function(version) {
|
36 | result = version;
|
37 | });
|
38 | });
|
39 |
|
40 | it('should correctly return the installed version', function() {
|
41 | result.should.be.a.String();
|
42 | result.should.equal('2.0.0');
|
43 | });
|
44 | });
|
45 |
|
46 | describe('.ensure()', function() {
|
47 | it('should correctly return installed version', function() {
|
48 | return manager.ensure(__dirname)
|
49 | .then(function(v) {
|
50 | v.should.have.properties('version', 'path');
|
51 | v.version.should.equal('2.0.0');
|
52 | });
|
53 | });
|
54 |
|
55 | it('should correctly install version specified', function() {
|
56 | return manager.ensure(path.resolve(__dirname, 'fixtures/book1'))
|
57 | .then(function(v) {
|
58 | v.should.have.properties('version', 'path');
|
59 | v.version.should.equal('3.0.0-pre.2');
|
60 | });
|
61 | });
|
62 | });
|
63 |
|
64 | describe('.list()', function() {
|
65 | var result;
|
66 |
|
67 | before(function() {
|
68 | result = manager.versions();
|
69 | });
|
70 |
|
71 | it('should correctly return the installed version', function() {
|
72 | result.should.be.an.Array();
|
73 | result.should.have.lengthOf(2);
|
74 | result[0].should.have.properties('name', 'tag', 'version', 'path');
|
75 | result[0].version.should.equal('3.0.0-pre.2');
|
76 | result[1].should.have.properties('name', 'tag', 'version', 'path');
|
77 | result[1].version.should.equal('2.0.0');
|
78 | });
|
79 | });
|
80 |
|
81 | describe('.link()', function() {
|
82 | var localGitbook = path.resolve(__dirname, '../node_modules/gitbook');
|
83 |
|
84 | before(function() {
|
85 | return manager.link('latest', localGitbook);
|
86 | });
|
87 |
|
88 | it('should correctly list latest version', function() {
|
89 | var result = manager.versions();
|
90 | result.should.have.lengthOf(3);
|
91 | result[1].should.have.properties('version', 'path');
|
92 | result[1].tag.should.equal('beta');
|
93 | result[1].name.should.equal('latest');
|
94 | result[1].link.should.equal(localGitbook);
|
95 | });
|
96 |
|
97 | it('should correctly return latest version as default one', function() {
|
98 | return manager.get(__dirname)
|
99 | .then(function(version) {
|
100 | version.name.should.equal('latest');
|
101 | });
|
102 | });
|
103 | });
|
104 |
|
105 | describe('.ensureAndLoad()', function() {
|
106 | it('should correctly return gitbook instance', function() {
|
107 | return manager.ensureAndLoad(__dirname)
|
108 | .then(function(gitbook) {
|
109 | gitbook.should.be.an.Object();
|
110 | gitbook.should.have.properties('commands');
|
111 | gitbook.commands.should.be.an.Array();
|
112 | });
|
113 | });
|
114 | });
|
115 |
|
116 | describe('.uninstall()', function() {
|
117 | it('should correctly remove a specific version', function() {
|
118 | return manager.uninstall('2.0.0')
|
119 | .then(function() {
|
120 | var result = manager.versions();
|
121 | result.should.have.lengthOf(2);
|
122 | });
|
123 | });
|
124 |
|
125 | it('should correctly remove a version by tag', function() {
|
126 | return manager.uninstall('latest')
|
127 | .then(function() {
|
128 | var result = manager.versions();
|
129 | result.should.have.lengthOf(1);
|
130 | });
|
131 | });
|
132 | });
|
133 | });
|