salix/services/loopback/common/methods/client/specs/updateBillingData.spec.js

60 lines
2.1 KiB
JavaScript
Raw Normal View History

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