#527 getLastEntries.js unit tests + fixtures + threeKastActive refactor

This commit is contained in:
Carlos Jimenez 2018-08-16 12:10:56 +02:00
parent b4321816be
commit 51e5e76edd
3 changed files with 54 additions and 23 deletions

View File

@ -662,9 +662,9 @@ INSERT INTO `vn`.`itemLog` (`id`, `originFk`, `userFk`, `action`, `description`)
INSERT INTO `vn`.`recovery`(`id`, `clientFk`, `started`, `finished`, `amount`, `period`) INSERT INTO `vn`.`recovery`(`id`, `clientFk`, `started`, `finished`, `amount`, `period`)
VALUES VALUES
( 1, 101, date_add(CURDATE(),INTERVAL -7 MONTH), date_add(CURDATE(),INTERVAL -3 MONTH), 50, 7), ( 1, 101, DATE_ADD(CURDATE(),INTERVAL -7 MONTH), DATE_ADD(CURDATE(),INTERVAL -3 MONTH), 50, 7),
( 2, 102, date_add(CURDATE(),INTERVAL -5 MONTH), CURDATE(), 100, 1), ( 2, 102, DATE_ADD(CURDATE(),INTERVAL -5 MONTH), CURDATE(), 100, 1),
( 3, 102, CURDATE(), date_add(CURDATE(),INTERVAL 1 MONTH), 50, 7), ( 3, 102, CURDATE(), DATE_ADD(CURDATE(),INTERVAL 1 MONTH), 50, 7),
( 4, 103, CURDATE(), NULL, 50, 7); ( 4, 103, CURDATE(), NULL, 50, 7);
INSERT INTO `bi`.`rotacion`(`Id_Article`, `warehouse_id`, `total`, `rotacion`, `cm3`, `almacenaje`, `manipulacion`, `auxiliar`, `mermas`) INSERT INTO `bi`.`rotacion`(`Id_Article`, `warehouse_id`, `total`, `rotacion`, `cm3`, `almacenaje`, `manipulacion`, `auxiliar`, `mermas`)
@ -704,17 +704,17 @@ INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`)
INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `m3`, `kg`) INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `m3`, `kg`)
VALUES VALUES
( 1, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 1, 2, 1, 100.00, 1000), (1, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000),
( 2, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 1, 2, 1, 150, 2000), (2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000),
( 3, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 1, 2, 1, 0.00, 0.00), (3, CURDATE(), CURDATE(), 1, 2, 1, 0.00, 0.00),
( 4, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 1, 2, 1, 50.00, 500); (4, DATE_ADD(CURDATE(), INTERVAL -30 DAY), DATE_ADD(CURDATE(), INTERVAL -30 DAY), 1, 2, 1, 50.00, 500);
INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `companyFk`) INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `companyFk`)
VALUES VALUES
( 1, 1, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 1, 442), ( 1, 1, DATE_ADD(CURDATE(), INTERVAL -30 DAY), 1, 442),
( 2, 2, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 2, 442), ( 2, 2, DATE_ADD(CURDATE(), INTERVAL -30 DAY), 2, 442),
( 3, 1, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 3, 442), ( 3, 1, DATE_ADD(CURDATE(), INTERVAL -30 DAY), 3, 442),
( 4, 2, DATE_ADD(CURDATE(), INTERVAL -30 DAY) , 4, 69); ( 4, 2, DATE_ADD(CURDATE(), INTERVAL -30 DAY), 4, 69);
INSERT INTO `vn`.`agencyProvince`(`provinceFk`, `agencyFk`, `zone`, `warehouseFk`) INSERT INTO `vn`.`agencyProvince`(`provinceFk`, `agencyFk`, `zone`, `warehouseFk`)
VALUES VALUES
@ -752,16 +752,18 @@ INSERT INTO `bi`.`claims_ratio`(`id_Cliente`, `Consumo`, `Reclamaciones`, `Ratio
( 103, 2000, 0.00, 0.00, 0.02, 1.00), ( 103, 2000, 0.00, 0.00, 0.02, 1.00),
( 104, 2500, 150.00, 0.02, 0.10, 1.00); ( 104, 2500, 150.00, 0.02, 0.10, 1.00);
INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packageFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`,`minPrice`,`producer`,`printedStickers`,`isChecked`,`isIgnored`) INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packageFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`,`minPrice`,`producer`,`printedStickers`,`isChecked`,`isIgnored`, `created`)
VALUES VALUES
(1, 1, 1, 2.5, 5000 , 1, 1, 0.350, 0.050, 0.000, 1, 1, 0, NULL, 1.50, 1.25, 1.30, 2.00, NULL, 0, 1, 0), (1, 1, 1, 2.5, 5000 , 1, 1, 0.350, 0.050, 0.000, 1, 1, 0, NULL, 1.50, 1.25, 1.30, 2.00, NULL, 0, 1, 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)),
(2, 2, 2, 5 , 450 , 1, 1, 0.500, 0.100, 0.000, 1, 1, 0, NULL, 2, 1.00, 1.30, 2.00, NULL, 0, 1, 0), (2, 2, 1, 20 , 100 , 1, 1, 0.700, 0.020, 0.000, 1, 1, 0, NULL, 2.50, 1.00, 2.50, 2.00, NULL, 0, 1, 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),
(3, 3, 3, 10 , 500 , 1, 1, 1.000, 0.050, 0.000, 1, 1, 0, NULL, 2.50, 1.00, 2.50, 2.00, NULL, 0, 1, 0), (3, 3, 1, 20 , 100 , 1, 1, 0.700, 0.020, 0.000, 1, 1, 0, NULL, 2.50, 1.00, 2.50, 2.00, NULL, 0, 1, 0, CURDATE()),
(4, 4, 4, 20 , 100 , 1, 1, 0.700, 0.020, 0.000, 1, 1, 0, NULL, 2.50, 1.00, 2.50, 2.00, NULL, 0, 1, 0); (4, 2, 2, 5 , 450 , 1, 1, 0.500, 0.100, 0.000, 1, 1, 0, NULL, 2, 1.00, 1.30, 2.00, NULL, 0, 1, 0, CURDATE()),
(5, 3, 3, 10 , 500 , 1, 1, 1.000, 0.050, 0.000, 1, 1, 0, NULL, 2.50, 1.00, 2.50, 2.00, NULL, 0, 1, 0, CURDATE()),
(6, 4, 4, 20 , 100 , 1, 1, 0.700, 0.020, 0.000, 1, 1, 0, NULL, 2.50, 1.00, 2.50, 2.00, NULL, 0, 1, 0, CURDATE());
INSERT INTO `vn2008`.`tblContadores`(`id`,`FechaInventario`) INSERT INTO `vn2008`.`tblContadores`(`id`,`FechaInventario`)
VALUES VALUES
(1,date_add(CURDATE(),INTERVAL -1 MONTH)); (1,DATE_ADD(CURDATE(),INTERVAL -1 MONTH));
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`) INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
VALUES VALUES
@ -772,9 +774,9 @@ 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`) 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 VALUES
( 1, date_add(CURDATE(),INTERVAL +1 DAY), 101, 1, 1, 121, 442, NULL, 'TPV' , 1, CURDATE(), CURDATE() , CURDATE()), ( 1, DATE_ADD(CURDATE(),INTERVAL +1 DAY), 101, 1, 1, 121, 442, NULL, 'TPV' , 1, CURDATE(), CURDATE() , CURDATE()),
( 2, date_add(CURDATE(),INTERVAL +1 DAY), 102, 2, 2, 122, 442, NULL, 'WEB' , 1, CURDATE(), CURDATE() , CURDATE()), ( 2, DATE_ADD(CURDATE(),INTERVAL +1 DAY), 102, 2, 2, 122, 442, NULL, 'WEB' , 1, CURDATE(), CURDATE() , CURDATE()),
( 3, date_add(CURDATE(),INTERVAL +2 DAY), 103, 3, 3, 123, 442, NULL, 'ANDROID', 0, CURDATE(), date_add(CURDATE(), INTERVAL +5 DAY), date_add(CURDATE(),INTERVAL +5 DAY)); ( 3, DATE_ADD(CURDATE(),INTERVAL +2 DAY), 103, 3, 3, 123, 442, NULL, 'ANDROID', 0, CURDATE(), DATE_ADD(CURDATE(), INTERVAL +5 DAY), DATE_ADD(CURDATE(),INTERVAL +5 DAY));
INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipment`, `amount`, `price`, `rate`, `created`, `saleFk`) INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipment`, `amount`, `price`, `rate`, `created`, `saleFk`)
VALUES VALUES

