salix/services/loopback/common/methods/client/specs/addressesPropagateRe.spec.js

39 lines
1.5 KiB
JavaScript

const app = require(`${servicesDir}/client/server/server`);
describe('Client addressesPropagateRe', () => {
let client;
beforeEach(async() => {
client = await app.models.Client.findById(101);
await app.models.Address.update({clientFk: 101}, {isEqualizated: false});
await client.updateAttributes({hasToInvoiceByAddress: true});
});
afterAll(async() => {
await app.models.Address.update({clientFk: 101}, {isEqualizated: false});
await client.updateAttributes({hasToInvoiceByAddress: true});
});
it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => {
let id = 101;
let data = {
isEqualizated: true
};
let resultAddress = await app.models.Address.find({where: {clientFk: id}});
let resultClient = await app.models.Client.find({where: {id: id}});
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();
});
});