From 6f162c774e527eeb51e0305f81e0bc19d2765748 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Thu, 19 Apr 2018 11:20:41 +0200 Subject: [PATCH] fixes and refactor in several spec files --- .../client/specs/getAverageInvoiced.spec.js | 12 +----- .../methods/client/specs/getMana.spec.js | 12 +----- .../methods/ticket/specs/get-taxes.spec.js | 12 +----- .../methods/ticket/specs/get-total.spec.js | 14 ++----- .../methods/ticket/specs/get-volume.spec.js | 12 +----- .../methods/ticket/specs/summary.spec.js | 30 +++++--------- .../loopback/common/test-helpers/loopback.js | 39 ------------------- services_tests.js | 1 + 8 files changed, 22 insertions(+), 110 deletions(-) delete mode 100644 services/loopback/common/test-helpers/loopback.js diff --git a/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js b/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js index 9d076c9f0..8bd2d9baa 100644 --- a/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js +++ b/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js @@ -1,16 +1,8 @@ -const getAverageInvoiced = require('../getAverageInvoiced'); -const model = { - remoteMethod: () => {} -}; -let Loopback = require('../../../test-helpers/loopback'); -Loopback.init(model); - -Loopback.rawSql(model); -getAverageInvoiced(model); +const app = require(`${servicesDir}/client/server/server`); describe('client getAverageInvoiced()', () => { it('should call the getAverageInvoiced method', done => { - model.getAverageInvoiced(101) + app.models.Client.getAverageInvoiced(101) .then(response => { expect(response.invoiced).toEqual(1500); done(); diff --git a/services/loopback/common/methods/client/specs/getMana.spec.js b/services/loopback/common/methods/client/specs/getMana.spec.js index 31e7ce231..f4e317bf3 100644 --- a/services/loopback/common/methods/client/specs/getMana.spec.js +++ b/services/loopback/common/methods/client/specs/getMana.spec.js @@ -1,16 +1,8 @@ -const getMana = require('../getMana'); -const model = { - remoteMethod: () => {} -}; -let Loopback = require('../../../test-helpers/loopback'); -Loopback.init(model); - -Loopback.rawSql(model); -getMana(model); +const app = require(`${servicesDir}/client/server/server`); describe('client getMana()', () => { it('should call the getMana method', done => { - model.getMana(101) + app.models.Client.getMana(101) .then(response => { expect(response.mana).toEqual(30.02); done(); diff --git a/services/loopback/common/methods/ticket/specs/get-taxes.spec.js b/services/loopback/common/methods/ticket/specs/get-taxes.spec.js index 179b8907c..087c8ce10 100644 --- a/services/loopback/common/methods/ticket/specs/get-taxes.spec.js +++ b/services/loopback/common/methods/ticket/specs/get-taxes.spec.js @@ -1,16 +1,8 @@ -const getTaxes = require('../get-taxes'); -const model = { - remoteMethod: () => {} -}; -let Loopback = require('../../../test-helpers/loopback'); -Loopback.init(model); - -Loopback.rawSql(model); -getTaxes(model); +const app = require(`${servicesDir}/ticket/server/server`); describe('ticket getTaxes()', () => { it('should call the getTaxes method', done => { - model.getTaxes(1) + app.models.Ticket.getTaxes(1) .then(response => { expect(response[0].tax).toEqual(1.05); done(); diff --git a/services/loopback/common/methods/ticket/specs/get-total.spec.js b/services/loopback/common/methods/ticket/specs/get-total.spec.js index a42234194..0a9d74e84 100644 --- a/services/loopback/common/methods/ticket/specs/get-total.spec.js +++ b/services/loopback/common/methods/ticket/specs/get-total.spec.js @@ -1,16 +1,8 @@ -const getTotal = require('../get-total'); -const model = { - remoteMethod: () => {} -}; -let Loopback = require('../../../test-helpers/loopback'); -Loopback.init(model); - -Loopback.rawSql(model); -getTotal(model); +const app = require(`${servicesDir}/ticket/server/server`); describe('ticket getTotal()', () => { it('should call the getTotal method and return the response', done => { - model.getTotal(1) + app.models.Ticket.getTotal(1) .then(response => { expect(response).toEqual(11.55); done(); @@ -18,7 +10,7 @@ describe('ticket getTotal()', () => { }); it(`should call the getTotal method and return zero if doesn't have lines`, done => { - model.getTotal(13) + app.models.Ticket.getTotal(13) .then(response => { expect(response).toEqual(0); done(); diff --git a/services/loopback/common/methods/ticket/specs/get-volume.spec.js b/services/loopback/common/methods/ticket/specs/get-volume.spec.js index 99e1d4a63..dbe97684d 100644 --- a/services/loopback/common/methods/ticket/specs/get-volume.spec.js +++ b/services/loopback/common/methods/ticket/specs/get-volume.spec.js @@ -1,17 +1,9 @@ -const getVolume = require('../get-volume'); -const model = { - remoteMethod: () => {} -}; -let Loopback = require('../../../test-helpers/loopback'); -Loopback.init(model); - -Loopback.rawSql(model); -getVolume(model); +const app = require(`${servicesDir}/ticket/server/server`); describe('ticket getVolume()', () => { it('should call the getVolume method', done => { let ticketFk = 1; - model.getVolume(ticketFk) + app.models.Ticket.getVolume(ticketFk) .then(response => { expect(response[0][0].m3_total).toEqual(0.008); done(); diff --git a/services/loopback/common/methods/ticket/specs/summary.spec.js b/services/loopback/common/methods/ticket/specs/summary.spec.js index 5b1c3f398..5072c7c37 100644 --- a/services/loopback/common/methods/ticket/specs/summary.spec.js +++ b/services/loopback/common/methods/ticket/specs/summary.spec.js @@ -1,22 +1,12 @@ -/* let Jasmine = require('jasmine'); -const {getTicketData} = require('../summary'); +// const app = require(`${servicesDir}/ticket/server/server`); -const summary = require('../summary'); -const model = { - remoteMethod: () => {} -}; +// fdescribe('ticket summary()', () => { +// describe('getTicketData()', () => { +// it('should sum all sales price', done => { +// let result = getTicketData(model, 1); -summary(model); - -fdescribe('ticket summary()', () => { - describe('getTicketData()', () => { - it('should sum all sales price', done => { - let result = getTicketData(model, 1); - - expect(result).toEqual("pepinillos"); - done(); - }); - }); -}); - - */ \ No newline at end of file +// expect(result).toEqual("pepinillos"); +// done(); +// }); +// }); +// }); diff --git a/services/loopback/common/test-helpers/loopback.js b/services/loopback/common/test-helpers/loopback.js deleted file mode 100644 index c6a11cb6d..000000000 --- a/services/loopback/common/test-helpers/loopback.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = { - importLoopbackModules: function() { - this.rawSqlModule = require('../methods/vnModel/rawSql.js'); - this.findOneModule = require('../methods/vnModel/rawSql.js'); - }, - - /** - * Initializes DataSource once - * @param {Object} Self - Model - */ - init: function(Self) { - if (!this.dataSource) - this.connect(); - - Self.dataSource = this.dataSource; - - this.importLoopbackModules(); - }, - - /** - * Instantiate Loopback DataSource - */ - connect: function() { - let DataSource = require('loopback-datasource-juggler').DataSource; - let dataSourceConfig = { - connector: 'mysql', - host: 'localhost', - user: 'root', - password: 'root', - database: 'salix' - }; - - this.dataSource = new DataSource(dataSourceConfig); - }, - - rawSql: function(Self) { - this.rawSqlModule(Self); - } -}; diff --git a/services_tests.js b/services_tests.js index cbd7e7f81..3ab2ed8ec 100644 --- a/services_tests.js +++ b/services_tests.js @@ -9,6 +9,7 @@ var verbose = false; if (process.argv[2] === '--v') { verbose = true; } +servicesDir = `${__dirname}/services`; var Jasmine = require('jasmine'); var jasmine = new Jasmine();