2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-08-21 12:59:04 +00:00
|
|
|
|
|
|
|
describe('loopback model address', () => {
|
|
|
|
let createdAddressId;
|
2021-06-23 11:24:23 +00:00
|
|
|
const clientId = 1101;
|
2018-09-06 08:42:43 +00:00
|
|
|
|
2021-10-15 12:45:41 +00:00
|
|
|
afterAll(async() => {
|
2020-01-28 08:03:20 +00:00
|
|
|
let client = await app.models.Client.findById(clientId);
|
2018-08-21 12:59:04 +00:00
|
|
|
|
|
|
|
await app.models.Address.destroyById(createdAddressId);
|
|
|
|
await client.updateAttribute('isEqualizated', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('observe()', () => {
|
2018-09-06 08:42:43 +00:00
|
|
|
it('should throw an error when deactivating a consignee if its the default address', async() => {
|
2018-08-21 12:59:04 +00:00
|
|
|
let error;
|
2018-09-06 08:42:43 +00:00
|
|
|
let address = await app.models.Address.findById(1);
|
2018-08-21 12:59:04 +00:00
|
|
|
|
|
|
|
await address.updateAttribute('isActive', false)
|
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
|
|
|
|
expect(error.message).toEqual('The default consignee can not be unchecked');
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set isEqualizated to true of a given Client to trigger any new address to have it', async() => {
|
2020-01-28 08:03:20 +00:00
|
|
|
let client = await app.models.Client.findById(clientId);
|
2018-08-21 12:59:04 +00:00
|
|
|
|
|
|
|
expect(client.isEqualizated).toBeFalsy();
|
|
|
|
|
|
|
|
await client.updateAttribute('isEqualizated', true);
|
|
|
|
|
|
|
|
let newAddress = await app.models.Address.create({
|
2020-01-28 08:03:20 +00:00
|
|
|
clientFk: clientId,
|
2018-08-21 12:59:04 +00:00
|
|
|
agencyModeFk: 5,
|
|
|
|
city: 'here',
|
|
|
|
isActive: true,
|
|
|
|
mobile: '555555555',
|
|
|
|
nickname: 'Test address',
|
|
|
|
phone: '555555555',
|
2019-09-19 07:17:21 +00:00
|
|
|
postalCode: '46000',
|
2018-08-21 12:59:04 +00:00
|
|
|
provinceFk: 1,
|
2020-01-28 08:03:20 +00:00
|
|
|
street: 'Test address',
|
|
|
|
incotermsFk: 'FAS',
|
|
|
|
customsAgentFk: 1
|
2018-08-21 12:59:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(newAddress.isEqualizated).toBeTruthy();
|
|
|
|
|
|
|
|
createdAddressId = newAddress.id;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|