2022-02-08 11:41:55 +00:00
|
|
|
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
|
|
|
|
2022-02-08 11:41:55 +00:00
|
|
|
it('should change quantity sale', async() => {
|
2022-11-25 10:50:24 +00:00
|
|
|
const tx = await models.Ticket.beginTransaction({});
|
2023-10-19 11:03:11 +00:00
|
|
|
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-02-08 11:41:55 +00:00
|
|
|
|
2022-11-25 10:50:24 +00:00
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2022-02-08 11:41:55 +00:00
|
|
|
|
2022-11-25 10:50:24 +00:00
|
|
|
const saleId = 30;
|
|
|
|
const newQuantity = 10;
|
2022-02-08 11:41:55 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2022-02-08 11:41:55 +00:00
|
|
|
});
|
|
|
|
});
|