const app = require(`${serviceRoot}/server/server`); describe('sale updateQuantity()', () => { it('should throw an error if the quantity is not a number', async() => { let error; await app.models.Sale.updateQuantity(1, 'wrong quantity!') .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; await app.models.Sale.updateQuantity(1, 99) .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); await app.models.Sale.updateQuantity(1, 4); 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); }); });