From 76cc0b7741b6228d8e7feca12689212296d6348b Mon Sep 17 00:00:00 2001 From: nwaraya Date: Mon, 23 Apr 2018 00:56:06 -0300 Subject: [PATCH] agrego nuevos tests de files --- docker/docker-compose.yml | 2 +- package.json | 2 +- tests/routes/v0/bootstrapping.js | 64 ------------------------- tests/services/fileService_test.js | 72 ++++++++++++++++++++++++++++ tests/services/filesService_test.js | 44 ----------------- tests/services/serverService_test.js | 72 ++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+), 110 deletions(-) delete mode 100644 tests/routes/v0/bootstrapping.js create mode 100644 tests/services/fileService_test.js delete mode 100644 tests/services/filesService_test.js create mode 100644 tests/services/serverService_test.js diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 3a7272c..7f9c449 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -14,7 +14,7 @@ services: - db:database db: container_name: postgres - image: postgres + image: postgres8.4.1 restart: always # ports: # - "3052:5432" diff --git a/package.json b/package.json index 9e75066..45c742a 100755 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start-prod-heroku": "npm install sequelize sequelize-cli pg && npm install && sequelize db:migrate --env=production && PRODUCTION_HEROKU=1 node ./bin/www", "debug": "PORT=3001 node --inspect=0.0.0.0:9229 ./bin/www", "tests": "sequelize db:migrate:undo:all --env=test && sequelize db:migrate --env=test && NODE_ENV=test node_modules/.bin/mocha tests/* --recursive --exit ", - "tests": "sequelize db:migrate:undo:all --env=test && sequelize db:migrate --env=test && sequelize db:seed:all --seeders-path=/usr/src/tests/seeders/ --env=test && NODE_ENV=test node_modules/.bin/mocha tests/* --recursive --exit ", + "tests_seeds": "sequelize db:migrate:undo:all --env=test && sequelize db:migrate --env=test && sequelize db:seed:all --seeders-path=/usr/src/tests/seeders/ --env=test && NODE_ENV=test node_modules/.bin/mocha tests/* --recursive --exit ", "nyc_tests": "sequelize db:migrate:undo:all --env=test && sequelize db:migrate --env=test && NODE_ENV=test node_modules/.bin/nyc node_modules/.bin/mocha tests/* --recursive --exit ", "reset_dev": "sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all " }, diff --git a/tests/routes/v0/bootstrapping.js b/tests/routes/v0/bootstrapping.js deleted file mode 100644 index a41f6d6..0000000 --- a/tests/routes/v0/bootstrapping.js +++ /dev/null @@ -1,64 +0,0 @@ -require('dotenv').config({ path: '.env.test' }) -let models = require('../../../models/sequelize') -let app = require('../../../app') -const usuarioService = require('../../../services/usuarioService')(models) -const rolService = require('../../../services/rolService')(models) -const assert = require('chai').assert -const request = require('supertest') - - -module.exports = { - crearUsuarioInicial: (entidad, permisosNecesarios) => { - let idUsuarioCreado - let promise = new Promise((resolve) => { - models - .EstadoInforme - .findOrCreate({ where: { nombre: 'EstadoInforme estado inicial', default: true } }) - .then(function () { - const nombre = 'username' + entidad - const email = 'mailRoute' + entidad + '@mail.com' - const verifEmail = 'mailRoute' + entidad + '@mail.com' - const psw = 'mySecretpass' - const verifPsw = 'mySecretpass' - usuarioService.create(nombre, email, verifEmail, psw, verifPsw) - .then((usuario) => { - idUsuarioCreado = usuario.id - const nombre = 'nombreRolRoute' + entidad - const descripcion = 'nombreRolRoute' + entidad - return rolService.create(nombre, descripcion) - }).then((rol) => { - const idRolCreado = rol.id - usuarioService.addRolById(idUsuarioCreado, idRolCreado) - return idRolCreado - }).then((idRolCreado) => { - let permisos = [] - permisosNecesarios.forEach(function (permiso) { - permisos.push(models.Permiso.create({ - nombre: permiso, - descripcion: permiso - }).then((permisoCreado) => { - const idPermisoCreado = permisoCreado.id - return rolService.addPermisoById(idRolCreado, idPermisoCreado) - }) - ) - }) - Promise.all(permisos).then(function () { - let token - request(app) - .post('/v0/api/token') - .set('Content-Type', 'application/x-www-form-urlencoded') - .send({ username: 'mailRoute' + entidad + '@mail.com', password: 'mySecretpass' }) - .expect(200, function (err, res) { - const result = JSON.parse(res.text).data - assert(result.username === 'mailRoute' + entidad + '@mail.com', 'No coinciden los username ' + res.text) - assert(result.token !== null, 'No tiene un token') - token = result.token - resolve(token) - }) - }) - }) - }) - }) - return promise - } -} \ No newline at end of file diff --git a/tests/services/fileService_test.js b/tests/services/fileService_test.js new file mode 100644 index 0000000..a41dc1b --- /dev/null +++ b/tests/services/fileService_test.js @@ -0,0 +1,72 @@ +'use strict' +require('dotenv').config({path: '.env.test'}) +let assert = require('chai').assert +let describe = require('mocha').describe +let it = require('mocha').it +let models = require('../../models/sequelize') +const fileService = require('../../services/fileService')(models) + +let idFileCreado +let revViejo +let originalname = 'originalname' +let filename = 'filename' + +describe('Verificaciones sobre FileService', function () { + it('Obtener un file que no existe', function (done) { + fileService.get('-1').catch(function (e) { + assert(e.status === 404, 'El file existe') + done() + }) + }) + it('Agregar un file', function (done) { + let path = 'un path' + let params = { + id: null, + _rev: null, + created_at: null, + updated_at: null, + size: null, + filename: null, + resource: null + } + let file = { + filename: filename, + originalname: originalname, + path: path, + size: 100 + } + fileService.create(file, params).then((file) => { + assert(file.id !== null, 'El file no existe') + idFileCreado = file.id + assert(file.resource === path, 'El file no tiene bien el resource') + assert(file.filename === originalname, 'El file no tiene bien el filename') + assert(file._rev != null, 'El _rev no se completo') + revViejo = file._rev + done() + }) + }) + it('Obtener un file', function (done) { + fileService.get(idFileCreado.toString()).then((path_filename) => { + assert(path_filename == filename, 'El file no tiene bien el filename') + done() + }) + }) + it('Edito un file', function (done) { + let filename2 = 'filename2' + let params = { + id: idFileCreado, + _rev: revViejo, + created_at: null, + updated_at: null, + size: 1200, + filename: filename2, + resource: filename2 + } + fileService.update(idFileCreado, params).then((file) => { + assert(file.id !== null, 'El file no existe') + assert(file.filename === filename2, 'El file no tiene bien el filename') + assert(file._rev != revViejo, 'El _rev no se modifico') + done() + }) + }) +}) \ No newline at end of file diff --git a/tests/services/filesService_test.js b/tests/services/filesService_test.js deleted file mode 100644 index 41ac212..0000000 --- a/tests/services/filesService_test.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict' -require('dotenv').config({path: '.env.test'}) -let assert = require('chai').assert -let describe = require('mocha').describe -let it = require('mocha').it -let models = require('../../models/sequelize') -const fileService = require('../../services/fileService')(models) - -let idFileCreado - -describe('Verificaciones sobre FileService', function () { - it('Obtener un file que no existe', function (done) { - fileService.get('-1').catch(function (e) { - assert(e.status === 404, 'El file existe') - done() - }) - }) - /*it('Agregar un file', function (done) { - let filename = 'filename' - let originalname = 'originalname' - let params = { - id: null, - _rev: null, - created_at: null, - updated_at: null, - size: null, - filename: null, - resource: null - } - let file = { - filename: filename, - originalname: originalname, - path: 'un path', - size: 100 - } - fileService.create(file, params).then((file) => { - assert(file.id !== null, 'El file no existe') - idFileCreado = file.id - assert(file.originalname === originalname, 'El file no tiene bien el originalname') - assert(file.filename === filename, 'El file no tiene bien el filename') - done() - }) - })*/ -}) \ No newline at end of file diff --git a/tests/services/serverService_test.js b/tests/services/serverService_test.js new file mode 100644 index 0000000..134dfa9 --- /dev/null +++ b/tests/services/serverService_test.js @@ -0,0 +1,72 @@ +/*'use strict' +require('dotenv').config({path: '.env.test'}) +let assert = require('chai').assert +let describe = require('mocha').describe +let it = require('mocha').it +let models = require('../../models/sequelize') +const fileService = require('../../services/fileService')(models) + +let idFileCreado +let revViejo +let originalname = 'originalname' +let filename = 'filename' + +describe('Verificaciones sobre FileService', function () { + it('Obtener un file que no existe', function (done) { + fileService.get('-1').catch(function (e) { + assert(e.status === 404, 'El file existe') + done() + }) + }) + it('Agregar un file', function (done) { + let path = 'un path' + let params = { + id: null, + _rev: null, + created_at: null, + updated_at: null, + size: null, + filename: null, + resource: null + } + let file = { + filename: filename, + originalname: originalname, + path: path, + size: 100 + } + fileService.create(file, params).then((file) => { + assert(file.id !== null, 'El file no existe') + idFileCreado = file.id + assert(file.resource === path, 'El file no tiene bien el resource') + assert(file.filename === originalname, 'El file no tiene bien el filename') + assert(file._rev != null, 'El _rev no se completo') + revViejo = file._rev + done() + }) + }) + it('Obtener un file', function (done) { + fileService.get(idFileCreado.toString()).then((path_filename) => { + assert(path_filename == filename, 'El file no tiene bien el filename') + done() + }) + }) + it('Edito un file', function (done) { + let filename2 = 'filename2' + let params = { + id: idFileCreado, + _rev: revViejo, + created_at: null, + updated_at: null, + size: 1200, + filename: filename2, + resource: filename2 + } + fileService.update(idFileCreado, params).then((file) => { + assert(file.id !== null, 'El file no existe') + assert(file.filename === filename2, 'El file no tiene bien el filename') + assert(file._rev != revViejo, 'El _rev no se modifico') + done() + }) + }) +})*/ \ No newline at end of file