2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-08-10 10:05:36 +00:00
|
|
|
|
|
|
|
describe('sale updateQuantity()', () => {
|
2021-05-26 07:14:18 +00:00
|
|
|
const ctx = {req: {accessToken: {userId: 9}}};
|
|
|
|
|
2018-08-10 10:05:36 +00:00
|
|
|
it('should throw an error if the quantity is not a number', async() => {
|
|
|
|
let error;
|
|
|
|
|
2021-05-26 07:14:18 +00:00
|
|
|
await app.models.Sale.updateQuantity(ctx, 1, 'wrong quantity!')
|
2018-08-10 10:05:36 +00:00
|
|
|
.catch(response => {
|
|
|
|
expect(response).toEqual(new Error('The value should be a number'));
|
|
|
|
error = response;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if the quantity is greater than it should be', async() => {
|
|
|
|
let error;
|
|
|
|
|
2021-05-26 07:14:18 +00:00
|
|
|
await app.models.Sale.updateQuantity(ctx, 1, 99)
|
2018-08-10 10:05:36 +00:00
|
|
|
.catch(response => {
|
|
|
|
expect(response).toEqual(new Error('The new quantity should be smaller than the old one'));
|
|
|
|
error = response;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update the quantity of a given sale current line', async() => {
|
|
|
|
let originalLineData = await app.models.Sale.findOne({where: {id: 1}, fields: ['quantity']});
|
|
|
|
|
|
|
|
expect(originalLineData.quantity).toEqual(5);
|
|
|
|
|
2021-05-26 07:14:18 +00:00
|
|
|
await app.models.Sale.updateQuantity(ctx, 1, 4);
|
2018-08-10 10:05:36 +00:00
|
|
|
|
|
|
|
let modifiedLineData = await app.models.Sale.findOne({where: {id: 1}, fields: ['quantity']});
|
|
|
|
|
|
|
|
expect(modifiedLineData.quantity).toEqual(4);
|
|
|
|
|
|
|
|
await app.models.Sale.update({id: 1}, {quantity: 5});
|
|
|
|
|
|
|
|
let resetLineDataValues = await app.models.Sale.findOne({where: {id: 1}, fields: ['quantity']});
|
|
|
|
|
|
|
|
expect(resetLineDataValues.quantity).toEqual(5);
|
|
|
|
});
|
|
|
|
});
|