fix test back

This commit is contained in:
Alexandre Riera 2022-11-16 13:46:16 +01:00
parent 3dd43d21ae
commit e4a6585b6a
3 changed files with 14 additions and 11 deletions

View File

@ -21,3 +21,7 @@ BEGIN
CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity);
END$$
DELIMITER ;
INSERT INTO `salix`.`ACL`
(model, property, accessType, permission, principalType, principalId)
VALUES('Sale', 'missingTrash', 'WRITE', 'ALLOW', 'ROLE', 'employee');

View File

@ -7,23 +7,22 @@ describe('sale missingTrash()', () => {
try {
const options = { transaction: tx };
const saleFk = 1;
const quantity = 3;
const quantity = 1;
const isTrash = true;
const warehouseFk = 1;
const newQuantity = 2;
const ctx = { req: { accessToken: { userId: 9 } } };
let sale = await models.Sale.findById(saleFk, null, options);
expect(sale.quantity).toEqual(5);
expect(sale.originalQuantity).toBe(null);
const sale = await models.Sale.findOne({fields: ['id','quantity', 'originalQuantity', 'ticketFk']}, options);
console.log(sale);
const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options);
console.log(ticket);
const newQuantity = sale.quantity-quantity;
await models.Sale.missingTrash(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options);
await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options);
sale = await models.Sale.findById(saleFk, null, options);
expect(sale.quantity).toEqual(2);
expect(sale.originalQuantity).toBe(5);
const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options);
expect(saleAfter.quantity).toEqual(newQuantity);
expect(saleAfter.originalQuantity).toBe(sale.quantity);
await tx.rollback();