#522 updateBillingData.js Backend unit tests

This commit is contained in:
Carlos Jimenez 2018-08-13 16:54:34 +02:00
parent 24ad4a83a1
commit 27bc339721
3 changed files with 70 additions and 2 deletions

View File

@ -0,0 +1,59 @@
const app = require(`${servicesDir}/client/server/server`);
describe('Client updateBillingData', () => {
afterAll(async() => {
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
let validparams = {iban: null};
let idWithDataChecked = 101;
await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked);
});
it('should return an error if the user is not administrative and the isTaxDataChecked value is true', async() => {
let error;
let ctxOfNoAdmin = {req: {accessToken: {userId: 1}}};
let params = [];
let idWithDataChecked = 101;
await app.models.Client.updateBillingData(ctxOfNoAdmin, params, idWithDataChecked)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You don't have enough privileges to do that`);
});
it('should return an error if the user is administrative and the isTaxDataChecked value is true BUT the params aint valid', async() => {
let error;
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
let invalidparams = {invalid: 'param for update'};
let idWithDataChecked = 101;
await app.models.Client.updateBillingData(ctxOfAdmin, invalidparams, idWithDataChecked)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You don't have enough privileges to do that`);
});
it('should update the client billing data and return the count if changes made', async() => {
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
let validparams = {iban: 12345};
let idWithDataChecked = 101;
let client = await app.models.Client.findById(idWithDataChecked);
expect(client.iban).toBeFalsy();
let result = await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked);
expect(result).toEqual({count: 1});
let updatedClient = await app.models.Client.findById(idWithDataChecked);
expect(updatedClient.iban).toEqual('12345');
});
});

View File

@ -39,7 +39,7 @@ describe('Client updateFiscalData', () => {
expect(error.toString()).toContain(`You don't have enough privileges to do that`);
});
it('should update the client discal data and return the count if changes made', async() => {
it('should update the client fiscal data and return the count if changes made', async() => {
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
let validparams = {postcode: 12345};
let idWithDataChecked = 101;

View File

@ -29,7 +29,16 @@ module.exports = Self => {
});
Self.updateBasicData = async(params, id) => {
let validUpdateParams = ['id', 'contact', 'name', 'email', 'phone', 'mobile', 'salesPersonFk', 'contactChannelFk'];
let validUpdateParams = [
'contact',
'name',
'email',
'phone',
'mobile',
'salesPersonFk',
'contactChannelFk'
];
for (const key in params) {
if (validUpdateParams.indexOf(key) === -1)
throw new UserError(`You don't have enough privileges to do that`);