diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 1e6c273ce..d51f16019 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -227,6 +227,13 @@ module.exports = Self => { ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance)); }); 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; if (!ctx.isNewInstance && changes) { let oldData = ctx.hookState.oldInstance; diff --git a/modules/client/back/models/specs/client.spec.js b/modules/client/back/models/specs/client.spec.js new file mode 100644 index 000000000..0ce70b4ae --- /dev/null +++ b/modules/client/back/models/specs/client.spec.js @@ -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; + }); + }); +});