2018-02-02 15:24:22 +00:00
|
|
|
const app = require('../../../../../client/server/server');
|
2018-01-31 11:02:35 +00:00
|
|
|
const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors;
|
|
|
|
const restoreFixtures = require('../../../../../../services/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:
|
|
|
|
`UPDATE vn.address SET isEqualizated = 0 WHERE clientFk = 101;`
|
|
|
|
};
|
|
|
|
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-01-23 14:59:21 +00:00
|
|
|
it('should propagate the isEqualizated on both addresses of Mr Wayne', done => {
|
2018-03-08 11:23:51 +00:00
|
|
|
let id = 101;
|
2018-01-23 14:59:21 +00:00
|
|
|
let data = {
|
|
|
|
isEqualizated: true
|
|
|
|
};
|
|
|
|
|
|
|
|
let callback = (error, result) => {
|
|
|
|
if (error) return catchErrors(done)(error);
|
|
|
|
|
|
|
|
expect(result).toBe(true);
|
|
|
|
app.models.Address.find({where: {clientFk: id}})
|
2018-02-02 15:24:22 +00:00
|
|
|
.then(result => {
|
|
|
|
expect(result[0].isEqualizated).toBeTruthy();
|
|
|
|
expect(result[1].isEqualizated).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
2018-01-23 14:59:21 +00:00
|
|
|
};
|
2018-01-24 12:45:32 +00:00
|
|
|
app.models.Address.find({where: {clientFk: id}})
|
2018-02-02 15:24:22 +00:00
|
|
|
.then(result => {
|
|
|
|
expect(result[0].isEqualizated).toBeFalsy();
|
|
|
|
expect(result[1].isEqualizated).toBeFalsy();
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
app.models.Client.addressesPropagateRe(id, data, callback);
|
|
|
|
})
|
|
|
|
.catch(catchErrors(done));
|
2018-01-23 14:59:21 +00:00
|
|
|
});
|
|
|
|
});
|