Backend tests refactor, bug fixes

This commit is contained in:
Juan Ferrer Toribio 2018-01-31 12:17:17 +01:00
parent 109f04c517
commit 3d6f9fbbca
15 changed files with 27 additions and 276 deletions

View File

@ -7,7 +7,7 @@
</vn-horizontal> </vn-horizontal>
<vn-horizontal ng-repeat="address in index.model.items track by address.id" class="pad-medium-top" style="align-items: center;"> <vn-horizontal ng-repeat="address in index.model.items track by address.id" class="pad-medium-top" style="align-items: center;">
<vn-one border-radius class="pad-small border-solid" <vn-one border-radius class="pad-small border-solid"
ng-class="{'bg-dark-item': address.isDefaultAddress,'bg-opacity-item': !address.isEnabled && !address.isDefaultAddress}"> ng-class="{'bg-dark-item': address.isDefaultAddress,'bg-opacity-item': !address.isActive && !address.isDefaultAddress}">
<vn-horizontal style="align-items: center;"> <vn-horizontal style="align-items: center;">
<vn-none pad-medium-h style="color:#FFA410;"> <vn-none pad-medium-h style="color:#FFA410;">
<i class="material-icons" ng-if="address.isDefaultAddress">star</i> <i class="material-icons" ng-if="address.isDefaultAddress">star</i>

View File

@ -38,7 +38,9 @@ gulp.task('client', ['clean'], () => {
}); });
gulp.task('services', ['nginx'], () => { gulp.task('services', ['nginx'], () => {
process.env.NODE_ENV = gutil.env.env || 'development'; if (gutil.env.env && !process.env.NODE_ENV)
process.env.NODE_ENV = gutil.env.env;
const servicesPath = './services/'; const servicesPath = './services/';
const services = fs.readdirSync(servicesPath); const services = fs.readdirSync(servicesPath);
services.splice(services.indexOf('loopback'), 1); services.splice(services.indexOf('loopback'), 1);

View File

@ -1,72 +0,0 @@
module.exports = function(Client) {
Client.remoteMethod('addressesList', {
description: 'List items using a filter',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'string',
required: true,
description: 'Model id',
http: {source: 'path'}
},
{
arg: 'filter',
type: 'object',
required: true,
description: 'Filter defining where',
http: function(ctx) {
return ctx.req.query;
}
}
],
returns: {
arg: 'data',
type: ['Address'],
root: true
},
http: {
path: `/:id/addressesList`,
verb: 'get'
}
});
Client.addressesList = function(id, params, callback) {
let filter = {
where: {
clientFk: id
},
skip: (params.page - 1) * params.size,
limit: params.size,
order: ['isDefaultAddress DESC', 'isEnabled DESC'],
include: {observations: 'observationType'}
};
let total = null;
let items = null;
function response(type, value) {
if (type === 'total') {
total = value;
} else {
items = value;
}
if (total !== null && items !== null) {
callback(null, {total: total, items: items});
}
}
Client.app.models.Address.find(filter, function(err, results) {
if (err)
return callback(err, null);
response('find', results);
});
Client.app.models.Address.count(filter.where, function(err, result) {
if (err)
return callback(err, null);
response('total', result);
});
};
};

View File

@ -1,43 +0,0 @@
module.exports = function(Client) {
Client.remoteMethod('addressesPropagateRe', {
description: 'Change property isEqualizated in all client addresses',
accessType: 'WRITE',
accepts: [
{
arg: 'id',
type: 'string',
required: true,
description: 'Client id',
http: {source: 'path'}
},
{
arg: 'data',
type: 'Object',
required: true,
description: 'data with new value',
http: {source: 'body'}
}
],
returns: {
arg: 'data',
type: 'boolean',
root: true
},
http: {
path: `/:id/addressesPropagateRe`,
verb: 'patch'
}
});
Client.addressesPropagateRe = (id, data, callback) => {
if (data.hasOwnProperty('isEqualizated')) {
Client.app.models.Address.updateAll({clientFk: id}, data, (err, info) => {
if (err)
return callback(err, null);
callback(null, true);
});
} else {
callback(null, false);
}
};
};

View File

@ -1,46 +0,0 @@
module.exports = function(Client) {
Client.remoteMethod('card', {
description: 'Get client for card call',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'Model id',
http: {source: 'path'}
},
returns: {
arg: 'data',
type: 'Client',
root: true
},
http: {
verb: 'get',
path: '/:id/card'
}
});
Client.card = function(id, callback) {
let filter = {
where: {
id: id
},
include: require('./card.json')
};
Client.find(filter, function(error, instances) {
if (error) throw error;
callback(null, formatCard(instances[0]));
});
};
function formatCard(card) {
let cardFormated = JSON.parse(JSON.stringify(card));
if (cardFormated.salesPersonFk)
cardFormated.salesPerson = {
id: card.salesPerson().id,
name: `${card.salesPerson().name} ${card.salesPerson().surname}`
};
return cardFormated;
}
};

View File

@ -1,58 +0,0 @@
let app = require('../../../server/server');
let md5 = require('md5');
module.exports = function(Client) {
Client.remoteMethod('createUserProfile', {
description: 'Creates both client and its web account',
accepts: {
arg: 'data',
type: 'object',
http: {source: 'body'}
},
returns: {
root: true,
type: 'boolean'
},
http: {
verb: 'post',
path: '/createUserProfile'
}
});
Client.createUserProfile = (data, callback) => {
let firstEmail = data.email ? data.email.split(',')[0] : null;
let user = {
name: data.userName,
email: firstEmail,
password: md5(parseInt(Math.random() * 100000000000000))
};
app.models.Account.beginTransaction({}, (error, transaction) => {
app.models.Account.create(user, {transaction}, (error, account) => {
if (error) {
transaction.rollback();
return callback(error);
}
let client = {
name: data.name,
fi: data.fi,
socialName: data.socialName,
id: account.id,
email: data.email,
salesPersonFk: data.salesPersonFk
};
Client.create(client, {transaction}, (error, newClient) => {
if (error) {
transaction.rollback();
return callback(error);
}
transaction.commit();
callback(null, newClient);
});
});
});
};
};

View File

@ -1,33 +0,0 @@
import app from '../../../../server/server';
import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
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);
});
});

