73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
const LoopBackContext = require('loopback-context');
|
|
|
|
describe('loopback model address', () => {
|
|
let createdAddressId;
|
|
const clientId = 1101;
|
|
|
|
const activeCtx = {
|
|
accessToken: {userId: 9},
|
|
http: {
|
|
req: {
|
|
headers: {origin: 'http://localhost'}
|
|
}
|
|
}
|
|
};
|
|
|
|
beforeAll(() => {
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
active: activeCtx
|
|
});
|
|
});
|
|
|
|
afterAll(async() => {
|
|
const client = await models.Client.findById(clientId);
|
|
|
|
await models.Address.destroyById(createdAddressId);
|
|
await client.updateAttribute('isEqualizated', false);
|
|
});
|
|
|
|
describe('observe()', () => {
|
|
it('should throw an error when deactivating a consignee if its the default address', async() => {
|
|
let error;
|
|
const address = await models.Address.findById(1);
|
|
|
|
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);
|
|
|
|
expect(client.isEqualizated).toBeFalsy();
|
|
|
|
await client.updateAttribute('isEqualizated', true);
|
|
|
|
const newAddress = await models.Address.create({
|
|
clientFk: clientId,
|
|
agencyModeFk: 5,
|
|
city: 'here',
|
|
isActive: true,
|
|
mobile: '555555555',
|
|
nickname: 'Test address',
|
|
phone: '555555555',
|
|
postalCode: '46000',
|
|
provinceFk: 1,
|
|
street: 'Test address',
|
|
incotermsFk: 'FAS',
|
|
customsAgentFk: 1
|
|
});
|
|
|
|
expect(newAddress.isEqualizated).toBeTruthy();
|
|
|
|
createdAddressId = newAddress.id;
|
|
});
|
|
});
|
|
});
|