diff --git a/services/auth/server/boot/specs/routes.spec.js b/services/auth/server/boot/specs/routes.spec.js index 2ea72a1e9..73215ad68 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'; +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/greuge/specs/total.spec.js b/services/client/common/methods/greuge/specs/total.spec.js index 846ce752e..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 @@ -import totalGreuge from '../total'; -import {catchErrors} from '../../../../../../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/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/loopback/common/methods/client/specs/addressesPropagateRe.spec.js b/services/loopback/common/methods/client/specs/addressesPropagateRe.spec.js index 5e7a7bac5..87a841def 100644 --- a/services/loopback/common/methods/client/specs/addressesPropagateRe.spec.js +++ b/services/loopback/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'; +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/loopback/common/methods/client/specs/card.spec.js b/services/loopback/common/methods/client/specs/card.spec.js index abe314fff..a7de41776 100644 --- a/services/loopback/common/methods/client/specs/card.spec.js +++ b/services/loopback/common/methods/client/specs/card.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../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/loopback/common/methods/client/specs/createWithUser.spec.js b/services/loopback/common/methods/client/specs/createWithUser.spec.js index 8ac31a7de..d2981aea2 100644 --- a/services/loopback/common/methods/client/specs/createWithUser.spec.js +++ b/services/loopback/common/methods/client/specs/createWithUser.spec.js @@ -1,6 +1,6 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; -import restoreFixtures from '../../../../../../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/loopback/common/methods/client/specs/hasCustomerRole.spec.js b/services/loopback/common/methods/client/specs/hasCustomerRole.spec.js index c8b866082..637d3be88 100644 --- a/services/loopback/common/methods/client/specs/hasCustomerRole.spec.js +++ b/services/loopback/common/methods/client/specs/hasCustomerRole.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Client hasCustomerRole', () => { it('should call the hasCustomerRole() method with a customer id', done => { diff --git a/services/loopback/common/methods/client/specs/listAddresses.spec.js b/services/loopback/common/methods/client/specs/listAddresses.spec.js index 3575d3a5e..594b1c9e7 100644 --- a/services/loopback/common/methods/client/specs/listAddresses.spec.js +++ b/services/loopback/common/methods/client/specs/listAddresses.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers'); describe('Client addresses', () => { it('should call the listAddresses method and receive total results and items', done => { diff --git a/services/loopback/common/methods/client/specs/listWorkers.spec.js b/services/loopback/common/methods/client/specs/listWorkers.spec.js index 00194842e..532d44aac 100644 --- a/services/loopback/common/methods/client/specs/listWorkers.spec.js +++ b/services/loopback/common/methods/client/specs/listWorkers.spec.js @@ -1,5 +1,5 @@ -import app from '../../../../server/server'; -import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +const app = require('../../../../server/server'); +const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; describe('Client listWorkers', () => { it('should call the listWorkers()', done => { diff --git a/services/loopback/common/methods/client/specs/salesperson.spec.js b/services/loopback/common/methods/client/specs/salesperson.spec.js new file mode 100644 index 000000000..a2688c9b4 --- /dev/null +++ b/services/loopback/common/methods/client/specs/salesperson.spec.js @@ -0,0 +1,33 @@ +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 => { + let filter = { + limit: 1 + }; + + let callback = (error, result) => { + if (error) return catchErrors(done)(error); + + expect(result.length).toEqual(1); + done(); + }; + + app.models.Client.activeSalesPerson(filter, callback); + }); + + it('should call the activeSalesPerson() method with no limit and receive all 3 salesPersons', done => { + let filter = { + }; + + let callback = (error, result) => { + if (error) return catchErrors(done)(error); + + expect(result.length).toEqual(3); + done(); + }; + + app.models.Client.activeSalesPerson(filter, callback); + }); +}); diff --git a/services/utils/jasmineHelpers.js b/services/utils/jasmineHelpers.js index 11a808d1d..fd0b82c5a 100644 --- a/services/utils/jasmineHelpers.js +++ b/services/utils/jasmineHelpers.js @@ -1,8 +1,8 @@ -export function catchErrors(done) { +module.exports.catchErrors = function(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 => {