View File

@ -1,7 +1,8 @@
{ {
"PHONE_INVALID_FORMAT": "The phone format is invalid", "PHONE_INVALID_FORMAT": "The phone format is invalid",
"You are not allowed to change the credit": "You are not allowed to change the credit", "You are not allowed to change the credit": "You are not allowed to change the credit",
"Unable to mark the equivalence surcharge": "Unable to mark the equivalence surcharge", "Unable to mark the equivalence surcharge": "Unable to mark the equivalence surcharge",
"The default consignee can not be unchecked": "The default consignee can not be unchecked", "The default consignee can not be unchecked": "The default consignee can not be unchecked",
"Unable to default a disabled consignee": "Unable to default a disabled consignee" "Unable to default a disabled consignee": "Unable to default a disabled consignee",
"El método de pago seleccionado requiere que se especifique el IBAN": "El método de pago seleccionado requiere que se especifique el IBAN"
} }

View File

@ -97,7 +97,7 @@ describe('Client Create', () => {
socialName: client.socialName socialName: client.socialName
}; };
app.models.Client.createUserProfile(formerAccountData, (err, client) => { app.models.Client.createWithUser(formerAccountData, (err, client) => {
expect(err.details.codes.name[0]).toEqual('uniqueness'); expect(err.details.codes.name[0]).toEqual('uniqueness');
done(); done();
}); });
@ -107,7 +107,7 @@ describe('Client Create', () => {
}); });
it('should create a new account', done => { it('should create a new account', done => {
app.models.Client.createUserProfile(newAccountData, (error, client) => { app.models.Client.createWithUser(newAccountData, (error, client) => {
if (error) return catchErrors(done)(error); if (error) return catchErrors(done)(error);
app.models.Account.findOne({where: {name: newAccountData.userName}}) app.models.Account.findOne({where: {name: newAccountData.userName}})
.then(account => { .then(account => {

View File

@ -1,8 +1,8 @@
import app from '../../../../server/server'; import app from '../../../../server/server';
import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
describe('Client getRoleCustomer', () => { describe('Client hasCustomerRole', () => {
it('should call the getRoleCustomer() method with a customer id', done => { it('should call the hasCustomerRole() method with a customer id', done => {
let id = 1; let id = 1;
let params = {}; let params = {};
@ -13,10 +13,10 @@ describe('Client getRoleCustomer', () => {
done(); done();
}; };
app.models.Client.getRoleCustomer(id, params, callback); app.models.Client.hasCustomerRole(id, params, callback);
}); });
it('should call the getRoleCustomer() method with a non customer id', done => { it('should call the hasCustomerRole() method with a non customer id', done => {
let id = 8; let id = 8;
let params = {}; let params = {};
@ -27,10 +27,10 @@ describe('Client getRoleCustomer', () => {
done(); done();
}; };
app.models.Client.getRoleCustomer(id, params, callback); app.models.Client.hasCustomerRole(id, params, callback);
}); });
it('should call the getRoleCustomer() method with an unreal id', done => { it('should call the hasCustomerRole() method with an unreal id', done => {
let id = 999; let id = 999;
let params = {}; let params = {};
@ -41,10 +41,10 @@ describe('Client getRoleCustomer', () => {
done(); done();
}; };
app.models.Client.getRoleCustomer(id, params, callback); app.models.Client.hasCustomerRole(id, params, callback);
}); });
it('should call the getRoleCustomer() method with an invalid id', done => { it('should call the hasCustomerRole() method with an invalid id', done => {
let id = 'WRONG!'; let id = 'WRONG!';
let params = {}; let params = {};
@ -55,6 +55,6 @@ describe('Client getRoleCustomer', () => {
done(); done();
}; };
app.models.Client.getRoleCustomer(id, params, callback); app.models.Client.hasCustomerRole(id, params, callback);
}); });
}); });

View File

@ -2,7 +2,7 @@ import app from '../../../../server/server';
import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
describe('Client addresses', () => { describe('Client addresses', () => {
it('should call the addressesList method and receive total results and items', done => { it('should call the listAddresses method and receive total results and items', done => {
let id = 1; let id = 1;
let params = { let params = {
page: 1, page: 1,
@ -15,6 +15,6 @@ describe('Client addresses', () => {
expect(Object.keys(result)).toEqual(['total', 'items']); expect(Object.keys(result)).toEqual(['total', 'items']);
done(); done();
}; };
app.models.Client.addressesList(id, params, callback); app.models.Client.listAddresses(id, params, callback);
}); });
}); });

View File

@ -1,8 +1,8 @@
import app from '../../../../server/server'; import app from '../../../../server/server';
import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
describe('Client employeeList', () => { describe('Client listWorkers', () => {
it('should call the employeeList()', done => { it('should call the listWorkers()', done => {
let callback = (error, result) => { let callback = (error, result) => {
if (error) return catchErrors(done)(error); if (error) return catchErrors(done)(error);
let amountOfEmployees = Object.keys(result).length; let amountOfEmployees = Object.keys(result).length;
@ -10,6 +10,6 @@ describe('Client employeeList', () => {
expect(amountOfEmployees).toEqual(6); expect(amountOfEmployees).toEqual(6);
done(); done();
}; };
app.models.Client.employeeList(callback); app.models.Client.listWorkers(callback);
}); });
}); });

View File

@ -8,7 +8,7 @@
"host": "localhost", "host": "localhost",
"port": 3306, "port": 3306,
"database": "vn", "database": "vn",
"user": "reports", "user": "root",
"password": "" "password": ""
}, },
"pdf": { "pdf": {