Commit 17de1e938ff26ef8f7dcfba5cf4049cf69f5f441

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !55
... ... @@ -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')
... ... @@ -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
... ... @@ -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,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
1   -angular.module('focaCrearCobranza', []);
  1 +angular.module('focaCrearCobranza', ['ngRoute']);
src/js/controller.js
... ... @@ -22,19 +22,19 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
22 22 maxDate: new Date(),
23 23 minDate: new Date(2010, 0, 1)
24 24 };
25   -
  25 +
26 26 var monedaPorDefecto;
27 27 //Trabajo con la cotización más reciente, por eso uso siempre la primera '[0]'
28 28 focaCrearCobranzaService.getCotizacionByIdMoneda(1).then(function(res) {
29 29 monedaPorDefecto = res.data[0];
30   -
  30 +
31 31 $scope.cobranza.moneda = monedaPorDefecto;
32 32 $scope.inicial.cobranza.moneda = $scope.cobranza.moneda;
33   -
  33 +
34 34 $scope.cobranza.cotizacion = monedaPorDefecto.cotizaciones[0];
35 35 $scope.inicial.cobranza.cotizacion = $scope.cobranza.cotizacion;
36 36 });
37   -
  37 +
38 38 $timeout(function() {
39 39 focaBotoneraLateralService.showSalir(false);
40 40 focaBotoneraLateralService.showPausar(true);
... ... @@ -51,25 +51,25 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
51 51  
52 52 init();
53 53 }
54   -
  54 +
55 55 function init() {
56 56 $scope.$broadcast('cleanCabecera');
57 57  
58 58 $scope.cobranza = {};
59 59 $scope.facturaTabla = [];
60 60 $scope.cobrosTabla = [];
61   -
  61 +
62 62 if (APP === 'cobranza') {
63 63 focaCrearCobranzaService.getCobradorById($scope.idCobrador).then(
64 64 function(res) {
65 65 var cobrador = res.data;
66   -
  66 +
67 67 $scope.$broadcast('addCabecera', {
68 68 label: 'Cobrador:',
69 69 valor: $filter('rellenarDigitos')(cobrador.NUM, 3) + ' - ' +
70 70 cobrador.NOM
71 71 });
72   -
  72 +
73 73 $scope.cobranza.cobrador = cobrador;
74 74 $scope.inicial.cobranza.cobrador = $scope.cobranza.cobrador;
75 75 }
... ... @@ -87,7 +87,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
87 87 $scope.puntoVenta = $filter('rellenarDigitos')(
88 88 res.data.sucursal, 4
89 89 );
90   -
  90 +
91 91 $scope.comprobante = $filter('rellenarDigitos')(
92 92 res.data.numeroRecibo, 8
93 93 );
... ... @@ -119,7 +119,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
119 119 $scope.cobranza.moneda.SIMBOLO + '0,00');
120 120 return;
121 121 }
122   -
  122 +
123 123 var cobranza = {};
124 124 var cheques = [];
125 125 var cuerpos = [];
... ... @@ -147,7 +147,7 @@ angular.module('focaCrearCobranza') .controller('cobranzaController',
147 147 NCU: $scope.facturaTabla[i].NCU
148 148 };
149 149 cuerpos.push(cuerpoFactura);
150   -
  150 +
151 151 }
152 152  
153 153 for (var j = 0; j < $scope.cobrosTabla.length; j++) {
... ... @@ -162,7 +162,7 @@ angular.module(&#39;focaCrearCobranza&#39;) .controller(&#39;cobranzaController&#39;,
162 162 LOP: 'P',
163 163 TIL: $scope.cobrosTabla[j].til,
164 164 COM: efectivo ? 'ef(COBRO EN EFECTIVO)' : $scope.cobrosTabla[j].tipo,
165   - FEC: !$scope.cobrosTabla[j].fechaPresentacion ?
  165 + FEC: !$scope.cobrosTabla[j].fechaPresentacion ?
166 166 $scope.cobrosTabla[j].fecha
167 167 .toISOString().slice(0, 19).replace('T', ' ') :
168 168 $scope.cobrosTabla[j].fechaPresentacion
... ... @@ -284,7 +284,7 @@ angular.module(&#39;focaCrearCobranza&#39;) .controller(&#39;cobranzaController&#39;,
284 284 if (c.NCU) delete c.NCU;
285 285 return c;
286 286 });
287   -
  287 +
288 288 focaCrearCobranzaService
289 289 .guardarCobranza(cobranza)
290 290 .then(
... ... @@ -313,7 +313,7 @@ angular.module(&#39;focaCrearCobranza&#39;) .controller(&#39;cobranzaController&#39;,
313 313 result.data,
314 314 ''
315 315 );
316   -
  316 +
317 317 init();
318 318 }, function(error) {
319 319 focaModalService.alert('Hubo un problema al cargar la cobranza');
... ... @@ -472,7 +472,7 @@ angular.module(&#39;focaCrearCobranza&#39;) .controller(&#39;cobranzaController&#39;,
472 472 }
473 473 );
474 474 };
475   -
  475 +
476 476 $scope.seleccionarEfectivo = function() {
477 477 var modalInstance = $uibModal.open(
478 478 {
... ... @@ -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>