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

62 lines
1.9 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
2024-06-11 08:45:46 +00:00
const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine');
2018-08-21 12:59:04 +00:00
describe('loopback model address', () => {
let createdAddressId;
const clientId = 1101;
2024-06-12 10:23:37 +00:00
beforeAll(() =>
mockLoopBackContext()
);
afterAll(async() => {
const client = await models.Client.findById(clientId);
2018-08-21 12:59:04 +00:00
await models.Address.destroyById(createdAddressId);
2018-08-21 12:59:04 +00:00
await client.updateAttribute('isEqualizated', false);
});
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;
const address = await 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() => {
const client = await models.Client.findById(clientId);
2018-08-21 12:59:04 +00:00
expect(client.isEqualizated).toBeFalsy();
await client.updateAttribute('isEqualizated', true);
const newAddress = await 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;
});
});
});