console.logs
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-05-03 15:17:34 +02:00
parent b40b8d931d
commit e140c9d1f4
2 changed files with 12 additions and 13 deletions

View File

@ -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}
});

View File

@ -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);
});
});