diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index b12e9fc53..a6ddd2e3f 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -73,6 +73,7 @@ diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 6d84781e7..f86cb17eb 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -1,31 +1,121 @@ const app = require('vn-loopback/server/server'); -describe('sale updatePrice()', () => { - it('should throw an error if the price is not a number', async() => { - let error; +// #1489 updatePrice backTest +xdescribe('sale updatePrice()', () => { + it('should set price to 0 if the params price is undefined', async() => { + let params = { + price: undefined, + id: 13, + ticketFk: 8 + }; + await app.models.Sale.updatePrice(params); + let saleUpdated = await app.models.Sale.findById(params.id); - let params = {price: `this price is so wrong!`}; - - await app.models.Sale.updatePrice(params) - .catch(response => { - expect(response).toEqual(new Error('The value should be a number')); - error = response; - }); - - expect(error).toBeDefined(); + expect(saleUpdated.price).toEqual(0); }); - it(`should throw an error if the price is undefined`, async() => { - let error; + it('should set price as a decimal number', async() => { + let params = { + price: 5.5, + id: 13, + ticketFk: 8 + }; + await app.models.Sale.updatePrice(params); + let saleUpdated = await app.models.Sale.findById(params.id); - let params = {ticketFk: 1, price: undefined}; - - await app.models.Sale.updatePrice(params) - .catch(response => { - expect(response).toEqual(new Error('The value should be a number')); - error = response; - }); - - expect(error).toBeDefined(); + expect(saleUpdated.price).toEqual(5.5); }); + + it('should now set price as a decimal number in a string', async() => { + let params = { + price: '5.5', + id: 13, + ticketFk: 8 + }; + await app.models.Sale.updatePrice(params); + let saleUpdated = await app.models.Sale.findById(params.id); + + expect(saleUpdated.price).toEqual(5.5); + }); + + it('should return 0 if the price is an empty string', async() => { + let params = { + price: '', + id: 13, + ticketFk: 8 + }; + await app.models.Sale.updatePrice(params); + let saleUpdated = await app.models.Sale.findById(params.id); + + expect(saleUpdated.price).toEqual(0); + }); + + + it('should este crea mana', async() => { + let params = { + price: 5.5, + id: 13, + ticketFk: 8 + }; + await app.models.Sale.updatePrice(params); + let saleUpdated = await app.models.Sale.findById(params.id); + + expect(saleUpdated.price).toEqual(5.5); + }); + + it('should este no crea el mana', async() => { + let params = { + price: 5.5, + id: 13, + ticketFk: 8 + }; + let todosLosComponentes = await app.models.SaleComponent.find({where: {saleFk: 13}}); + + expect(todosLosComponentes[0].value).toEqual(''); + expect(todosLosComponentes[1].value).toEqual(''); + expect(todosLosComponentes[2].value).toEqual(''); + expect(todosLosComponentes[3].value).toEqual(''); + expect(todosLosComponentes[4].value).toEqual(''); + + await app.models.Sale.updatePrice(params); + todosLosComponentes = await app.models.SaleComponent.find({where: {saleFk: 13}}); + let saleUpdated = await app.models.Sale.findById(params.id); + + expect(saleUpdated.price).toEqual(5.5); + + expect(todosLosComponentes[0].value).toEqual(''); + expect(todosLosComponentes[1].value).toEqual(''); + expect(todosLosComponentes[2].value).toEqual(''); + expect(todosLosComponentes[3].value).toEqual(''); + expect(todosLosComponentes[4].value).toEqual(''); + }); + // 2 let componentToUse; + // if (usesMana) + // componentToUse = 37; + // 3else + // componentToUse = 34; + + // 4 if (saleComponent) + // saleComponent.updateAttributes({value: saleComponent.value + value}); + // 5 else { + // await Self.app.models.SaleComponent.create({ + // saleFk: params.id, + // componentFk: componentToUse, + // value: value + // }); + // } + + // it(`should throw an error if the price is undefined`, async() => { + // let error; + + // let params = {ticketFk: 1, price: undefined}; + + // await app.models.Sale.updatePrice(params) + // .catch(response => { + // expect(response).toEqual(new Error('The value should be a number')); + // error = response; + // }); + + // expect(error).toBeDefined(); + // }); });