From 96713076882aec3b8400c60e3cb621043e5babf0 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Mon, 3 Jun 2019 12:00:48 +0200 Subject: [PATCH] #1486 back test updateDiscount --- db/dump/fixtures.sql | 2 +- .../methods/sale/specs/updateDiscount.spec.js | 34 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b1cc35f63..38318f578 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -442,7 +442,7 @@ INSERT INTO `vn`.`ticket`(`id`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped (5, 3, 3, 3, DATE_ADD(CURDATE(), INTERVAL -3 DAY), DATE_ADD(CURDATE(), INTERVAL -3 DAY), 103, 'address 23', 123, 'T3333333', 0, DATE_ADD(CURDATE(), INTERVAL -3 DAY)), (6, 3, 3, 4, DATE_ADD(CURDATE(), INTERVAL -2 DAY), DATE_ADD(CURDATE(), INTERVAL -2 DAY), 103, 'address 23', 123, 'T4444444', 0, DATE_ADD(CURDATE(), INTERVAL -2 DAY)), (7, 4, 4, 4, DATE_ADD(CURDATE(), INTERVAL -1 DAY), DATE_ADD(CURDATE(), INTERVAL -1 DAY), 104, 'address 24', 124, 'T4444444', 0, DATE_ADD(CURDATE(), INTERVAL -1 DAY)), - (8, 1, 1, 4, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 104, 'address 24', 124, NULL, 0, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), + (8, 1, 1, 4, CURDATE(), CURDATE(), 104, 'address 24', 124, NULL, 0, CURDATE()), (9, 5, 5, 4, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 105, 'address 25', 125, 'A1111111', 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), (10, 6, 5, 5, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(CURDATE(), INTERVAL -3 MONTH), 105, 'address 25', 125, 'A1111111', 0, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), (11, 7, 1, 1, CURDATE() , CURDATE() , 101, 'address 21', 121, NULL, 0, CURDATE()), diff --git a/modules/ticket/back/methods/sale/specs/updateDiscount.spec.js b/modules/ticket/back/methods/sale/specs/updateDiscount.spec.js index 69f1a11ff..a193357f2 100644 --- a/modules/ticket/back/methods/sale/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateDiscount.spec.js @@ -2,12 +2,27 @@ const app = require('vn-loopback/server/server'); // #1486 back test updateDiscount xdescribe('sale updateDiscount()', () => { + const originalSaleId = 14; + let componentId; let originalSale; - let createdSaleComponent; + let saleComponentsRestore; + + beforeAll(async done => { + originalSale = await app.models.Sale.findById(originalSaleId); + let manaDiscount = await app.models.ComponentRate.findOne({where: {code: 'mana'}}); + componentId = manaDiscount.id; + saleComponentsRestore = await app.models.SaleComponent.findOne({ + where: { + componentFk: componentId, + saleFk: originalSaleId + } + }); + done(); + }); afterAll(async done => { originalSale.save(); - createdSaleComponent.destroy(); + saleComponentsRestore.save(); done(); }); @@ -45,15 +60,10 @@ xdescribe('sale updateDiscount()', () => { }); it('should update the discount if the salesPerson has mana', async() => { - const saleId = 1; - originalSale = await app.models.Sale.findById(saleId); - - let manaDiscount = await app.models.ComponentRate.findOne({where: {code: 'mana'}}); - let componentId = manaDiscount.id; - createdSaleComponent = await app.models.SaleComponent.findOne({ + let createdSaleComponent = await app.models.SaleComponent.findOne({ where: { componentFk: componentId, - saleFk: saleId + saleFk: originalSaleId } }); @@ -62,17 +72,17 @@ xdescribe('sale updateDiscount()', () => { const ticketId = 8; const sales = [ { - id: saleId, + id: originalSaleId, discount: 100} ]; await app.models.Sale.updateDiscount(ticketId, sales); - let updatedSale = await app.models.Sale.findById(saleId); + let updatedSale = await app.models.Sale.findById(originalSaleId); createdSaleComponent = await app.models.SaleComponent.findOne({ where: { componentFk: componentId, - saleFk: saleId + saleFk: originalSaleId } });