UNPKG

5.84 kBJavaScriptView Raw
1var assert = require ('assert');
2var path = require ('path');
3var rm = require ('rimraf');
4var fs = require ('fs');
5var proxyquire = require('proxyquire');
6
7var commands;
8
9describe ('cli commands', function(){
10
11 require('./includes/startup');
12
13 var temp_folder = "test/tmp";
14 var packagesLocalFolder = path.join(process.cwd(), "/test/fixtures/packages");
15
16 //make sure temp folder is deleted even if tests fail (before and after)
17 beforeEach(function(done){
18 commands = proxyquire('../lib/cli/commands', {
19 './commands-logic': {
20 'generate' : function(projectDir, defaultPackage, itemType, itemName, callback){
21 callback(null);
22 }
23 }
24 });
25
26 rm(temp_folder, function(){
27 fs.mkdir(temp_folder, done);
28 });
29 });
30
31 afterEach(function(done){
32 rm(temp_folder, done);
33 });
34
35 describe ('generate', function(){
36
37 it('should exit with errors if no args are passed', function(done){
38 var args = [];
39 commands.generate.run(args, function(err) {
40 assert.ok(err);
41 done();
42 });
43 });
44
45 it('should exit with errors if only element type is passed', function(done){
46 var args = ['job'];
47 commands.generate.run(args, function(err) {
48 assert.ok(err);
49 done();
50 });
51 });
52
53 it('should not exit with errors if correct arguments are passed', function(done){
54 var args = ['job', 'test'];
55 commands.generate.run(args, function(err) {
56 assert.ok(!err, err);
57 done();
58 });
59 });
60
61 it('should pass the right parameters to the logic module', function(done){
62 var args = ['job', 'test'];
63 commands = proxyquire('../lib/cli/commands', {
64 './commands-logic': {
65 'generate' : function(projectDir, defaultPackage, itemType, itemName, callback){
66 assert.equal(defaultPackage, 'default');
67 assert.equal(itemType, 'job');
68 assert.equal(itemName, 'test');
69 callback(null);
70 }
71 }
72 });
73
74 commands.generate.run(args, function(err) {
75 assert.ok(!err, err);
76 done();
77 });
78 });
79
80 it('should pass the right parameters to the logic module when item includes package', function(done){
81 var args = ['job', 'mypackage#test'];
82 commands = proxyquire('../lib/cli/commands', {
83 './commands-logic': {
84 'generate' : function(projectDir, defaultPackage, itemType, itemName, callback){
85 assert.equal(defaultPackage, 'mypackage');
86 assert.equal(itemType, 'job');
87 assert.equal(itemName, 'test');
88 callback(null);
89 }
90 }
91 });
92
93 commands.generate.run(args, function(err) {
94 assert.ok(!err, err);
95 done();
96 });
97 });
98
99 });
100
101 describe ('new', function(){
102
103 it('should exit with errors if bad arguments are passed', function(done){
104 var args = [];
105 commands.new.run(args, function(err) {
106 assert.ok(err);
107 done();
108 });
109 });
110
111 it('should pass the right parameters to the logic module when item includes package', function(done){
112 var args = ['mywallboard'];
113 commands = proxyquire('../lib/cli/commands', {
114 './commands-logic': {
115 'newProject' : function(srcDir, destDir, callback){
116 assert.equal(destDir.length - destDir.lastIndexOf('mywallboard'), 11);
117 callback('error so we can interrupt execution and assert just for valid parameters');
118 }
119 }
120 });
121
122 commands.new.run(args, function(err) {
123 assert.ok(err, err);
124 done();
125 });
126 });
127
128 });
129
130 describe ('start', function(){
131
132 it('should pass job filter parameters forward', function(done){
133 var args = ['3000', '--job', 'myJobFilter'];
134 commands = proxyquire('../lib/cli/commands', {
135 './commands-logic': {
136 'start' : function(options, callback){
137 assert.equal(options.filters.jobFilter, 'myJobFilter');
138 callback();
139 }
140 }
141 });
142
143 commands.start.run(args, function(err) {
144 assert.ok(!err, err);
145 done();
146 });
147 });
148
149 it('should pass dashboard filter parameters forward', function(done){
150 var args = ['3000', '--dashboard', 'myDashboardFilter'];
151 commands = proxyquire('../lib/cli/commands', {
152 './commands-logic': {
153 'start' : function(options, callback){
154 assert.equal(options.filters.dashboardFilter, 'myDashboardFilter');
155 callback();
156 }
157 }
158 });
159
160 commands.start.run(args, function(err) {
161 assert.ok(!err, err);
162 done();
163 });
164 });
165
166 it('should pass noinstall flag forward', function(done){
167 var args = ['3000', '--noinstall'];
168 commands = proxyquire('../lib/cli/commands', {
169 './commands-logic': {
170 'start' : function(options, callback){
171 assert.equal(options.install, false);
172 callback();
173 }
174 }
175 });
176
177 commands.start.run(args, function(err) {
178 assert.ok(!err, err);
179 done();
180 });
181 });
182
183 });
184
185 describe ('install', function(){
186
187 it('should call proper logic module', function(done){
188 var args = [];
189 commands = proxyquire('../lib/cli/commands', {
190 './commands-logic': {
191 'install' : function(options, callback){
192 callback('reached');
193 }
194 }
195 });
196
197 commands.install.run(args, function(err) {
198 assert.equal(err, 'reached');
199 done();
200 });
201 });
202
203 });
204
205});
\No newline at end of file