This commit is contained in:
parent
bb787b1581
commit
910071bde0
|
@ -211,7 +211,7 @@ describe('sale model ', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should throw an error if the quantity is greater than the minimum quantity of the item but is out of range', async() => {
|
||||
it('should throw an error if the quantity is lower than the minimum quantity of the item and is in range', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||
|
||||
const saleId = 25;
|
||||
|
@ -233,6 +233,25 @@ describe('sale model ', () => {
|
|||
expect(e).toEqual(new Error('The amount cannot be less than the minimum'));
|
||||
}
|
||||
});
|
||||
|
||||
it('should update the quantity if the quantity is lower than the minimum quantity of the item and is out of the range', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||
|
||||
const saleId = 17;
|
||||
const newQuantity = 8;
|
||||
|
||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||
sqlStatement = `
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available;
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 100000 as price;`;
|
||||
params = null;
|
||||
}
|
||||
return models.Ticket.rawSql(sqlStatement, params, opts);
|
||||
});
|
||||
|
||||
await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue