From 4f20716fa3dea884db77d8b40b93d47a08bb8086 Mon Sep 17 00:00:00 2001 From: Bernat Date: Wed, 29 May 2019 14:59:26 +0200 Subject: [PATCH 1/3] #1489 updatePrice backTest --- .../methods/sale/specs/updatePrice.spec.js | 136 +++++++++++++++--- 1 file changed, 113 insertions(+), 23 deletions(-) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 6d84781e7..3b0de8220 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); + }); + + + fit('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); + }); + + fit('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(); + // }); }); From d742eef7c382fe1fe7f2dbe7b2565a6bf426b3c7 Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 30 May 2019 08:04:46 +0200 Subject: [PATCH 2/3] Tarea #1478 item.basicData --- modules/item/front/basic-data/index.html | 1 + 1 file changed, 1 insertion(+) 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 @@ From 24c3b356058f286e648fc39220e13545bb6e2613 Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 30 May 2019 08:06:52 +0200 Subject: [PATCH 3/3] Test #1489 updatePrice backTest skipped --- modules/ticket/back/methods/sale/specs/updatePrice.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 3b0de8220..f86cb17eb 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -51,7 +51,7 @@ xdescribe('sale updatePrice()', () => { }); - fit('should este crea mana', async() => { + it('should este crea mana', async() => { let params = { price: 5.5, id: 13, @@ -63,7 +63,7 @@ xdescribe('sale updatePrice()', () => { expect(saleUpdated.price).toEqual(5.5); }); - fit('should este no crea el mana', async() => { + it('should este no crea el mana', async() => { let params = { price: 5.5, id: 13,