2018-08-13 11:11:37 +00:00
|
|
|
const app = require(`${servicesDir}/client/server/server`);
|
2018-01-23 14:59:21 +00:00
|
|
|
|
|
|
|
describe('Client addressesPropagateRe', () => {
|
2018-10-03 10:53:30 +00:00
|
|
|
let client;
|
2018-09-21 13:01:51 +00:00
|
|
|
beforeEach(async() => {
|
2018-10-03 10:53:30 +00:00
|
|
|
client = await app.models.Client.findById(101);
|
2018-09-21 13:01:51 +00:00
|
|
|
await app.models.Address.update({clientFk: 101}, {isEqualizated: false});
|
2018-10-03 10:53:30 +00:00
|
|
|
await client.updateAttributes({hasToInvoiceByAddress: true});
|
2018-01-23 14:59:21 +00:00
|
|
|
});
|
|
|
|
|
2018-09-21 13:01:51 +00:00
|
|
|
afterAll(async() => {
|
|
|
|
await app.models.Address.update({clientFk: 101}, {isEqualizated: false});
|
2018-10-03 10:53:30 +00:00
|
|
|
await client.updateAttributes({hasToInvoiceByAddress: true});
|
2018-01-24 07:09:39 +00:00
|
|
|
});
|
|
|
|
|
2018-09-21 13:01:51 +00:00
|
|
|
it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => {
|
2018-03-08 11:23:51 +00:00
|
|
|
let id = 101;
|
2018-01-23 14:59:21 +00:00
|
|
|
let data = {
|
|
|
|
isEqualizated: true
|
|
|
|
};
|
|
|
|
|
2018-07-03 09:13:33 +00:00
|
|
|
let resultAddress = await app.models.Address.find({where: {clientFk: id}});
|
|
|
|
let resultClient = await app.models.Client.find({where: {id: id}});
|
2018-01-23 14:59:21 +00:00
|
|
|
|
2018-07-03 09:13:33 +00:00
|
|
|
expect(resultAddress[0].isEqualizated).toBeFalsy();
|
|
|
|
expect(resultAddress[1].isEqualizated).toBeFalsy();
|
|
|
|
expect(resultClient[0].hasToInvoiceByAddress).toBeTruthy();
|
|
|
|
|
|
|
|
await app.models.Client.addressesPropagateRe(id, data);
|
|
|
|
|
|
|
|
resultAddress = await app.models.Address.find({where: {clientFk: id}});
|
|
|
|
resultClient = await app.models.Client.find({where: {id: id}});
|
|
|
|
|
|
|
|
expect(resultAddress[0].isEqualizated).toBeTruthy();
|
|
|
|
expect(resultAddress[1].isEqualizated).toBeTruthy();
|
|
|
|
expect(resultClient[0].hasToInvoiceByAddress).toBeFalsy();
|
2018-01-23 14:59:21 +00:00
|
|
|
});
|
|
|
|
});
|