test client hook
This commit is contained in:
parent
2c5f44f94a
commit
061dceb2b0
|
@ -227,6 +227,13 @@ module.exports = Self => {
|
||||||
ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance));
|
ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance));
|
||||||
});
|
});
|
||||||
account.observe('after save', async ctx => {
|
account.observe('after save', async ctx => {
|
||||||
|
console.log('--------------asdajdgsaysdgahsdkasgdagdsjhagdkadasda--------------');
|
||||||
|
console.log('--------------asdajdgsaysdgahsdkasgdagdsjhagdkadasda--------------');
|
||||||
|
console.log('--------------asdajdgsaysdgahsdkasgdagdsjhagdkadasda--------------');
|
||||||
|
console.log('--------------asdajdgsaysdgahsdkasgdagdsjhagdkadasda--------------');
|
||||||
|
console.log('--------------asdajdgsaysdgahsdkasgdagdsjhagdkadasda--------------');
|
||||||
|
console.log('--------------asdajdgsaysdgahsdkasgdagdsjhagdkadasda--------------');
|
||||||
|
console.log('--------------asdajdgsaysdgahsdkasgdagdsjhagdkadasda--------------');
|
||||||
let changes = ctx.data || ctx.instance;
|
let changes = ctx.data || ctx.instance;
|
||||||
if (!ctx.isNewInstance && changes) {
|
if (!ctx.isNewInstance && changes) {
|
||||||
let oldData = ctx.hookState.oldInstance;
|
let oldData = ctx.hookState.oldInstance;
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
fdescribe('loopback model client', () => {
|
||||||
|
const accountId = 101;
|
||||||
|
let originalValue;
|
||||||
|
afterAll(async done => {
|
||||||
|
// await originalValue.save();
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('observe()', () => {
|
||||||
|
it('should log when we update the account model', async() => {
|
||||||
|
originalValue = await app.models.Account.findById(accountId);
|
||||||
|
let account = await app.models.Account.findById(accountId);
|
||||||
|
|
||||||
|
await account.updateAttribute('name', 'updatingName');
|
||||||
|
let clientLog = await app.models.ClientLog.find({where: {originFk: accountId}});
|
||||||
|
console.log('clientLog', clientLog);
|
||||||
|
// let logs = await app.models.ClientLog.find({fields: ['id', 'newInstance']});
|
||||||
|
|
||||||
|
// let m3Log = logs.filter(log => {
|
||||||
|
// return log.newInstance.m3 === 1.9;
|
||||||
|
// });
|
||||||
|
// logIdToDestroy = m3Log[0].id;
|
||||||
|
|
||||||
|
expect(clientLog).toBe();
|
||||||
|
});
|
||||||
|
|
||||||
|
xit('should set isEqualizated to true of a given Client to trigger any new address to have it', async() => {
|
||||||
|
let client = await app.models.Client.findById(clientId);
|
||||||
|
|
||||||
|
expect(client.isEqualizated).toBeFalsy();
|
||||||
|
|
||||||
|
await client.updateAttribute('isEqualizated', true);
|
||||||
|
|
||||||
|
let newAddress = await app.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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue