refactor test updateBillingData

This commit is contained in:
Bernat 2018-09-27 10:03:11 +02:00
parent 504096d702
commit 46a62854d6
2 changed files with 38 additions and 14 deletions

View File

@ -22,7 +22,7 @@ describe('Client updateBasicData', () => {
expect(error.toString()).toContain(`You don't have enough privileges to do that`); 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 id = 101; let id = 101;
let client = await app.models.Client.findById(id); let client = await app.models.Client.findById(id);

View File

@ -3,7 +3,15 @@ const app = require(`${servicesDir}/client/server/server`);
describe('Client updateBillingData', () => { describe('Client updateBillingData', () => {
afterAll(async() => { afterAll(async() => {
let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
let validparams = {iban: null}; let validparams = {
phone: 1111111111,
payMethodFk: 5,
dueDay: 0,
iban: null,
hasLcr: 0,
hasCoreVnl: 1,
hasSepaVnl: 1
};
let idWithDataChecked = 101; let idWithDataChecked = 101;
await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked); await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked);
@ -13,7 +21,7 @@ describe('Client updateBillingData', () => {
let error; let error;
let ctxOfNoAdmin = {req: {accessToken: {userId: 1}}}; let ctxOfNoAdmin = {req: {accessToken: {userId: 1}}};
let params = []; let params = {iban: null};
let idWithDataChecked = 101; let idWithDataChecked = 101;
await app.models.Client.updateBillingData(ctxOfNoAdmin, params, idWithDataChecked) await app.models.Client.updateBillingData(ctxOfNoAdmin, params, idWithDataChecked)
@ -21,29 +29,45 @@ describe('Client updateBillingData', () => {
error = e; error = e;
}); });
expect(error.toString()).toContain(`You don't have enough privileges to do that`); expect(error.message).toEqual(`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() => { it('should update the billing data and check if the changes were made', async() => {
let error;
let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
let invalidparams = {invalid: 'param for update'}; let params = {
phone: 2222222222,
payMethodFk: 4,
dueDay: 30,
iban: 'ES91 2100 0418 4502 0005 1332',
hasLcr: 1,
hasCoreVnl: 0,
hasSepaVnl: 0
};
let idWithDataChecked = 101; let idWithDataChecked = 101;
await app.models.Client.updateBillingData(ctxOfAdmin, invalidparams, idWithDataChecked) await app.models.Client.updateBillingData(ctxOfAdmin, params, idWithDataChecked);
.catch(e => { let client = await app.models.Client.findById(idWithDataChecked);
error = e;
});
expect(error.toString()).toContain(`You don't have enough privileges to do that`); expect(client.phone).not.toEqual(params.phone);
expect(client.payMethodFk).toEqual(params.payMethodFk);
expect(client.dueDay).toEqual(params.dueDay);
expect(client.iban).toEqual(params.iban);
expect(client.hasLcr).toBeTruthy();
expect(client.hasCoreVnl).toBeFalsy();
expect(client.hasSepaVnl).toBeFalsy();
}); });
it('should return an error if the given IBAN is an invalid one', async() => { it('should return an error if the given IBAN is an invalid one', async() => {
let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
let validparams = {iban: 12345}; let validparams = {
payMethodFk: 5,
iban: null};
let idWithDataChecked = 101; let idWithDataChecked = 101;
await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked);
validparams = {iban: 12345};
try { try {
await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked); await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked);
} catch (error) { } catch (error) {