2018-08-13 11:11:37 +00:00
|
|
|
const app = require(`${servicesDir}/client/server/server`);
|
|
|
|
const restoreFixtures = require(`${servicesDir}/db/testing_fixtures`);
|
2018-01-23 14:59:21 +00:00
|
|
|
|
|
|
|
describe('Client addressesPropagateRe', () => {
|
2018-03-08 11:23:51 +00:00
|
|
|
let sqlStatements = {deletes: ``, inserts: ``, updates:
|
2018-07-03 09:13:33 +00:00
|
|
|
`UPDATE vn.address SET isEqualizated = FALSE WHERE clientFk = 101;
|
|
|
|
UPDATE vn.client SET hasToInvoiceByAddress = TRUE WHERE id = 101;`
|
2018-03-08 11:23:51 +00:00
|
|
|
};
|
|
|
|
beforeEach(() => {
|
|
|
|
restoreFixtures(sqlStatements);
|
2018-01-23 14:59:21 +00:00
|
|
|
});
|
|
|
|
|
2018-03-08 11:23:51 +00:00
|
|
|
afterAll(() => {
|
|
|
|
restoreFixtures(sqlStatements);
|
2018-01-24 07:09:39 +00:00
|
|
|
});
|
|
|
|
|
2018-07-03 09:13:33 +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
|
|
|
});
|
|
|
|
});
|