From e140c9d1f421904303327ba4cd51904b854eda43 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 3 May 2022 15:17:34 +0200 Subject: [PATCH] console.logs --- modules/client/back/models/client-credit.js | 7 +++++-- .../back/models/specs/clientCredit.spec.js | 18 +++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/client/back/models/client-credit.js b/modules/client/back/models/client-credit.js index 587ca0adc..96ac5a22a 100644 --- a/modules/client/back/models/client-credit.js +++ b/modules/client/back/models/client-credit.js @@ -12,13 +12,16 @@ module.exports = Self => { where: {clientFk: instance.clientFk}, order: 'created DESC' }); - if (clientCredit.length > maxCreditRows) { const creditToDestroy = []; for (const [index, credit] of clientCredit.entries()) { - if (index >= maxCreditRows) + console.log(index); + if (index >= maxCreditRows) { + console.log(index, 'BORRAR'); creditToDestroy.push(credit.id); + } } + await models.ClientCredit.destroyAll({ id: {inq: creditToDestroy} }); diff --git a/modules/client/back/models/specs/clientCredit.spec.js b/modules/client/back/models/specs/clientCredit.spec.js index db5004e5c..4d4c2bdee 100644 --- a/modules/client/back/models/specs/clientCredit.spec.js +++ b/modules/client/back/models/specs/clientCredit.spec.js @@ -9,23 +9,20 @@ describe('Client Credit', () => { const clientConfig = await models.ClientConfig.findOne({ where: {id: 1} }); - let rowsBefore; let rowsAfter; try { const options = {transaction: tx}; - const context = {options}; - - rowsBefore = await models.ClientCredit.find({ - where: {clientFk: instance.id} - }, options); - + const ctx = {options}; const salesAssistant = await models.Account.findOne({ where: {name: 'salesAssistant'} }, options); - context.options.accessToken = {userId: salesAssistant.id}; - - await models.Client.changeCredit(context, instance, {credit: 350}); + ctx.options.accessToken = {userId: salesAssistant.id}; + await models.ClientCredit.create({ + amount: 355, + clientFk: instance.id, + workerFk: salesAssistant.id + }, ctx.options); rowsAfter = await models.ClientCredit.find({ where: {clientFk: instance.id} @@ -37,7 +34,6 @@ describe('Client Credit', () => { throw e; } - expect(rowsBefore.length).toEqual(11); expect(rowsAfter.length).toEqual(clientConfig.maxCreditRows); }); });