salix/modules/client/back/models/specs/address.spec.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

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;
const clientId = 1101;
2019-02-28 09:17:09 +00:00
afterAll(async done => {
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);
2019-02-28 09:17:09 +00:00
done();
2018-08-21 12:59:04 +00:00
});
describe('observe()', () => {
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;
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;
});
});
});