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

73 lines
2.2 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
2018-08-21 12:59:04 +00:00
describe('loopback model address', () => {
let createdAddressId;
const clientId = 1101;
const activeCtx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
}
};
2022-05-11 17:38:10 +00:00
beforeAll(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
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;
});
});
});