#9848 fix test and update fixtures

This commit is contained in:
Bernat 2019-02-13 13:19:15 +01:00
parent 8fa7abe191
commit bbd4188695
4 changed files with 206 additions and 98 deletions

View File

@ -3,16 +3,16 @@ const app = require('vn-loopback/server/server');
describe('order addToOrder()', () => {
let rowToDelete;
afterAll(async() => {
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 16});
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: 20});
});
it('should add a row to a given order', async() => {
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}});
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: 20}});
expect(unmodifiedRows.length).toBe(4);
expect(unmodifiedRows.length).toBe(1);
let params = {
orderFk: 16,
orderFk: 20,
items: [{
itemFk: 1,
quantity: 1,
@ -22,10 +22,10 @@ describe('order addToOrder()', () => {
await app.models.OrderRow.addToOrder(params);
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 16}});
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: 20}});
rowToDelete = modifiedRows[modifiedRows.length - 1].id;
expect(modifiedRows.length).toBe(5);
expect(modifiedRows.length).toBe(2);
});
});

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
describe('ticket getSales()', () => {
it('should return the sales of a ticket', async () => {
it('should return the sales of a ticket', async() => {
let sales = await app.models.Ticket.getSales(16);
expect(sales.length).toEqual(4);

View File

@ -0,0 +1,108 @@
USE `hedera`;
DROP procedure IF EXISTS `orderAddItem`;
DELIMITER $$
USE `hedera`$$
CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`(IN `vOrder` INT, IN `vWarehouse` INT, IN `vItem` INT, IN `vAmount` INT)
BEGIN
DECLARE vRow INT;
DECLARE vAdd INT;
DECLARE vAvailable INT;
DECLARE vDone BOOL;
DECLARE vGrouping INT;
DECLARE vRate INT;
DECLARE vShipment DATE;
DECLARE vPrice DECIMAL(10,2);
DECLARE vDate DATE;
DECLARE vAddress INT;
DECLARE vAgencyMode INT;
DECLARE cur CURSOR FOR
SELECT grouping, price, rate
FROM tmp.bionic_price
WHERE warehouse_id = vWarehouse
AND item_id = vItem
ORDER BY grouping DESC;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET vDone = TRUE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
SELECT date_send, address_id, agency_id
INTO vDate, vAddress, vAgencyMode
FROM `order`
WHERE id = vOrder;
CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem);
START TRANSACTION;
SELECT shipped INTO vShipment
FROM tmp.travel_tree
WHERE warehouseFk = vWarehouse;
SELECT available INTO vAvailable
FROM tmp.bionic_lot
WHERE warehouse_id = vWarehouse
AND item_id = vItem;
IF vAmount > IFNULL(vAvailable, 0)
THEN
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
END IF;
OPEN cur;
l: LOOP
SET vDone = FALSE;
FETCH cur INTO vGrouping, vPrice, vRate;
IF vDone THEN
LEAVE l;
END IF;
SET vAdd = vAmount - MOD(vAmount, vGrouping);
SET vAmount = vAmount - vAdd;
IF vAdd = 0 THEN
ITERATE l;
END IF;
INSERT INTO order_row SET
order_id = vOrder,
item_id = vItem,
warehouse_id = vWarehouse,
shipment = vShipment,
rate = vRate,
amount = vAdd,
price = vPrice;
SET vRow = LAST_INSERT_ID();
INSERT INTO order_component (order_row_id, component_id, price)
SELECT vRow, c.component_id, c.cost
FROM tmp.bionic_component c
JOIN bi.tarifa_componentes t
ON t.Id_Componente = c.component_id
AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate)
WHERE c.warehouse_id = vWarehouse
AND c.item_id = vItem;
END LOOP;
CLOSE cur;
IF vAmount > 0
THEN
CALL util.throw ('AMOUNT_NOT_MATCH_GROUPING');
END IF;
COMMIT;
CALL vn2008.bionic_free ();
END$$
DELIMITER ;

View File

@ -860,103 +860,109 @@ INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`, `date_make`, `first_row_stamp`, `confirm_date`)
VALUES
(1 , DATE_ADD(CURDATE(), INTERVAL -15 DAY) , 101, 1, 1, 121, 442, NULL, 'TPV', 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) ),
(2 , DATE_ADD(CURDATE(), INTERVAL -10 DAY) , 101, 2, 1, 121, 442, NULL, 'WEB', 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) ),
(3 , DATE_ADD(CURDATE(), INTERVAL -5 DAY) , 102, 3, 2, 122, 442, NULL, 'ANDROID', 1, DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) ),
(4 , DATE_ADD(CURDATE(), INTERVAL -4 DAY) , 102, 1, 2, 122, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) ),
(5 , DATE_ADD(CURDATE(), INTERVAL -3 DAY) , 103, 2, 3, 123, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) ),
(6 , DATE_ADD(CURDATE(), INTERVAL -2 DAY) , 103, 3, 3, 123, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) ),
(7 , DATE_ADD(CURDATE(), INTERVAL -1 DAY) , 104, 1, 4, 124, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) ),
(1 , DATE_ADD(CURDATE(), INTERVAL -15 DAY), 101, 1, 1, 121, 442, NULL, 'TPV', 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) , DATE_ADD(CURDATE(), INTERVAL -15 DAY) ),
(2 , DATE_ADD(CURDATE(), INTERVAL -10 DAY), 101, 2, 1, 121, 442, NULL, 'WEB', 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) , DATE_ADD(CURDATE(), INTERVAL -10 DAY) ),
(3 , DATE_ADD(CURDATE(), INTERVAL -5 DAY), 102, 3, 2, 122, 442, NULL, 'ANDROID', 1, DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) , DATE_ADD(CURDATE(), INTERVAL -5 DAY) ),
(4 , DATE_ADD(CURDATE(), INTERVAL -4 DAY), 102, 1, 2, 122, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) , DATE_ADD(CURDATE(), INTERVAL -4 DAY) ),
(5 , DATE_ADD(CURDATE(), INTERVAL -3 DAY), 103, 2, 3, 123, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) , DATE_ADD(CURDATE(), INTERVAL -3 DAY) ),
(6 , DATE_ADD(CURDATE(), INTERVAL -2 DAY), 103, 3, 3, 123, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) , DATE_ADD(CURDATE(), INTERVAL -2 DAY) ),
(7 , DATE_ADD(CURDATE(), INTERVAL -1 DAY), 104, 1, 4, 124, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) , DATE_ADD(CURDATE(), INTERVAL -1 DAY) ),
(8 , DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 104, 2, 4, 124, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
(9 , DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 105, 3, 5, 125, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH)),
(10, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), 105, 1, 6, 125, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(CURDATE(), INTERVAL -3 MONTH)),
(11, CURDATE() , 101, 2, 7, 121, 442, NULL, 'SALIX', 1, CURDATE() , CURDATE() , CURDATE() ),
(11, CURDATE(), 101, 2, 7, 121, 442, NULL, 'SALIX', 1, CURDATE() , CURDATE() , CURDATE() ),
(12, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 101, 3, 1, 121, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(CURDATE(), INTERVAL +1 MONTH), DATE_ADD(CURDATE(), INTERVAL +1 MONTH)),
(13, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 101, 1, 2, 121, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), DATE_ADD(CURDATE(), INTERVAL +2 MONTH), DATE_ADD(CURDATE(), INTERVAL +2 MONTH)),
(14, DATE_ADD(CURDATE(), INTERVAL +3 MONTH), 101, 2, 2, 121, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL +3 MONTH), DATE_ADD(CURDATE(), INTERVAL +3 MONTH), DATE_ADD(CURDATE(), INTERVAL +3 MONTH)),
(15, DATE_ADD(CURDATE(), INTERVAL +4 MONTH), 101, 3, 3, 121, 442, NULL, 'SALIX', 1, DATE_ADD(CURDATE(), INTERVAL +4 MONTH), DATE_ADD(CURDATE(), INTERVAL +4 MONTH), DATE_ADD(CURDATE(), INTERVAL +4 MONTH)),
(16, DATE_ADD(CURDATE(), INTERVAL +4 DAY) , 101, 1, 1, 121, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(17, CURDATE() , 106, 2, 4, 126, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(18, CURDATE() , 107, 3, 4, 127, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(19, CURDATE() , 108, 1, 5, 128, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(20, CURDATE() , 109, 2, 5, 119, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(21, CURDATE() , 110, 3, 5, 129, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() );
(16, DATE_ADD(CURDATE(), INTERVAL +4 DAY), 101, 1, 1, 121, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(17, CURDATE(), 106, 2, 4, 126, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(18, CURDATE(), 107, 3, 4, 127, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(19, CURDATE(), 108, 1, 5, 128, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(20, CURDATE(), 109, 2, 1, 119, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() ),
(21, CURDATE(), 110, 3, 5, 129, 442, NULL, 'SALIX', 0, CURDATE() , CURDATE() , CURDATE() );
INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipment`, `amount`, `price`, `rate`, `created`, `saleFk`)
VALUES
( 1, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 5, 9.10, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 1),
( 2, 1, 2, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 10, 1.07, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 2),
( 3, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 2, 9.10, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 3),
( 4, 1, 4, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 20, 3.06, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 4),
( 5, 2, 1, 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY), 10, 9.10, 0, DATE_ADD(CURDATE(), INTERVAL -10 DAY), 5),
( 6, 3, 1, 2, DATE_ADD(CURDATE(), INTERVAL -5 DAY), 15, 6.50, 0, DATE_ADD(CURDATE(), INTERVAL -5 DAY), 6),
( 7, 11, 2, 1, CURDATE(), 15, 1.30, 0, CURDATE(), 7),
( 8, 11, 4, 1, CURDATE(), 10, 3.26, 0, CURDATE(), 8),
( 9, 16, 1, 1, CURDATE(), 5, 9.10, 0, CURDATE(), 9),
( 10, 16, 2, 1, CURDATE(), 10, 1.07, 0, CURDATE(), 10),
( 11, 16, 1, 1, CURDATE(), 2, 9.10, 0, CURDATE(), 11),
( 12, 16, 4, 1, CURDATE(), 20, 3.06, 0, CURDATE(), 12);
(1, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 5, 9.10, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 1),
(2, 1, 2, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 10, 1.07, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 2),
(3, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 2, 9.10, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 3),
(4, 1, 4, 1, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 20, 3.06, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY), 4),
(5, 2, 1, 1, DATE_ADD(CURDATE(), INTERVAL -10 DAY), 10, 9.10, 0, DATE_ADD(CURDATE(), INTERVAL -10 DAY), 5),
(6, 3, 1, 2, DATE_ADD(CURDATE(), INTERVAL -5 DAY), 15, 6.50, 0, DATE_ADD(CURDATE(), INTERVAL -5 DAY), 6),
(7, 11, 2, 1, CURDATE(), 15, 1.30, 0, CURDATE(), 7),
(8, 11, 4, 1, CURDATE(), 10, 3.26, 0, CURDATE(), 8),
(9, 16, 1, 1, CURDATE(), 5, 9.10, 0, CURDATE(), 9),
(10, 16, 2, 1, CURDATE(), 10, 1.07, 0, CURDATE(), 10),
(11, 16, 1, 1, CURDATE(), 2, 9.10, 0, CURDATE(), 11),
(12, 16, 4, 1, CURDATE(), 20, 3.06, 0, CURDATE(), 12),
(13, 20, 1, 1, CURDATE(), 2, 9.10, 0, CURDATE(), NULL);
INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`)
VALUES
( 1, 15, 0.58),
( 1, 23, 6.5),
( 1, 28, 20.72),
( 1, 29, -18.72),
( 1, 39, 0.02),
( 2, 15, 0.058),
( 2, 21, 0.002),
( 2, 28, 5.6),
( 2, 29, -4.6),
( 2, 39, 0.01),
( 3, 15, 0.58),
( 3, 23, 6.5),
( 3, 28, 20.72),
( 3, 29, -18.72),
( 3, 39, 0.02),
( 4, 15, 0.051),
( 4, 21, -0.001),
( 4, 28, 20.72),
( 4, 29, -19.72),
( 4, 37, 2),
( 4, 39, 0.01),
( 5, 15, 0.58),
( 5, 23, 6.5),
( 5, 28, 20.72),
( 5, 29, -18.72),
( 5, 39, 0.02),
( 6, 23, 6.5),
( 7, 15, 0.29),
( 7, 28, 5.6),
( 7, 29, -4.6),
( 7, 39, 0.01),
( 8, 15, 0.254),
( 8, 21, -0.004),
( 8, 28, 20.72),
( 8, 29, -19.72),
( 8, 37, 2),
( 8, 39, 0.01),
( 9, 15, 0.58),
( 9, 23, 6.5),
( 9, 28, 20.72),
( 9, 29, -18.72),
( 9, 39, 0.02),
( 10, 15, 0.058),
( 10, 21, 0.002),
( 10, 28, 5.6),
( 10, 29, -4.6),
( 10, 39, 0.01),
( 11, 15, 0.58),
( 11, 23, 6.5),
( 11, 28, 20.72),
( 11, 29, -18.72),
( 11, 39, 0.02),
( 12, 15, 0.051),
( 12, 22, -0.001),
( 12, 28, 20.72),
( 12, 29, -19.72),
( 12, 37, 2),
( 12, 39, 0.01);
(1, 15, 0.58),
(1, 23, 6.5),
(1, 28, 20.72),
(1, 29, -18.72),
(1, 39, 0.02),
(2, 15, 0.058),
(2, 21, 0.002),
(2, 28, 5.6),
(2, 29, -4.6),
(2, 39, 0.01),
(3, 15, 0.58),
(3, 23, 6.5),
(3, 28, 20.72),
(3, 29, -18.72),
(3, 39, 0.02),
(4, 15, 0.051),
(4, 21, -0.001),
(4, 28, 20.72),
(4, 29, -19.72),
(4, 37, 2),
(4, 39, 0.01),
(5, 15, 0.58),
(5, 23, 6.5),
(5, 28, 20.72),
(5, 29, -18.72),
(5, 39, 0.02),
(6, 23, 6.5),
(7, 15, 0.29),
(7, 28, 5.6),
(7, 29, -4.6),
(7, 39, 0.01),
(8, 15, 0.254),
(8, 21, -0.004),
(8, 28, 20.72),
(8, 29, -19.72),
(8, 37, 2),
(8, 39, 0.01),
(9, 15, 0.58),
(9, 23, 6.5),
(9, 28, 20.72),
(9, 29, -18.72),
(9, 39, 0.02),
(10, 15, 0.058),
(10, 21, 0.002),
(10, 28, 5.6),
(10, 29, -4.6),
(10, 39, 0.01),
(11, 15, 0.58),
(11, 23, 6.5),
(11, 28, 20.72),
(11, 29, -18.72),
(11, 39, 0.02),
(12, 15, 0.051),
(12, 22, -0.001),
(12, 28, 20.72),
(12, 29, -19.72),
(12, 37, 2),
(12, 39, 0.01),
(13, 15, 0.58),
(13, 23, 6.5),
(13, 28, 20.72),
(13, 29, -18.72),
(13, 39, 0.02);
INSERT INTO `vn`.`clientContact`(`id`, `clientFk`, `name`, `phone`)
VALUES
@ -1042,13 +1048,7 @@ INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`)
(12, 12),
(13, 13),
(14, 14),
(15, 15),
(16, 16),
(17, 17),
(18, 18),
(19, 19),
(20, 20),
(21, 21);
(15, 15);
INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`)
VALUES