From 215ae09b70a2089476a914ffee9bf60cd7ac32d6 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 31 Jan 2018 11:15:12 +0100 Subject: [PATCH 1/2] refactor to remove import from backend testing in order to use require --- services/auth/server/boot/specs/routes.spec.js | 6 +++--- .../client/common/methods/client/specs/addresses.spec.js | 4 ++-- .../methods/client/specs/addressesPropagateRe.spec.js | 6 +++--- services/client/common/methods/client/specs/card.spec.js | 4 ++-- services/client/common/methods/client/specs/create.spec.js | 6 +++--- .../client/common/methods/client/specs/employee.spec.js | 4 ++-- services/client/common/methods/client/specs/roles.spec.js | 4 ++-- .../client/common/methods/client/specs/salesperson.spec.js | 4 ++-- services/client/common/methods/greuge/specs/total.spec.js | 4 ++-- services/db/testing_fixtures.js | 5 ++--- services/utils/jasmineHelpers.js | 4 ++-- services_tests.js | 2 -- 12 files changed, 25 insertions(+), 28 deletions(-) diff --git a/services/auth/server/boot/specs/routes.spec.js b/services/auth/server/boot/specs/routes.spec.js index 2ea72a1e9..ca5ca06e0 100644 --- a/services/auth/server/boot/specs/routes.spec.js +++ b/services/auth/server/boot/specs/routes.spec.js @@ -1,6 +1,6 @@ -import app from '../../../server/server'; -import routes from '../routes'; -import restoreFixtures from '../../../../../services/db/testing_fixtures'; +let app = require('../../../server/server'); +let routes = require('../routes'); +let restoreFixtures = require('../../../../../services/db/testing_fixtures'); describe('Auth routes', () => { let fixturesToApply = {tables: ['`salix`.`user`'], inserts: [ diff --git a/services/client/common/methods/client/specs/addresses.spec.js b/services/client/common/methods/client/specs/addresses.spec.js index a56b9c981..809f80875 100644 --- a/services/client/common/methods/client/specs/addresses.spec.js +++ b/services/client/common/methods/client/specs/addresses.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +let app = require('../../../../server/server'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Client addresses', () => { it('should call the addressesList method and receive total results and items', done => { diff --git a/services/client/common/methods/client/specs/addressesPropagateRe.spec.js b/services/client/common/methods/client/specs/addressesPropagateRe.spec.js index 5e7a7bac5..d055cc86f 100644 --- a/services/client/common/methods/client/specs/addressesPropagateRe.spec.js +++ b/services/client/common/methods/client/specs/addressesPropagateRe.spec.js @@ -1,6 +1,6 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; -import restoreFixtures from '../../../../../../services/db/testing_fixtures'; +let app = require('../../../../server/server'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +let restoreFixtures = require('../../../../../../services/db/testing_fixtures'); describe('Client addressesPropagateRe', () => { let fixturesToApply = {tables: ['`account`.`user`', '`vn2008`.`Clientes`', '`vn2008`.`Consignatarios`'], inserts: [ diff --git a/services/client/common/methods/client/specs/card.spec.js b/services/client/common/methods/client/specs/card.spec.js index abe314fff..895097cac 100644 --- a/services/client/common/methods/client/specs/card.spec.js +++ b/services/client/common/methods/client/specs/card.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +let app = require('../../../../server/server'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Client card', () => { it('should call the card() method to receive a formated card of Bruce Wayne', done => { diff --git a/services/client/common/methods/client/specs/create.spec.js b/services/client/common/methods/client/specs/create.spec.js index e10fb62c6..9b6295483 100644 --- a/services/client/common/methods/client/specs/create.spec.js +++ b/services/client/common/methods/client/specs/create.spec.js @@ -1,6 +1,6 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; -import restoreFixtures from '../../../../../../services/db/testing_fixtures'; +let app = require('../../../../server/server'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +let restoreFixtures = require('../../../../../../services/db/testing_fixtures'); describe('Client Create', () => { let fixturesToApply = {tables: ['`account`.`user`', '`vn2008`.`Clientes`', '`vn2008`.`Consignatarios`'], inserts: [ diff --git a/services/client/common/methods/client/specs/employee.spec.js b/services/client/common/methods/client/specs/employee.spec.js index 2cbaa4020..04726aeb9 100644 --- a/services/client/common/methods/client/specs/employee.spec.js +++ b/services/client/common/methods/client/specs/employee.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +let app = require('../../../../server/server'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Client employeeList', () => { it('should call the employeeList()', done => { diff --git a/services/client/common/methods/client/specs/roles.spec.js b/services/client/common/methods/client/specs/roles.spec.js index 559d272b2..b6ef8240c 100644 --- a/services/client/common/methods/client/specs/roles.spec.js +++ b/services/client/common/methods/client/specs/roles.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +let app = require('../../../../server/server'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Client getRoleCustomer', () => { it('should call the getRoleCustomer() method with a customer id', done => { diff --git a/services/client/common/methods/client/specs/salesperson.spec.js b/services/client/common/methods/client/specs/salesperson.spec.js index fa5cc4ea7..c95b9bf52 100644 --- a/services/client/common/methods/client/specs/salesperson.spec.js +++ b/services/client/common/methods/client/specs/salesperson.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +let app = require('../../../../server/server'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Client activeSalesPerson', () => { it('should call the activeSalesPerson() method with limit of 1', done => { diff --git a/services/client/common/methods/greuge/specs/total.spec.js b/services/client/common/methods/greuge/specs/total.spec.js index 846ce752e..b088692fc 100644 --- a/services/client/common/methods/greuge/specs/total.spec.js +++ b/services/client/common/methods/greuge/specs/total.spec.js @@ -1,5 +1,5 @@ -import totalGreuge from '../total'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +let totalGreuge = require('../total'); +let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Greuge totalGreuge()', () => { it('should call the sumAmount method', done => { diff --git a/services/db/testing_fixtures.js b/services/db/testing_fixtures.js index 21954fb19..9b7fa6b65 100644 --- a/services/db/testing_fixtures.js +++ b/services/db/testing_fixtures.js @@ -32,11 +32,10 @@ let truncate = (tables, callback) => { connection.connect(); -export default function restoreFixtures(fixturesToApply, callback) { +module.exports = function restoreFixtures(fixturesToApply, callback) { connection.query('SET FOREIGN_KEY_CHECKS = 0', () => { truncate(fixturesToApply.tables, () => { insertFixtures(fixturesToApply.inserts, callback); }); }); -} - +}; diff --git a/services/utils/jasmineHelpers.js b/services/utils/jasmineHelpers.js index 11a808d1d..ab45069c3 100644 --- a/services/utils/jasmineHelpers.js +++ b/services/utils/jasmineHelpers.js @@ -1,8 +1,8 @@ -export function catchErrors(done) { +module.exports = function catchErrors(done) { return error => { if (error instanceof Error) { return done.fail(error.stack); } return done.fail(JSON.stringify(error)); }; -} +}; diff --git a/services_tests.js b/services_tests.js index f3fccbde3..d91e31c84 100644 --- a/services_tests.js +++ b/services_tests.js @@ -1,5 +1,3 @@ -require('babel-core/register')({presets: ['es2015']}); - process.env.NODE_ENV = 'test'; process.on('warning', warning => { From cd027a3e12811a6436a3e88fced0a4c838cc006d Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 31 Jan 2018 12:02:35 +0100 Subject: [PATCH 2/2] refactor to avoid using import on backend testing env --- services/auth/server/boot/specs/routes.spec.js | 6 +++--- .../client/common/methods/client/specs/addresses.spec.js | 4 ++-- .../methods/client/specs/addressesPropagateRe.spec.js | 6 +++--- services/client/common/methods/client/specs/card.spec.js | 4 ++-- services/client/common/methods/client/specs/create.spec.js | 6 +++--- .../client/common/methods/client/specs/employee.spec.js | 4 ++-- services/client/common/methods/client/specs/roles.spec.js | 4 ++-- .../client/common/methods/client/specs/salesperson.spec.js | 4 ++-- services/client/common/methods/greuge/specs/total.spec.js | 4 ++-- services/utils/jasmineHelpers.js | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/services/auth/server/boot/specs/routes.spec.js b/services/auth/server/boot/specs/routes.spec.js index ca5ca06e0..73215ad68 100644 --- a/services/auth/server/boot/specs/routes.spec.js +++ b/services/auth/server/boot/specs/routes.spec.js @@ -1,6 +1,6 @@ -let app = require('../../../server/server'); -let routes = require('../routes'); -let restoreFixtures = require('../../../../../services/db/testing_fixtures'); +const app = require('../../../server/server'); +const routes = require('../routes'); +const restoreFixtures = require('../../../../../services/db/testing_fixtures'); describe('Auth routes', () => { let fixturesToApply = {tables: ['`salix`.`user`'], inserts: [ diff --git a/services/client/common/methods/client/specs/addresses.spec.js b/services/client/common/methods/client/specs/addresses.spec.js index 809f80875..d679dff22 100644 --- a/services/client/common/methods/client/specs/addresses.spec.js +++ b/services/client/common/methods/client/specs/addresses.spec.js @@ -1,5 +1,5 @@ -let app = require('../../../../server/server'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Client addresses', () => { it('should call the addressesList method and receive total results and items', done => { diff --git a/services/client/common/methods/client/specs/addressesPropagateRe.spec.js b/services/client/common/methods/client/specs/addressesPropagateRe.spec.js index d055cc86f..87a841def 100644 --- a/services/client/common/methods/client/specs/addressesPropagateRe.spec.js +++ b/services/client/common/methods/client/specs/addressesPropagateRe.spec.js @@ -1,6 +1,6 @@ -let app = require('../../../../server/server'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); -let restoreFixtures = require('../../../../../../services/db/testing_fixtures'); +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; +const restoreFixtures = require('../../../../../../services/db/testing_fixtures'); describe('Client addressesPropagateRe', () => { let fixturesToApply = {tables: ['`account`.`user`', '`vn2008`.`Clientes`', '`vn2008`.`Consignatarios`'], inserts: [ diff --git a/services/client/common/methods/client/specs/card.spec.js b/services/client/common/methods/client/specs/card.spec.js index 895097cac..a7de41776 100644 --- a/services/client/common/methods/client/specs/card.spec.js +++ b/services/client/common/methods/client/specs/card.spec.js @@ -1,5 +1,5 @@ -let app = require('../../../../server/server'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Client card', () => { it('should call the card() method to receive a formated card of Bruce Wayne', done => { diff --git a/services/client/common/methods/client/specs/create.spec.js b/services/client/common/methods/client/specs/create.spec.js index 9b6295483..15b3e000b 100644 --- a/services/client/common/methods/client/specs/create.spec.js +++ b/services/client/common/methods/client/specs/create.spec.js @@ -1,6 +1,6 @@ -let app = require('../../../../server/server'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); -let restoreFixtures = require('../../../../../../services/db/testing_fixtures'); +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; +const restoreFixtures = require('../../../../../../services/db/testing_fixtures'); describe('Client Create', () => { let fixturesToApply = {tables: ['`account`.`user`', '`vn2008`.`Clientes`', '`vn2008`.`Consignatarios`'], inserts: [ diff --git a/services/client/common/methods/client/specs/employee.spec.js b/services/client/common/methods/client/specs/employee.spec.js index 04726aeb9..208956961 100644 --- a/services/client/common/methods/client/specs/employee.spec.js +++ b/services/client/common/methods/client/specs/employee.spec.js @@ -1,5 +1,5 @@ -let app = require('../../../../server/server'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Client employeeList', () => { it('should call the employeeList()', done => { diff --git a/services/client/common/methods/client/specs/roles.spec.js b/services/client/common/methods/client/specs/roles.spec.js index b6ef8240c..a98c4c6f7 100644 --- a/services/client/common/methods/client/specs/roles.spec.js +++ b/services/client/common/methods/client/specs/roles.spec.js @@ -1,5 +1,5 @@ -let app = require('../../../../server/server'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Client getRoleCustomer', () => { it('should call the getRoleCustomer() method with a customer id', done => { diff --git a/services/client/common/methods/client/specs/salesperson.spec.js b/services/client/common/methods/client/specs/salesperson.spec.js index c95b9bf52..a2688c9b4 100644 --- a/services/client/common/methods/client/specs/salesperson.spec.js +++ b/services/client/common/methods/client/specs/salesperson.spec.js @@ -1,5 +1,5 @@ -let app = require('../../../../server/server'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Client activeSalesPerson', () => { it('should call the activeSalesPerson() method with limit of 1', done => { diff --git a/services/client/common/methods/greuge/specs/total.spec.js b/services/client/common/methods/greuge/specs/total.spec.js index b088692fc..1646d9c38 100644 --- a/services/client/common/methods/greuge/specs/total.spec.js +++ b/services/client/common/methods/greuge/specs/total.spec.js @@ -1,5 +1,5 @@ -let totalGreuge = require('../total'); -let catchErrors = require('../../../../../../services/utils/jasmineHelpers'); +const totalGreuge = require('../total'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Greuge totalGreuge()', () => { it('should call the sumAmount method', done => { diff --git a/services/utils/jasmineHelpers.js b/services/utils/jasmineHelpers.js index ab45069c3..fd0b82c5a 100644 --- a/services/utils/jasmineHelpers.js +++ b/services/utils/jasmineHelpers.js @@ -1,4 +1,4 @@ -module.exports = function catchErrors(done) { +module.exports.catchErrors = function(done) { return error => { if (error instanceof Error) { return done.fail(error.stack);