#192 refactor on back end unit test helpers to ready loopback methods extensions CR Joan

This commit is contained in:
Carlos Jimenez 2018-04-18 14:37:17 +02:00
parent 228239b027
commit f3eecf53b7
10 changed files with 77 additions and 27 deletions

View File

@ -1,10 +1,11 @@
const getAverageInvoiced = require('../getAverageInvoiced'); const getAverageInvoiced = require('../getAverageInvoiced');
const {rawSql} = require('../../../test-helpers/rawSql');
const model = { const model = {
remoteMethod: () => {} remoteMethod: () => {}
}; };
let Loopback = require('../../../test-helpers/loopback');
Loopback.init(model);
rawSql(model); Loopback.rawSql(model);
getAverageInvoiced(model); getAverageInvoiced(model);
describe('client getAverageInvoiced()', () => { describe('client getAverageInvoiced()', () => {

View File

@ -1,10 +1,11 @@
const getMana = require('../getMana'); const getMana = require('../getMana');
const {rawSql} = require('../../../test-helpers/rawSql');
const model = { const model = {
remoteMethod: () => {} remoteMethod: () => {}
}; };
let Loopback = require('../../../test-helpers/loopback');
Loopback.init(model);
rawSql(model); Loopback.rawSql(model);
getMana(model); getMana(model);
describe('client getMana()', () => { describe('client getMana()', () => {

View File

@ -1,4 +1,4 @@
var UserError = require('../../helpers').UserError; let UserError = require('../../helpers').UserError;
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('clone', { Self.remoteMethod('clone', {

View File

@ -0,0 +1,20 @@
const clone = require('../clone');
const model = {
remoteMethod: () => {}
};
let Loopback = require('../../../test-helpers/loopback');
Loopback.init(model);
Loopback.rawSql(model);
clone(model);
describe('item clone()', () => {
it('should', () => {
let itemFk = 1;
model.clone(itemFk)
.then(response => {
expect(response).toEqual('whatever');
done();
});
});
});

View File

@ -25,7 +25,7 @@ module.exports = Self => {
} }
}); });
Self.updateTaxes = async (id, taxes) => { Self.updateTaxes = async(id, taxes) => {
let promises = []; let promises = [];
for (let tax of taxes) { for (let tax of taxes) {
if (!tax.taxClassFk) if (!tax.taxClassFk)

View File

@ -1,10 +1,11 @@
const getTaxes = require('../get-taxes'); const getTaxes = require('../get-taxes');
const {rawSql} = require('../../../test-helpers/rawSql');
const model = { const model = {
remoteMethod: () => {} remoteMethod: () => {}
}; };
let Loopback = require('../../../test-helpers/loopback');
Loopback.init(model);
rawSql(model); Loopback.rawSql(model);
getTaxes(model); getTaxes(model);
describe('ticket getTaxes()', () => { describe('ticket getTaxes()', () => {

View File

@ -1,10 +1,11 @@
const getTotal = require('../get-total'); const getTotal = require('../get-total');
const {rawSql} = require('../../../test-helpers/rawSql');
const model = { const model = {
remoteMethod: () => {} remoteMethod: () => {}
}; };
let Loopback = require('../../../test-helpers/loopback');
Loopback.init(model);
rawSql(model); Loopback.rawSql(model);
getTotal(model); getTotal(model);
describe('ticket getTotal()', () => { describe('ticket getTotal()', () => {

View File

@ -1,10 +1,11 @@
const getVolume = require('../get-volume'); const getVolume = require('../get-volume');
const {rawSql} = require('../../../test-helpers/rawSql');
const model = { const model = {
remoteMethod: () => {} remoteMethod: () => {}
}; };
let Loopback = require('../../../test-helpers/loopback');
Loopback.init(model);
rawSql(model); Loopback.rawSql(model);
getVolume(model); getVolume(model);
describe('ticket getVolume()', () => { describe('ticket getVolume()', () => {

View File

@ -0,0 +1,39 @@
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

@ -1,14 +0,0 @@
module.exports.rawSql = Self => {
const DataSource = require('loopback-datasource-juggler').DataSource;
const rawSql = require('../methods/vnModel/rawSql.js');
const dataSourceConfig = {
connector: 'mysql',
host: 'localhost',
user: 'root',
password: 'root',
database: 'salix'
};
const dataSource = new DataSource(dataSourceConfig);
Self.dataSource = dataSource;
rawSql(Self);
};