2018-08-13 12:10:03 +00:00
|
|
|
const app = require(`${servicesDir}/client/server/server`);
|
|
|
|
|
|
|
|
describe('Client updateFiscalData', () => {
|
|
|
|
afterAll(async() => {
|
|
|
|
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
|
|
|
|
let validparams = {postcode: 46460};
|
|
|
|
let idWithDataChecked = 101;
|
|
|
|
|
|
|
|
await app.models.Client.updateFiscalData(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.updateFiscalData(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.updateFiscalData(ctxOfAdmin, invalidparams, idWithDataChecked)
|
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error.toString()).toContain(`You don't have enough privileges to do that`);
|
|
|
|
});
|
|
|
|
|
2018-08-13 14:54:34 +00:00
|
|
|
it('should update the client fiscal data and return the count if changes made', async() => {
|
2018-08-13 12:10:03 +00:00
|
|
|
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
|
|
|
|
let validparams = {postcode: 12345};
|
|
|
|
let idWithDataChecked = 101;
|
|
|
|
|
2018-08-13 12:52:05 +00:00
|
|
|
let client = await app.models.Client.findById(idWithDataChecked);
|
|
|
|
|
|
|
|
expect(client.postcode).toEqual('46460');
|
|
|
|
|
2018-08-13 12:10:03 +00:00
|
|
|
let result = await app.models.Client.updateFiscalData(ctxOfAdmin, validparams, idWithDataChecked);
|
|
|
|
|
2018-10-03 10:53:30 +00:00
|
|
|
expect(result.postcode).toEqual('12345');
|
2018-08-13 12:10:03 +00:00
|
|
|
});
|
|
|
|
});
|