View File

@ -0,0 +1,29 @@
const app = require(`${servicesDir}/item/server/server`);
describe('item getLastEntries()', () => {
it('should return one entry for a given item', async() => {
let date = new Date();
let filter = {where: {itemFk: 1, date: date}};
let result = await app.models.Item.getLastEntries(filter);
expect(result.length).toEqual(1);
});
it('should return two entries for a given item', async() => {
let date = new Date();
date.setMonth(date.getMonth() - 1);
let filter = {where: {itemFk: 1, date: date}};
let result = await app.models.Item.getLastEntries(filter);
expect(result.length).toEqual(2);
});
it('should return three entries for a given item', async() => {
let date = new Date();
date.setMonth(date.getMonth() - 2);
let filter = {where: {itemFk: 1, date: date}};
let result = await app.models.Item.getLastEntries(filter);
expect(result.length).toEqual(3);
});
});

View File

@ -3,9 +3,9 @@ const app = require(`${servicesDir}/ticket/server/server`);
describe('ticket threeLastActive()', () => { describe('ticket threeLastActive()', () => {
it('should return the last three active tickets', async() => { it('should return the last three active tickets', async() => {
let expectedResult = [ let expectedResult = [
{id: 12, shipped: '2018-09-14 00:00:00', agencyName: 'inhouse pickup', warehouseName: 'Warehouse One'}, {id: 12, shipped: '2018-09-16 00:00:00', agencyName: 'inhouse pickup', warehouseName: 'Warehouse One'},
{id: 13, shipped: '2018-10-14 00:00:00', agencyName: 'Super-Man delivery', warehouseName: 'Warehouse Two'}, {id: 13, shipped: '2018-10-16 00:00:00', agencyName: 'Super-Man delivery', warehouseName: 'Warehouse Two'},
{id: 14, shipped: '2018-11-14 00:00:00', agencyName: 'Super-Man delivery', warehouseName: 'Warehouse Two'} {id: 14, shipped: '2018-11-16 00:00:00', agencyName: 'Super-Man delivery', warehouseName: 'Warehouse Two'}
]; ];
expectedResult = JSON.stringify(expectedResult); expectedResult = JSON.stringify(expectedResult);