2022-02-08 11:41:55 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2023-03-23 09:05:02 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
2022-02-08 11:41:55 +00:00
|
|
|
|
|
|
|
describe('setSaleQuantity()', () => {
|
2023-03-23 09:05:02 +00:00
|
|
|
beforeAll(async() => {
|
|
|
|
const activeCtx = {
|
|
|
|
accessToken: {userId: 9},
|
|
|
|
http: {
|
|
|
|
req: {
|
|
|
|
headers: {origin: 'http://localhost'}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
|
|
active: activeCtx
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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-17 09:00:41 +00:00
|
|
|
spyOn(models.Item, 'getVisibleAvailable').and.returnValue((new Promise(resolve => resolve({available: 100}))));
|
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
|
|
|
});
|
|
|
|
});
|