Commit 4abfac3b147a454f91b48762b5133254ddd61e1d

Authored by Eric Fernandez
1 parent d7c76f29c4
Exists in master

unit test servicios y rutas

... ... @@ -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 };
... ... @@ -56,7 +57,7 @@ gulp.task('clean', function() {
56 57 gulp.task('pre-commit', function() {
57 58 return pump(
58 59 [
59   - gulp.src(paths.srcJS),
  60 + gulp.src([paths.srcJS, paths.specs]),
60 61 jshint('.jshintrc'),
61 62 jshint.reporter('default'),
62 63 jshint.reporter('fail')
... ... @@ -4,7 +4,7 @@
4 4 "description": "Listado y ABM nota de pedidos",
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",
... ... @@ -37,6 +37,7 @@
37 37 "devDependencies": {
38 38 "angular": "^1.7.5",
39 39 "angular-ladda": "^0.4.3",
  40 + "angular-mocks": "^1.7.7",
40 41 "angular-route": "^1.7.5",
41 42 "bootstrap": "^4.1.3",
42 43 "foca-busqueda-cliente": "git+http://git.focasoftware.com/npm/foca-busqueda-cliente.git",
... ... @@ -0,0 +1,19 @@
  1 +describe('Rutas del módulo crear nota de pedido', function() {
  2 +
  3 + var route;
  4 +
  5 + beforeEach(function() {
  6 + module('focaCrearNotaPedido');
  7 + inject(function($route) {
  8 + route = $route;
  9 + });
  10 + });
  11 +
  12 + it('la ruta /venta-nota-pedido/crear dirige correctamente', function() {
  13 + //expect
  14 + expect(route.routes['/venta-nota-pedido/crear'].controller)
  15 + .toBe('notaPedidoCtrl');
  16 + expect(route.routes['/venta-nota-pedido/crear'].templateUrl)
  17 + .toBe('src/views/nota-pedido.html');
  18 + });
  19 +});
... ... @@ -0,0 +1,377 @@
  1 +describe('Servicios módulo crear nota de pedido', function() {
  2 +
  3 + beforeEach(function() {
  4 + module('focaCrearNotaPedido');
  5 + });
  6 +
  7 + describe('servicios crearNotaPedidoService', function() {
  8 +
  9 + var servicio, httpBackend;
  10 +
  11 + beforeEach(function() {
  12 +
  13 + inject(module(function($provide) {
  14 + $provide.value('API_ENDPOINT', {
  15 + URL: 'localhost'
  16 + });
  17 + }));
  18 +
  19 + inject(function(_crearNotaPedidoService_, $httpBackend) {
  20 + servicio = _crearNotaPedidoService_;
  21 + httpBackend = $httpBackend;
  22 + });
  23 + });
  24 +
  25 + it('Existe el servicio crearNotaPedidoService', function() {
  26 + //assert
  27 + expect(typeof servicio).toEqual('object');
  28 + });
  29 +
  30 + it('la función crearNotaPedido lleva la ruta correcta', function() {
  31 + //arrange
  32 + var responseFake = { data: 'test'};
  33 + var result;
  34 + var bodyFake = 1;
  35 + httpBackend.expectPOST('localhost/nota-pedido', { notaPedido: bodyFake })
  36 + .respond(responseFake);
  37 +
  38 + //act
  39 + servicio.crearNotaPedido(bodyFake).then(function(data) {
  40 + result = data.data;
  41 + });
  42 + httpBackend.flush();
  43 +
  44 + //assert
  45 + expect(result).toEqual(responseFake);
  46 + });
  47 +
  48 + it('la función obtenerNotaPedido lleva la ruta correcta', function() {
  49 + //arrange
  50 + var responseFake = { data: 'test'};
  51 + var result;
  52 + httpBackend.expectGET('localhost/nota-pedido').respond(responseFake);
  53 +
  54 + //act
  55 + servicio.obtenerNotaPedido().then(function(data) {
  56 + result = data.data;
  57 + });
  58 + httpBackend.flush();
  59 +
  60 + //assert
  61 + expect(result).toEqual(responseFake);
  62 + });
  63 +
  64 + it('la función setNotaPedido setea nota pedido', function() {
  65 + //arrange
  66 + var paramFake = 1;
  67 +
  68 + //act
  69 + servicio.setNotaPedido(paramFake);
  70 +
  71 + //assert
  72 + expect(servicio.notaPedido).toEqual(paramFake);
  73 + });
  74 +
  75 + it('la función clearNotaPedido setea nota pedido undefined', function() {
  76 +
  77 + //act
  78 + servicio.clearNotaPedido();
  79 +
  80 + //assert
  81 + expect(servicio.notaPedido).toEqual(undefined);
  82 + });
  83 +
  84 + it('la función clearNotaPedido setea nota pedido undefined', function() {
  85 + //arrange
  86 + var paramFake = 1;
  87 +
  88 + //act
  89 + servicio.setNotaPedido(paramFake);
  90 + var result = servicio.getNotaPedido();
  91 +
  92 + //assert
  93 + expect(result).toEqual(paramFake);
  94 + });
  95 +
  96 + it('la funcion getArticulosByIdNotaPedido llama a la ruta correcta', function() {
  97 +
  98 + //arrange
  99 + var responseFake = { data: 'test'};
  100 + var result;
  101 + var paramFake = 1;
  102 + httpBackend.expectGET('localhost/articulos/nota-pedido/' + paramFake)
  103 + .respond(responseFake);
  104 +
  105 + //act
  106 + servicio.getArticulosByIdNotaPedido(paramFake).then(function(data) {
  107 + result = data.data;
  108 + });
  109 + httpBackend.flush();
  110 +
  111 + //assert
  112 + expect(result).toEqual(responseFake);
  113 + });
  114 +
  115 + it('la funcion crearArticulosParaNotaPedido llama a la ruta correcta', function() {
  116 +
  117 + //arrange
  118 + var responseFake = { data: 'test'};
  119 + var result;
  120 + var paramFake = 1;
  121 + httpBackend.expectPOST('localhost/articulos/nota-pedido',
  122 + {articuloNotaPedido: paramFake}).respond(responseFake);
  123 +
  124 + //act
  125 + servicio.crearArticulosParaNotaPedido(paramFake).then(function(data) {
  126 + result = data.data;
  127 + });
  128 + httpBackend.flush();
  129 +
  130 + //assert
  131 + expect(result).toEqual(responseFake);
  132 + });
  133 +
  134 + it('la funcion getDomiciliosByIdNotaPedido llama a la ruta correcta', function() {
  135 +
  136 + //arrange
  137 + var responseFake = { data: 'test'};
  138 + var result;
  139 + var paramFake = 1;
  140 + httpBackend.expectGET('localhost/nota-pedido/' + paramFake + '/domicilios')
  141 + .respond(responseFake);
  142 +
  143 + //act
  144 + servicio.getDomiciliosByIdNotaPedido(paramFake).then(function(data) {
  145 + result = data.data;
  146 + });
  147 + httpBackend.flush();
  148 +
  149 + //assert
  150 + expect(result).toEqual(responseFake);
  151 + });
  152 +
  153 + it('la funcion getDomiciliosByIdCliente llama a la ruta correcta', function() {
  154 +
  155 + //arrange
  156 + var responseFake = { data: 'test'};
  157 + var result;
  158 + var paramFake = 1;
  159 + httpBackend.expectGET('localhost/domicilio/tipo/2/cliente/' + paramFake )
  160 + .respond(responseFake);
  161 +
  162 + //act
  163 + servicio.getDomiciliosByIdCliente(paramFake).then(function(data) {
  164 + result = data.data;
  165 + });
  166 + httpBackend.flush();
  167 +
  168 + //assert
  169 + expect(result).toEqual(responseFake);
  170 + });
  171 +
  172 + it('la funcion getPrecioCondicion llama a la ruta correcta', function() {
  173 +
  174 + //arrange
  175 + var responseFake = { data: 'test'};
  176 + var result;
  177 + httpBackend.expectGET('localhost/precio-condicion').respond(responseFake);
  178 +
  179 + //act
  180 + servicio.getPrecioCondicion().then(function(data) {
  181 + result = data.data;
  182 + });
  183 + httpBackend.flush();
  184 +
  185 + //assert
  186 + expect(result).toEqual(responseFake);
  187 + });
  188 +
  189 + it('la funcion getPrecioCondicionById llama a la ruta correcta', function() {
  190 +
  191 + //arrange
  192 + var responseFake = { data: 'test'};
  193 + var result;
  194 + var paramFake = 1;
  195 + httpBackend.expectGET('localhost/precio-condicion/' + paramFake).respond(responseFake);
  196 +
  197 + //act
  198 + servicio.getPrecioCondicionById(paramFake).then(function(data) {
  199 + result = data.data;
  200 + });
  201 + httpBackend.flush();
  202 +
  203 + //assert
  204 + expect(result).toEqual(responseFake);
  205 + });
  206 +
  207 + it('la funcion getPlazoPagoByPrecioCondicion llama a la ruta correcta', function() {
  208 +
  209 + //arrange
  210 + var responseFake = { data: 'test'};
  211 + var result;
  212 + var paramFake = 1;
  213 + httpBackend.expectGET('localhost/plazo-pago/precio-condicion/' + paramFake)
  214 + .respond(responseFake);
  215 +
  216 + //act
  217 + servicio.getPlazoPagoByPrecioCondicion(paramFake).then(function(data) {
  218 + result = data.data;
  219 + });
  220 + httpBackend.flush();
  221 +
  222 + //assert
  223 + expect(result).toEqual(responseFake);
  224 + });
  225 +
  226 + it('la funcion crearFlete llama a la ruta correcta', function() {
  227 +
  228 + //arrange
  229 + var responseFake = { data: 'test'};
  230 + var result;
  231 + var paramFake = 1;
  232 + httpBackend.expectPOST('localhost/flete', { flete: paramFake })
  233 + .respond(responseFake);
  234 +
  235 + //act
  236 + servicio.crearFlete(paramFake).then(function(data) {
  237 + result = data.data;
  238 + });
  239 + httpBackend.flush();
  240 +
  241 + //assert
  242 + expect(result).toEqual(responseFake);
  243 + });
  244 +
  245 + it('la funcion crearPlazosParaNotaPedido llama a la ruta correcta', function() {
  246 +
  247 + //arrange
  248 + var responseFake = { data: 'test'};
  249 + var result;
  250 + var paramFake = 1;
  251 + httpBackend.expectPOST('localhost/plazo-pago/nota-pedido', { plazos: paramFake })
  252 + .respond(responseFake);
  253 +
  254 + //act
  255 + servicio.crearPlazosParaNotaPedido(paramFake).then(function(data) {
  256 + result = data.data;
  257 + });
  258 + httpBackend.flush();
  259 +
  260 + //assert
  261 + expect(result).toEqual(responseFake);
  262 + });
  263 +
  264 + it('la funcion getCotizacionByIdMoneda llama a la ruta correcta', function() {
  265 +
  266 + //arrange
  267 + var responseFake = { data: 'test'};
  268 + var result;
  269 + var paramFake = 1;
  270 + httpBackend.expectGET('localhost/moneda/' + paramFake).respond(responseFake);
  271 +
  272 + //act
  273 + servicio.getCotizacionByIdMoneda(paramFake).then(function(data) {
  274 + result = data.data;
  275 + });
  276 + httpBackend.flush();
  277 +
  278 + //assert
  279 + expect(result).toEqual(responseFake);
  280 + });
  281 +
  282 + it('la funcion crearEstadoParaNotaPedido llama a la ruta correcta', function() {
  283 +
  284 + //arrange
  285 + var responseFake = { data: 'test'};
  286 + var result;
  287 + var paramFake = 1;
  288 + httpBackend.expectPOST('localhost/estado', { estado: paramFake })
  289 + .respond(responseFake);
  290 +
  291 + //act
  292 + servicio.crearEstadoParaNotaPedido(paramFake).then(function(data) {
  293 + result = data.data;
  294 + });
  295 + httpBackend.flush();
  296 +
  297 + //assert
  298 + expect(result).toEqual(responseFake);
  299 + });
  300 +
  301 + it('la funcion getNumeroNotaPedido llama a la ruta correcta', function() {
  302 +
  303 + //arrange
  304 + var responseFake = { data: 'test'};
  305 + var result;
  306 + httpBackend.expectGET('localhost/nota-pedido/numero-siguiente').respond(responseFake);
  307 +
  308 + //act
  309 + servicio.getNumeroNotaPedido().then(function(data) {
  310 + result = data.data;
  311 + });
  312 + httpBackend.flush();
  313 +
  314 + //assert
  315 + expect(result).toEqual(responseFake);
  316 + });
  317 +
  318 + it('la funcion crearPuntosDescarga llama a la ruta correcta', function() {
  319 +
  320 + //arrange
  321 + var responseFake = { data: 'test'};
  322 + var result;
  323 + var paramFake = 1;
  324 + httpBackend.expectPOST('localhost/puntos-descarga/nota-pedido',
  325 + { puntosDescarga: paramFake }).respond(responseFake);
  326 +
  327 + //act
  328 + servicio.crearPuntosDescarga(paramFake).then(function(data) {
  329 + result = data.data;
  330 + });
  331 + httpBackend.flush();
  332 +
  333 + //assert
  334 + expect(result).toEqual(responseFake);
  335 + });
  336 +
  337 + it('la funcion getPuntosDescargaByClienDom llama a la ruta correcta', function() {
  338 +
  339 + //arrange
  340 + var responseFake = { data: 'test'};
  341 + var result;
  342 + var paramFake = 1;
  343 + var paramFake2 = 1;
  344 + httpBackend.expectGET('localhost/punto-descarga/' + paramFake + '/' + paramFake2)
  345 + .respond(responseFake);
  346 +
  347 + //act
  348 + servicio.getPuntosDescargaByClienDom(paramFake, paramFake2).then(function(data) {
  349 + result = data.data;
  350 + });
  351 + httpBackend.flush();
  352 +
  353 + //assert
  354 + expect(result).toEqual(responseFake);
  355 + });
  356 +
  357 + it('la funcion getVendedorById llama a la ruta correcta', function() {
  358 +
  359 + //arrange
  360 + var responseFake = { data: 'test'};
  361 + var result;
  362 + var paramFake = 1;
  363 + httpBackend.expectGET('localhost/vendedor-cobrador/' + paramFake)
  364 + .respond(responseFake);
  365 +
  366 + //act
  367 + servicio.getVendedorById(paramFake).then(function(data) {
  368 + result = data.data;
  369 + });
  370 + httpBackend.flush();
  371 +
  372 + //assert
  373 + expect(result).toEqual(responseFake);
  374 + });
  375 +
  376 + });
  377 +});
1   -angular.module('focaCrearNotaPedido', []);
  1 +angular.module('focaCrearNotaPedido', ['ngRoute']);
src/js/controller.js
... ... @@ -49,12 +49,12 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
49 49 } else {
50 50 $scope.botonera = crearNotaPedidoService.getBotonera();
51 51 }
52   -
  52 +
53 53 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
54 54 crearNotaPedidoService.getCotizacionByIdMoneda(1).then(function(res) {
55 55 $scope.monedaDefecto = res.data[0];
56 56 $scope.cotizacionDefecto = $scope.monedaDefecto.cotizaciones[0];
57   -
  57 +
58 58 init();
59 59 });
60 60 }
... ... @@ -71,7 +71,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
71 71 moneda: $scope.monedaDefecto,
72 72 cotizacion: $scope.cotizacionDefecto
73 73 };
74   -
  74 +
75 75 $scope.articulosTabla = [];
76 76 $scope.idLista = undefined;
77 77  
... ... @@ -194,7 +194,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
194 194 dias: plazo.dias
195 195 });
196 196 });
197   -
  197 +
