Merge branch 'dev' into 232401_dev_init
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-05-25 08:04:15 +00:00
commit 99f87aaf38
3 changed files with 34 additions and 14 deletions

View File

@ -84,6 +84,7 @@
"The current ticket can't be modified": "El ticket actual no puede ser modificado", "The current ticket can't be modified": "El ticket actual no puede ser modificado",
"The current claim can't be modified": "La reclamación actual no puede ser modificada", "The current claim can't be modified": "La reclamación actual no puede ser modificada",
"The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas", "The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas",
"The sales do not exists": "La(s) línea(s) seleccionada(s) no existe(n)",
"Please select at least one sale": "Por favor selecciona al menos una linea", "Please select at least one sale": "Por favor selecciona al menos una linea",
"All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket", "All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket",
"NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada", "NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada",

View File

@ -38,6 +38,9 @@ module.exports = Self => {
} }
}, myOptions); }, myOptions);
if (!salesData.length)
throw new UserError(`The sales do not exists`);
const ticketId = salesData[0].ticketFk; const ticketId = salesData[0].ticketFk;
const isTicketEditable = await models.Ticket.isEditable(ctx, ticketId, myOptions); const isTicketEditable = await models.Ticket.isEditable(ctx, ticketId, myOptions);
@ -62,7 +65,5 @@ module.exports = Self => {
throw new UserError('It is not possible to modify cloned sales'); throw new UserError('It is not possible to modify cloned sales');
if (!shouldEditFloramondo) if (!shouldEditFloramondo)
throw new UserError('It is not possible to modify sales that their articles are from Floramondo'); throw new UserError('It is not possible to modify sales that their articles are from Floramondo');
return true;
}; };
}; };

View File

@ -17,6 +17,32 @@ describe('sale canEdit()', () => {
}); });
}); });
describe('sale not exists', () => {
it('should return error if sale not exists', async() => {
const tx = await models.Sale.beginTransaction({});
try {
const options = {transaction: tx};
const developerId = 9;
const ctx = {req: {accessToken: {userId: developerId}}};
let max = await models.Sale.findOne({fields: ['id'], order: 'id DESC'}, options);
max.id = max.id + 1;
const sales = [max.id];
await models.Sale.canEdit(ctx, sales, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e.message;
}
expect(error).toEqual('The sales do not exists');
});
});
describe('sale editTracked', () => { describe('sale editTracked', () => {
it('should return true if the role is production regardless of the saleTrackings', async() => { it('should return true if the role is production regardless of the saleTrackings', async() => {
const tx = await models.Sale.beginTransaction({}); const tx = await models.Sale.beginTransaction({});
@ -29,9 +55,7 @@ describe('sale canEdit()', () => {
const sales = [25]; const sales = [25];
const result = await models.Sale.canEdit(ctx, sales, options); await models.Sale.canEdit(ctx, sales, options);
expect(result).toEqual(true);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -51,9 +75,7 @@ describe('sale canEdit()', () => {
const sales = [10]; const sales = [10];
const result = await models.Sale.canEdit(ctx, sales, options); await models.Sale.canEdit(ctx, sales, options);
expect(result).toEqual(true);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -87,9 +109,7 @@ describe('sale canEdit()', () => {
}); });
const ctx = {req: {accessToken: {userId: role.id}}}; const ctx = {req: {accessToken: {userId: role.id}}};
const result = await models.Sale.canEdit(ctx, saleCloned, options); await models.Sale.canEdit(ctx, saleCloned, options);
expect(result).toEqual(true);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -150,9 +170,7 @@ describe('sale canEdit()', () => {
const saleToEdit = await models.Sale.findById(sales[0], null, options); const saleToEdit = await models.Sale.findById(sales[0], null, options);
await saleToEdit.updateAttribute('itemFk', 9, options); await saleToEdit.updateAttribute('itemFk', 9, options);
const result = await models.Sale.canEdit(ctx, sales, options); await models.Sale.canEdit(ctx, sales, options);
expect(result).toEqual(true);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {