From cd09d5044644d9febf011b53fdb0f46e75306f23 Mon Sep 17 00:00:00 2001 From: efernandez Date: Mon, 25 Feb 2019 18:00:17 -0300 Subject: [PATCH] unit test --- gulpfile.js | 3 +- package.json | 3 +- spec/controllerSpec.js | 0 spec/routeSpec.js | 19 +++++++ spec/serviceSpec.js | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ src/js/app.js | 2 +- test.html | 21 +++++++ 7 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 spec/controllerSpec.js create mode 100644 spec/routeSpec.js create mode 100644 spec/serviceSpec.js create mode 100644 test.html diff --git a/gulpfile.js b/gulpfile.js index 5eeb890..3f88bcf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,6 +13,7 @@ const connect = require('gulp-connect'); var paths = { srcJS: 'src/js/*.js', srcViews: 'src/views/*.html', + specs: 'spec/*.js', tmp: 'tmp', dist: 'dist/' }; @@ -57,7 +58,7 @@ gulp.task('clean', function() { gulp.task('pre-commit', function() { return pump( [ - gulp.src(paths.srcJS), + gulp.src([paths.srcJS, paths.specs]), jshint('.jshintrc'), jshint.reporter('default'), jshint.reporter('fail') diff --git a/package.json b/package.json index 583c022..07323df 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "sistema de cobranzas a partir de facturas", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "test.html", "compile": "gulp uglify", "gulp-pre-commit": "gulp pre-commit", "postinstall": "npm run compile && gulp clean-post-install", @@ -22,6 +22,7 @@ "devDependencies": { "angular": "^1.7.5", "angular-ladda": "^0.4.3", + "angular-mocks": "^1.7.7", "angular-route": "^1.7.5", "bootstrap": "^4.1.3", "foca-botonera-facturador": "git+http://git.focasoftware.com/npm/foca-botonera-facturador.git", diff --git a/spec/controllerSpec.js b/spec/controllerSpec.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/routeSpec.js b/spec/routeSpec.js new file mode 100644 index 0000000..7d98b94 --- /dev/null +++ b/spec/routeSpec.js @@ -0,0 +1,19 @@ +describe('rutas del módulo crear cobranza', function() { + + var route; + + beforeEach(function() { + + module('focaCrearCobranza'); + inject(function($route) { + route = $route; + }); + }); + + it('route /cobranza/crear lleva a ctrl y template correcto', function() { + + //assert + expect(route.routes['/cobranza/crear'].controller).toBe('cobranzaController'); + expect(route.routes['/cobranza/crear'].templateUrl).toBe('src/views/cobranza.html'); + }); +}); \ No newline at end of file diff --git a/spec/serviceSpec.js b/spec/serviceSpec.js new file mode 100644 index 0000000..53a4731 --- /dev/null +++ b/spec/serviceSpec.js @@ -0,0 +1,148 @@ +describe('Servicios módulo crear cobranza', function() { + + beforeEach(function() { + + module('focaCrearCobranza'); + + inject(module(function($provide) { + $provide.value('API_ENDPOINT', { + URL: 'localhost' + }); + })); + }); + + describe('servicio focaCrearCobranzaService', function() { + + var servicio; + var httpBackend; + + beforeEach(function() { + inject(function($httpBackend, _focaCrearCobranzaService_) { + httpBackend = $httpBackend; + servicio = _focaCrearCobranzaService_; + }); + }); + + it('existe el servicio focaCrearCobranzaService', function() { + + //assert + expect(typeof servicio).toEqual('object'); + }); + + it('getNumeroRecibo llama a ruta correcta', function() { + + //arrange + var responseFake = 'responseFake'; + var result; + + httpBackend.expectGET('localhost/recibo/numero-siguiente').respond(responseFake); + + //act + servicio.getNumeroRecibo().then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('getCotizacionByIdMoneda llama a ruta correcta', function() { + + //arrange + var responseFake = 'responseFake'; + var result; + var paramFake = 1; + + httpBackend.expectGET('localhost/moneda/' + paramFake).respond(responseFake); + + //act + servicio.getCotizacionByIdMoneda(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('guardarCobranza llama a ruta correcta', function() { + + //arrange + var responseFake = 'responseFake'; + var result; + var paramFake = 1; + + httpBackend.expectPOST('localhost/recibo/guardar', paramFake).respond(responseFake); + + //act + servicio.guardarCobranza(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('getCobradorById llama a ruta correcta', function() { + + //arrange + var responseFake = 'responseFake'; + var result; + var paramFake = 1; + + httpBackend.expectGET('localhost/vendedor-cobrador/' + paramFake).respond(responseFake); + + //act + servicio.getCobradorById(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('enviarComprobantePorMail llama a ruta correcta', function() { + + //arrange + var responseFake = 'responseFake'; + var result; + var paramFake = 1; + + httpBackend.expectPOST('localhost/mail/comprobante', + {receiver: paramFake}).respond(responseFake); + + //act + servicio.enviarComprobantePorMail(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + + it('actualizarEmail llama a ruta correcta', function() { + + //arrange + var responseFake = 'responseFake'; + var result; + var paramFake = 1; + + httpBackend.expectPOST('localhost/cliente/update/email', + {mail: paramFake}).respond(responseFake); + + //act + servicio.actualizarEmail(paramFake).then(function(data) { + result = data.data; + }); + httpBackend.flush(); + + //assert + expect(result).toEqual(responseFake); + }); + }); + +}); \ No newline at end of file diff --git a/src/js/app.js b/src/js/app.js index 529a1d1..c062135 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -1 +1 @@ -angular.module('focaCrearCobranza', []); +angular.module('focaCrearCobranza', ['ngRoute']); diff --git a/test.html b/test.html new file mode 100644 index 0000000..6c50ce2 --- /dev/null +++ b/test.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + -- 1.9.1