198 198 if (plazosACrear.length) {
199 199 crearNotaPedidoService.crearPlazosParaNotaPedido(plazosACrear);
200 200 }
... ... @@ -204,7 +204,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
204 204  
205 205 focaBotoneraLateralService.endGuardar(true);
206 206 $scope.saveLoading = false;
207   -
  207 +
208 208 init();
209 209 }, function(error) {
210 210 focaModalService.alert('Hubo un error al crear la nota de pedido');
... ... @@ -308,7 +308,7 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
308 308 }
309 309 cabeceras.push(cabeceraBomba);
310 310 }
311   -
  311 +
312 312 $scope.articulosTabla = notaPedido.articulosNotaPedido;
313 313 notaPedidoBusinessService.calcularArticulos($scope.articulosTabla,
314 314 notaPedido.cotizacion.VENDEDOR);
... ... @@ -318,15 +318,15 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
318 318 } else {
319 319 $scope.idLista = -1;
320 320 }
321   -
  321 +
322 322 $scope.puntoVenta = $filter('rellenarDigitos')(
323 323 notaPedido.sucursal, 4
324 324 );
325   -
  325 +
326 326 $scope.comprobante = $filter('rellenarDigitos')(
327 327 notaPedido.numeroNotaPedido, 8
328 328 );
329   -
  329 +
330 330 $scope.notaPedido = notaPedido;
331 331 $scope.notaPedido.moneda = notaPedido.cotizacion.moneda;
332 332 $scope.plazosPagos = notaPedido.notaPedidoPlazo;
... ... @@ -767,14 +767,14 @@ angular.module('focaCrearNotaPedido') .controller('notaPedidoCtrl',
767 767 modalInstance.result.then(
768 768 function(cotizacion) {
769 769 var articulosTablaTemp = $scope.articulosTabla;
770   -
  770 +
771 771 for(var i = 0; i < articulosTablaTemp.length; i++) {
772 772 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio *
773 773 $scope.notaPedido.cotizacion.VENDEDOR;
774 774 articulosTablaTemp[i].precio = articulosTablaTemp[i].precio /
775 775 cotizacion.VENDEDOR;
776 776 }
777   -
  777 +
778 778 $scope.articulosTabla = articulosTablaTemp;
779 779 $scope.notaPedido.moneda = moneda;
780 780 $scope.monedaDefecto = moneda;
... ... @@ -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>