2018-08-13 14:54:34 +00:00
|
|
|
const app = require(`${servicesDir}/client/server/server`);
|
|
|
|
|
|
|
|
describe('Client updateBillingData', () => {
|
|
|
|
afterAll(async() => {
|
|
|
|
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
|
2018-09-27 08:03:11 +00:00
|
|
|
let validparams = {
|
|
|
|
phone: 1111111111,
|
|
|
|
payMethodFk: 5,
|
|
|
|
dueDay: 0,
|
|
|
|
iban: null,
|
|
|
|
hasLcr: 0,
|
|
|
|
hasCoreVnl: 1,
|
|
|
|
hasSepaVnl: 1
|
|
|
|
};
|
2018-08-13 14:54:34 +00:00
|
|
|
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}}};
|
2018-09-27 08:03:11 +00:00
|
|
|
let params = {iban: null};
|
2018-08-13 14:54:34 +00:00
|
|
|
let idWithDataChecked = 101;
|
|
|
|
|
|
|
|
await app.models.Client.updateBillingData(ctxOfNoAdmin, params, idWithDataChecked)
|
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
});
|
|
|
|
|
2018-09-27 08:03:11 +00:00
|
|
|
expect(error.message).toEqual(`You don't have enough privileges to do that`);
|
2018-08-13 14:54:34 +00:00
|
|
|
});
|
|
|
|
|
2018-09-27 08:03:11 +00:00
|
|
|
it('should update the billing data and check if the changes were made', async() => {
|
2018-08-13 14:54:34 +00:00
|
|
|
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
|
2018-09-27 08:03:11 +00:00
|
|
|
let params = {
|
|
|
|
phone: 2222222222,
|
|
|
|
payMethodFk: 4,
|
|
|
|
dueDay: 30,
|
|
|
|
iban: 'ES91 2100 0418 4502 0005 1332',
|
|
|
|
hasLcr: 1,
|
|
|
|
hasCoreVnl: 0,
|
|
|
|
hasSepaVnl: 0
|
|
|
|
};
|
2018-08-13 14:54:34 +00:00
|
|
|
let idWithDataChecked = 101;
|
|
|
|
|
2018-09-27 08:03:11 +00:00
|
|
|
await app.models.Client.updateBillingData(ctxOfAdmin, params, idWithDataChecked);
|
|
|
|
let client = await app.models.Client.findById(idWithDataChecked);
|
2018-08-13 14:54:34 +00:00
|
|
|
|
2018-09-27 08:03:11 +00:00
|
|
|
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();
|
2018-08-13 14:54:34 +00:00
|
|
|
});
|
|
|
|
|
2018-09-18 12:36:41 +00:00
|
|
|
it('should return an error if the given IBAN is an invalid one', async() => {
|
2018-08-13 14:54:34 +00:00
|
|
|
let ctxOfAdmin = {req: {accessToken: {userId: 5}}};
|
2018-09-27 08:03:11 +00:00
|
|
|
let validparams = {
|
|
|
|
payMethodFk: 5,
|
|
|
|
iban: null};
|
2018-08-13 14:54:34 +00:00
|
|
|
let idWithDataChecked = 101;
|
|
|
|
|
2018-09-27 08:03:11 +00:00
|
|
|
await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked);
|
|
|
|
|
|
|
|
validparams = {iban: 12345};
|
|
|
|
|
2018-09-18 12:36:41 +00:00
|
|
|
try {
|
|
|
|
await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked);
|
|
|
|
} catch (error) {
|
|
|
|
expect(error.toString()).toContain('The IBAN does not have the correct format');
|
|
|
|
}
|
|
|
|
|
2018-08-13 14:54:34 +00:00
|
|
|
let client = await app.models.Client.findById(idWithDataChecked);
|
|
|
|
|
|
|
|
expect(client.iban).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|