fixes and refactor in several spec files

This commit is contained in:
Carlos Jimenez 2018-04-19 11:20:41 +02:00
parent ded1ab5d93
commit 6f162c774e
8 changed files with 22 additions and 110 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();
});
});
});
*/
// expect(result).toEqual("pepinillos");
// done();
// });
// });
// });

View File

@ -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);
}
};

View File

@ -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();