Commit cd09d5044644d9febf011b53fdb0f46e75306f23
1 parent
56cbcbad48
Exists in
master
unit test
Showing
7 changed files
with
193 additions
and
3 deletions
Show diff stats
gulpfile.js
... | ... | @@ -13,6 +13,7 @@ const connect = require('gulp-connect'); |
13 | 13 | var paths = { |
14 | 14 | srcJS: 'src/js/*.js', |
15 | 15 | srcViews: 'src/views/*.html', |
16 | + specs: 'spec/*.js', | |
16 | 17 | tmp: 'tmp', |
17 | 18 | dist: 'dist/' |
18 | 19 | }; |
... | ... | @@ -57,7 +58,7 @@ gulp.task('clean', function() { |
57 | 58 | gulp.task('pre-commit', function() { |
58 | 59 | return pump( |
59 | 60 | [ |
60 | - gulp.src(paths.srcJS), | |
61 | + gulp.src([paths.srcJS, paths.specs]), | |
61 | 62 | jshint('.jshintrc'), |
62 | 63 | jshint.reporter('default'), |
63 | 64 | jshint.reporter('fail') |
package.json
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | "description": "sistema de cobranzas a partir de facturas", |
5 | 5 | "main": "index.js", |
6 | 6 | "scripts": { |
7 | - "test": "echo \"Error: no test specified\" && exit 1", | |
7 | + "test": "test.html", | |
8 | 8 | "compile": "gulp uglify", |
9 | 9 | "gulp-pre-commit": "gulp pre-commit", |
10 | 10 | "postinstall": "npm run compile && gulp clean-post-install", |
... | ... | @@ -22,6 +22,7 @@ |
22 | 22 | "devDependencies": { |
23 | 23 | "angular": "^1.7.5", |
24 | 24 | "angular-ladda": "^0.4.3", |
25 | + "angular-mocks": "^1.7.7", | |
25 | 26 | "angular-route": "^1.7.5", |
26 | 27 | "bootstrap": "^4.1.3", |
27 | 28 | "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git", |
spec/controllerSpec.js
spec/routeSpec.js
... | ... | @@ -0,0 +1,19 @@ |
1 | +describe('rutas del módulo crear cobranza', function() { | |
2 | + | |
3 | + var route; | |
4 | + | |
5 | + beforeEach(function() { | |
6 | + | |
7 | + module('focaCrearCobranza'); | |
8 | + inject(function($route) { | |
9 | + route = $route; | |
10 | + }); | |
11 | + }); | |
12 | + | |
13 | + it('route /cobranza/crear lleva a ctrl y template correcto', function() { | |
14 | + | |
15 | + //assert | |
16 | + expect(route.routes['/cobranza/crear'].controller).toBe('cobranzaController'); | |
17 | + expect(route.routes['/cobranza/crear'].templateUrl).toBe('src/views/cobranza.html'); | |
18 | + }); | |
19 | +}); | |
0 | 20 | \ No newline at end of file |
spec/serviceSpec.js
... | ... | @@ -0,0 +1,148 @@ |
1 | +describe('Servicios módulo crear cobranza', function() { | |
2 | + | |
3 | + beforeEach(function() { | |
4 | + | |
5 | + module('focaCrearCobranza'); | |
6 | + | |
7 | + inject(module(function($provide) { | |
8 | + $provide.value('API_ENDPOINT', { | |
9 | + URL: 'localhost' | |
10 | + }); | |
11 | + })); | |
12 | + }); | |
13 | + | |
14 | + describe('servicio focaCrearCobranzaService', function() { | |
15 | + | |
16 | + var servicio; | |
17 | + var httpBackend; | |
18 | + | |
19 | + beforeEach(function() { | |
20 | + inject(function($httpBackend, _focaCrearCobranzaService_) { | |
21 | + httpBackend = $httpBackend; | |
22 | + servicio = _focaCrearCobranzaService_; | |
23 | + }); | |
24 | + }); | |
25 | + | |
26 | + it('existe el servicio focaCrearCobranzaService', function() { | |
27 | + | |
28 | + //assert | |
29 | + expect(typeof servicio).toEqual('object'); | |
30 | + }); | |
31 | + | |
32 | + it('getNumeroRecibo llama a ruta correcta', function() { | |
33 | + | |
34 | + //arrange | |
35 | + var responseFake = 'responseFake'; | |
36 | + var result; | |
37 | + | |
38 | + httpBackend.expectGET('localhost/recibo/numero-siguiente').respond(responseFake); | |
39 | + | |
40 | + //act | |
41 | + servicio.getNumeroRecibo().then(function(data) { | |
42 | + result = data.data; | |
43 | + }); | |
44 | + httpBackend.flush(); | |
45 | + | |
46 | + //assert | |
47 | + expect(result).toEqual(responseFake); | |
48 | + }); | |
49 | + | |
50 | + it('getCotizacionByIdMoneda llama a ruta correcta', function() { | |
51 | + | |
52 | + //arrange | |
53 | + var responseFake = 'responseFake'; | |
54 | + var result; | |
55 | + var paramFake = 1; | |
56 | + | |
57 | + httpBackend.expectGET('localhost/moneda/' + paramFake).respond(responseFake); | |
58 | + | |
59 | + //act | |
60 | + servicio.getCotizacionByIdMoneda(paramFake).then(function(data) { | |
61 | + result = data.data; | |
62 | + }); | |
63 | + httpBackend.flush(); | |
64 | + | |
65 | + //assert | |
66 | + expect(result).toEqual(responseFake); | |
67 | + }); | |
68 | + | |
69 | + it('guardarCobranza llama a ruta correcta', function() { | |
70 | + | |
71 | + //arrange | |
72 | + var responseFake = 'responseFake'; | |
73 | + var result; | |
74 | + var paramFake = 1; | |
75 | + | |
76 | + httpBackend.expectPOST('localhost/recibo/guardar', paramFake).respond(responseFake); | |
77 | + | |
78 | + //act | |
79 | + servicio.guardarCobranza(paramFake).then(function(data) { | |
80 | + result = data.data; | |
81 | + }); | |
82 | + httpBackend.flush(); | |
83 | + | |
84 | + //assert | |
85 | + expect(result).toEqual(responseFake); | |
86 | + }); | |
87 | + | |
88 | + it('getCobradorById llama a ruta correcta', function() { | |
89 | + | |
90 | + //arrange | |
91 | + var responseFake = 'responseFake'; | |
92 | + var result; | |
93 | + var paramFake = 1; | |
94 | + | |
95 | + httpBackend.expectGET('localhost/vendedor-cobrador/' + paramFake).respond(responseFake); | |
96 | + | |
97 | + //act | |
98 | + servicio.getCobradorById(paramFake).then(function(data) { | |
99 | + result = data.data; | |
100 | + }); | |
101 | + httpBackend.flush(); | |
102 | + | |
103 | + //assert | |
104 | + expect(result).toEqual(responseFake); | |
105 | + }); | |
106 | + | |
107 | + it('enviarComprobantePorMail llama a ruta correcta', function() { | |
108 | + | |
109 | + //arrange | |
110 | + var responseFake = 'responseFake'; | |
111 | + var result; | |
112 | + var paramFake = 1; | |
113 | + | |
114 | + httpBackend.expectPOST('localhost/mail/comprobante', | |
115 | + {receiver: paramFake}).respond(responseFake); | |
116 | + | |
117 | + //act | |
118 | + servicio.enviarComprobantePorMail(paramFake).then(function(data) { | |
119 | + result = data.data; | |
120 | + }); | |
121 | + httpBackend.flush(); | |
122 | + | |
123 | + //assert | |
124 | + expect(result).toEqual(responseFake); | |
125 | + }); | |
126 | + | |
127 | + it('actualizarEmail llama a ruta correcta', function() { | |
128 | + | |
129 | + //arrange | |
130 | + var responseFake = 'responseFake'; | |
131 | + var result; | |
132 | + var paramFake = 1; | |
133 | + | |
134 | + httpBackend.expectPOST('localhost/cliente/update/email', | |
135 | + {mail: paramFake}).respond(responseFake); | |
136 | + | |
137 | + //act | |
138 | + servicio.actualizarEmail(paramFake).then(function(data) { | |
139 | + result = data.data; | |
140 | + }); | |
141 | + httpBackend.flush(); | |
142 | + | |
143 | + //assert | |
144 | + expect(result).toEqual(responseFake); | |
145 | + }); | |
146 | + }); | |
147 | + | |
148 | +}); | |
0 | 149 | \ No newline at end of file |
src/js/app.js
test.html
... | ... | @@ -0,0 +1,21 @@ |
1 | +<html> | |
2 | + <head> | |
3 | + <link rel="stylesheet" type="text/css" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css"> | |
4 | + <meta charset="UTF-8" /> | |
5 | + </head> | |
6 | + <body> | |
7 | + <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> | |
8 | + <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> | |
9 | + <script type="text/javascript" src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script> | |
10 | + <script type="text/javascript" src="node_modules/angular/angular.min.js"></script> | |
11 | + <script type="text/javascript" src="node_modules/angular-route/angular-route.min.js"></script> | |
12 | + <script type="text/javascript" src="node_modules/angular-mocks/angular-mocks.js"></script> | |
13 | + <script type="text/javascript" src="src/js/app.js"></script> | |
14 | + <script type="text/javascript" src="src/js/controller.js"></script> | |
15 | + <script type="text/javascript" src="src/js/service.js"></script> | |
16 | + <script type="text/javascript" src="src/js/route.js"></script> | |
17 | + <script type="text/javascript" src="spec/controllerSpec.js"></script> | |
18 | + <script type="text/javascript" src="spec/serviceSpec.js"></script> | |
19 | + <script type="text/javascript" src="spec/routeSpec.js"></script> | |
20 | + </body> | |
21 | +</html> |