salix/back/methods/collection/spec/setSaleQuantity.spec.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
describe('setSaleQuantity()', () => {
2024-06-14 06:39:57 +00:00
beforeAll.mockLoopBackContext();
2023-03-23 09:05:02 +00:00
it('should change quantity sale', async() => {
2022-11-25 10:50:24 +00:00
const tx = await models.Ticket.beginTransaction({});
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => {
if (sqlStatement.includes('catalog_calcFromItem')) {
sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY
SELECT 100 as available;`;
params = null;
}
return models.Ticket.rawSql(sqlStatement, params, options);
});
2022-11-25 10:50:24 +00:00
try {
const options = {transaction: tx};
2022-11-25 10:50:24 +00:00
const saleId = 30;
const newQuantity = 10;
2022-11-25 10:50:24 +00:00
const originalSale = await models.Sale.findById(saleId, null, options);
await models.Collection.setSaleQuantity(saleId, newQuantity, options);
const updateSale = await models.Sale.findById(saleId, null, options);
2023-03-08 11:10:08 +00:00
expect(updateSale.quantity).not.toEqual(originalSale.quantity);
2022-11-25 10:50:24 +00:00
expect(updateSale.quantity).toEqual(newQuantity);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});