feat: refs #6276 test saleTracking_mark
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-01-22 12:36:52 +01:00
parent f04724a61f
commit ed713e762b
7 changed files with 100 additions and 22 deletions

View File

@ -18,5 +18,6 @@
"salix", "salix",
"fdescribe", "fdescribe",
"Loggable" "Loggable"
] ],
"CodeGPT.apiKey": "CodeGPT Plus Beta"
} }

View File

@ -210,6 +210,8 @@
"We do not have availability for the selected item": "We do not have availability for the selected item", "We do not have availability for the selected item": "We do not have availability for the selected item",
"You are already using a machine": "You are already using a machine", "You are already using a machine": "You are already using a machine",
"This worker does not exist": "This worker does not exist", "This worker does not exist": "This worker does not exist",
"this state does not exist": "This state does not exist" "this state does not exist": "This state does not exist",
"The line could not be marked": "The line could not be marked"
} }

View File

@ -331,7 +331,6 @@
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima", "quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
"Cannot past travels with entries": "No se pueden pasar envíos con entradas", "Cannot past travels with entries": "No se pueden pasar envíos con entradas",
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}", "It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}",
"The line could not be marked": "The line could not be marked",
"This claim has been updated": "La reclamación con Id: {{claimId}}, ha sido actualizada", "This claim has been updated": "La reclamación con Id: {{claimId}}, ha sido actualizada",
"This user does not have an assigned tablet": "Este usuario no tiene tablet asignada", "This user does not have an assigned tablet": "Este usuario no tiene tablet asignada",
"Incorrect pin": "Pin incorrecto.", "Incorrect pin": "Pin incorrecto.",
@ -347,5 +346,7 @@
"You are already using a machine": "Ya estás usando una máquina.", "You are already using a machine": "Ya estás usando una máquina.",
"This worker does not exist": "Este trabajador no existe", "This worker does not exist": "Este trabajador no existe",
"this state does not exist": "Este estado no existe", "this state does not exist": "Este estado no existe",
"Este estado no existe": "Este estado no existe" "Este estado no existe": "Este estado no existe",
"The line could not be marked": "No se ha podido marcar la línea",
"No se ha podido marcar la línea": "No se ha podido marcar la línea"
} }

View File

@ -268,14 +268,8 @@ class VnMySQL extends MySQL {
arguments, model, ctx, opts, cb); arguments, model, ctx, opts, cb);
} }
isLoggable(model) {
const Model = this.getModelDefinition(model).model;
const {settings} = Model.definition;
return settings?.mixins?.Loggable;
}
invokeMethod(method, args, model, ctx, opts, cb) { invokeMethod(method, args, model, ctx, opts, cb) {
if (!this.isLoggable(model)) if (!opts?.httpCtx)
return super[method].apply(this, args); return super[method].apply(this, args);
this.invokeMethodP(method, [...args], model, ctx, opts) this.invokeMethodP(method, [...args], model, ctx, opts)

View File

@ -54,6 +54,7 @@ module.exports = Self => {
Self.mark = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, quantity, itemShelvingFk, options) => { Self.mark = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, quantity, itemShelvingFk, options) => {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const models = Self.app.models; const models = Self.app.models;
const $t = ctx.req.__;
const myOptions = {}; const myOptions = {};
let tx; let tx;
@ -73,15 +74,9 @@ module.exports = Self => {
userFk: userId userFk: userId
}, myOptions); }, myOptions);
const itemShelving = await models.ItemShelving.findOne({ const itemShelving = await models.ItemShelving.findById(itemShelvingFk, myOptions);
where: {
id: itemShelvingFk
}
}, myOptions);
await itemShelving.updateAttributes({ await itemShelving.updateAttributes({visible: itemShelving.visible - quantity}, myOptions);
visible: itemShelving.visible - quantity}
, myOptions);
await Self.updateAll( await Self.updateAll(
{saleFk}, {saleFk},
@ -89,12 +84,21 @@ module.exports = Self => {
myOptions myOptions
); );
await Self.updateTracking(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, myOptions); await Self.updateTracking(ctx, saleFk, originalQuantity, code, isChecked, null, isScanned, myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw new UserError('The line could not be marked'); throw new UserError($t('The line could not be marked'));
} }
const buy = await models.Buy.findOne({
where: {
id: buyFk,
itemOriginalFk: {neq: null}
}
});
if (buy) await models.SaleBuy.create({saleFk, buyFk});
}; };
}; };

View File

@ -0,0 +1,76 @@
const {models} = require('vn-loopback/server/server');
fdescribe('saleTracking mark()', () => {
const saleFk = 1;
const originalQuantity = 10;
const code = 'PREPARED';
const isChecked = true;
const buyFk = 1;
const isScanned = false;
const quantity = 1;
const itemShelvingFk = 1;
beforeAll(async() => {
ctx = {
req: {
accessToken: {userId: 104},
headers: {origin: 'http://localhost'},
__: value => value
}
};
});
it('should throw an error if the line was not able to be marked', async() => {
const tx = await models.SaleTracking.beginTransaction({});
const options = {transaction: tx};
const code = 'FAKESTATE';
try {
await models.SaleTracking.mark(
ctx,
saleFk,
originalQuantity,
code,
isChecked,
buyFk,
isScanned,
quantity,
itemShelvingFk,
options
);
await tx.rollback();
} catch (e) {
const error = e;
expect(error.message).toEqual('The line could not be marked');
await tx.rollback();
}
});
it('should add an itemShelvingSale and Modify a saleTracking', async() => {
const tx = await models.SaleTracking.beginTransaction({});
const options = {transaction: tx};
try {
const itemShelvingSaleBefore = await models.ItemShelvingSale.find({}, options);
await models.SaleTracking.mark(
ctx,
saleFk,
originalQuantity,
code,
isChecked,
buyFk,
isScanned,
quantity,
itemShelvingFk,
options
);
const itemShelvingSaleAfter = await models.ItemShelvingSale.find({}, options);
const saleTracking = await models.SaleTracking.findOne({where: {saleFk, isChecked: false}}, options);
expect(itemShelvingSaleAfter.length).toEqual(itemShelvingSaleBefore.length + 1);
expect(saleTracking.isChecked).toBeFalse();
await tx.rollback();
} catch (e) {
await tx.rollback();
}
});
});

View File

@ -18,7 +18,7 @@ describe('saleTracking updateTracking()', () => {
}; };
}); });
it('should add a new saleTracking and saleBuy', async() => { it('should throw an error if the state does not exist', async() => {
const tx = await models.SaleTracking.beginTransaction({}); const tx = await models.SaleTracking.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
const code = 'FAKESTATE'; const code = 'FAKESTATE';