feat(back): new Date mocked time
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-04-01 13:55:45 +02:00
parent d86f4da425
commit c904bf0bdf
126 changed files with 501 additions and 293 deletions

3
back/helpers.spec.js Normal file
View File

@ -0,0 +1,3 @@
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
jasmine.clock().mockDate(baseTime);

View File

@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server');
describe('campaign latest()', () => {
it('should return the campaigns from the last year', async() => {
const now = new Date('2022-01-19');
const now = new Date();
const result = await app.models.Campaign.latest();
const randomIndex = Math.floor(Math.random() * result.length);
const campaignDated = result[randomIndex].dated;
@ -12,7 +12,7 @@ describe('campaign latest()', () => {
});
it('should return the campaigns from the current year', async() => {
const now = new Date('2022-01-19');
const now = new Date();
const currentYear = now.getFullYear();
const result = await app.models.Campaign.latest({
where: {dated: {like: `%${currentYear}%`}}

View File

@ -4,7 +4,7 @@ describe('campaign upcoming()', () => {
it('should return the upcoming campaign but from the last year', async() => {
const response = await app.models.Campaign.upcoming();
const campaignDated = response.dated;
const now = new Date('2022-01-19');
const now = new Date();
expect(campaignDated).toEqual(jasmine.any(Date));
expect(campaignDated).toBeLessThanOrEqual(now);

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('Chat sendCheckingPresence()', () => {
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(6, 0);
const ctx = {req: {accessToken: {userId: 1}}};
const chatModel = models.Chat;

View File

@ -0,0 +1,57 @@
DELIMITER ;;
DROP FUNCTION IF EXISTS `vn`.`getEnvironment`;
CREATE FUNCTION `vn`.`getEnvironment`()
RETURNS VARCHAR(25)
DETERMINISTIC
BEGIN
DECLARE vEnvironment VARCHAR(25);
SELECT environment INTO vEnvironment
FROM `util`.`config`
LIMIT 1;
RETURN vEnvironment;
END ;;
DELIMITER ;
DELIMITER ;;
DROP FUNCTION IF EXISTS `vn`.`VN_CURDATE`;
CREATE FUNCTION `vn`.`VN_CURDATE`()
RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN DATE('2022-01-19');
ELSE
RETURN CURDATE();
END IF;
END ;;
DELIMITER ;
DELIMITER ;;
DROP FUNCTION IF EXISTS `vn`.`VN_CURTIME`;
CREATE FUNCTION `vn`.`VN_CURTIME`()
RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIME('00:00:00');
ELSE
RETURN CURTIME();
END IF;
END ;;
DELIMITER ;
DELIMITER ;;
DROP FUNCTION IF EXISTS `vn`.`VN_NOW`;
CREATE FUNCTION `vn`.`VN_NOW`()
RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIMESTAMP('2022-01-19 00:00:00');
ELSE
RETURN NOW();
END IF;
END ;;
DELIMITER ;

File diff suppressed because one or more lines are too long

View File

@ -41,7 +41,7 @@ RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIME('08:25:00');
RETURN TIME('00:00:00');
ELSE
RETURN CURTIME();
END IF;
@ -55,7 +55,7 @@ RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIMESTAMP('2022-01-19 08:25:00');
RETURN TIMESTAMP('2022-01-19 00:00:00');
ELSE
RETURN NOW();
END IF;

View File

@ -8413,7 +8413,7 @@ DECLARE rs CURSOR FOR
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET myTime = HOUR(now()) + MINUTE(now()) / 60;
SET myTime = HOUR(vn.VN_NOW()) + MINUTE(vn.VN_NOW()) / 60;
OPEN rs;
@ -8498,7 +8498,7 @@ DECLARE rs CURSOR FOR
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET myTime = HOUR(now()) + MINUTE(now()) / 60;
SET myTime = HOUR(vn.VN_NOW()) + MINUTE(vn.VN_NOW()) / 60;
OPEN rs;
@ -9116,7 +9116,7 @@ CREATE TABLE `ekt` (
`deliveryNumber` bigint(20) unsigned DEFAULT NULL,
`fec` date DEFAULT NULL,
`hor` time DEFAULT NULL,
`now` timestamp NULL DEFAULT current_timestamp(),
`vn.VN_NOW` timestamp NULL DEFAULT current_timestamp(),
`ptj` mediumint(8) unsigned DEFAULT NULL,
`ref` int(11) NOT NULL,
`item` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
@ -10482,7 +10482,7 @@ proc:BEGIN
AND IF(t.package, l.package = e.package, TRUE)
AND IF(t.item, l.item = e.item, TRUE)
AND i.isFloramondo = vIsFloramondoDirect
ORDER BY l.now DESC, b.id ASC
ORDER BY l.vn.VN_NOW DESC, b.id ASC
LIMIT 1;
END IF;
@ -11071,7 +11071,7 @@ proc: BEGIN
AND it.isInventory
AND t.id IS NULL
AND po.id IS NULL;
-- select now(),'Antes de crear ITO';
-- select vn.VN_NOW(),'Antes de crear ITO';
DROP TEMPORARY TABLE IF EXISTS itemToInsert;
CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY
SELECT o.*, CAST(NULL AS DECIMAL(6,0)) as itemFk
@ -11562,7 +11562,7 @@ proc: BEGIN
AND it.isInventory
AND t.id IS NULL
AND po.id IS NULL;
-- select now(),'Antes de crear ITO';
-- select vn.VN_NOW(),'Antes de crear ITO';
DROP TEMPORARY TABLE IF EXISTS itemToInsert;
CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY
SELECT o.*, CAST(NULL AS DECIMAL(6,0)) as itemFk
@ -11963,7 +11963,7 @@ proc: BEGIN
-- GROUP BY Item_ArticleCode, s1, s2, s3, s4, s5, s6, company_name, Quality, NumberOfItemsPerCask, EmbalageCode, Price, PictureReference
;
-- select now(),'Antes de crear edi.offer';
-- select vn.VN_NOW(),'Antes de crear edi.offer';
DROP TEMPORARY TABLE IF EXISTS edi.offer;
CREATE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`),
@ -12042,7 +12042,7 @@ proc: BEGIN
AND it.isInventory
AND t.id IS NULL
AND po.id IS NULL;
-- select now(),'Antes de crear ITO';
-- select vn.VN_NOW(),'Antes de crear ITO';
DROP TEMPORARY TABLE IF EXISTS itemToInsert;
CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY
SELECT o.*, CAST(NULL AS DECIMAL(6,0)) as itemFk
@ -41421,6 +41421,89 @@ CREATE TABLE `ticketRecalc` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue of changed tickets to recalc its total';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `ticketRefund`
--
DROP TABLE IF EXISTS `ticketRefund`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ticketRefund` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`refundTicketFk` int(11) NOT NULL,
`originalTicketFk` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `ticketRefund_FK` (`refundTicketFk`),
KEY `ticketRefund_FK_1` (`originalTicketFk`),
CONSTRAINT `ticketRefund_FK` FOREIGN KEY (`refundTicketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE,
CONSTRAINT `ticketRefund_FK_1` FOREIGN KEY (`originalTicketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeInsert`
BEFORE INSERT ON `ticketRefund`
FOR EACH ROW
BEGIN
DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE;
IF NEW.refundTicketFk = NEW.originalTicketFk THEN
CALL util.throw('Original ticket and refund ticket has same id');
END IF;
SELECT COUNT(*) INTO vAlreadyExists
FROM ticketRefund
WHERE refundTicketFk = NEW.originalTicketFk;
IF vAlreadyExists > 0 THEN
CALL util.throw('This ticket is already a refund');
END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeUpdate`
BEFORE UPDATE ON `ticketRefund`
FOR EACH ROW
BEGIN
DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE;
IF NEW.refundTicketFk = NEW.originalTicketFk THEN
CALL util.throw('Original ticket and refund ticket has same id');
END IF;
SELECT COUNT(*) INTO vAlreadyExists
FROM ticketRefund
WHERE refundTicketFk = NEW.originalTicketFk;
IF vAlreadyExists > 0 THEN
CALL util.throw('This ticket is already a refund');
END IF;
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Table structure for table `ticketRequest`
--
@ -49321,7 +49404,7 @@ BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN DATE('2022-01-19');
ELSE
RETURN vn.VN_CURDATE();
RETURN CURDATE();
END IF;
END ;;
DELIMITER ;
@ -49343,9 +49426,9 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `VN_CURTIME`() RETURNS date
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIME('08:25:00');
RETURN TIME('00:00:00');
ELSE
RETURN vn.VN_CURTIME();
RETURN CURTIME();
END IF;
END ;;
DELIMITER ;
@ -49367,9 +49450,9 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `VN_NOW`() RETURNS date
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIMESTAMP('2022-01-19 08:25:00');
RETURN TIMESTAMP('2022-01-19 00:00:00');
ELSE
RETURN vn.VN_NOW();
RETURN NOW();
END IF;
END ;;
DELIMITER ;
@ -83951,7 +84034,10 @@ BEGIN
FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount;
END WHILE;
CLOSE vRsMainTicket;
CLOSE vRsMainTicket;
INSERT INTO vn.ticketRefund(refundTicketFk, originalTicketFk)
VALUES(vNewTicket, vOriginTicket);
END ;;
DELIMITER ;
@ -97845,4 +97931,4 @@ USE `vncontrol`;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-01-19 10:35:31
-- Dump completed on 2022-03-31 15:08:35

View File

@ -97,11 +97,11 @@ mysqldump \
${SCHEMAS[@]} \
${IGNORETABLES[@]} \
| sed 's/\bCURDATE\b/vn.VN_CURDATE/ig'\
| sed 's/\bCURTIME\b/vn.VN_CURTIME/g' \
| sed 's/\bNOW\b/vn.VN_NOW/g' \
| sed 's/\bCURRENT_DATE\b/vn.VN_CURDATE/g' \
| sed 's/\bCURRENT_TIME\b/vn.VN_CURTIME/g' \
| sed 's/\bLOCALTIME\b/vn.VN_NOW/g' \
| sed 's/\bLOCALTIMESTAMP\b/vn.VN_NOW/g' \
| sed 's/\bCURTIME\b/vn.VN_CURTIME/ig' \
| sed 's/\bNOW\b/vn.VN_NOW/ig' \
| sed 's/\bCURRENT_DATE\b/vn.VN_CURDATE/ig' \
| sed 's/\bCURRENT_TIME\b/vn.VN_CURTIME/ig' \
| sed 's/\bLOCALTIME\b/vn.VN_NOW/ig' \
| sed 's/\bLOCALTIMESTAMP\b/vn.VN_NOW/ig' \
| sed 's/ AUTO_INCREMENT=[0-9]* //g' \
> dump/structure.sql

View File

@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('buyUltimate()', () => {
const today = new Date('2022-01-19');
const today = new Date();
it(`should create buyUltimate temporal table and update it's values`, async() => {
let stmts = [];
let stmt;

View File

@ -5,7 +5,7 @@ describe('buyUltimateFromInterval()', () => {
let today;
let future;
beforeAll(() => {
let now = new Date('2022-01-19');
let now = new Date();
now.setHours(0, 0, 0, 0);
today = now;

View File

@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('ticket ticketCalculateClon()', () => {
const today = new Date('2022-01-19');
const today = new Date();
it('should add the ticket to the order containing the original ticket', async() => {
let stmts = [];
let stmt;

View File

@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('ticket ticketCreateWithUser()', () => {
const today = new Date('2022-01-19');
const today = new Date();
it('should confirm the procedure creates the expected ticket', async() => {
let stmts = [];
let stmt;

View File

@ -3,9 +3,9 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('timeBusiness_calculateByUser()', () => {
it('should return the expected hours for today', async() => {
let start = new Date('2022-01-19');
let start = new Date();
start.setHours(0, 0, 0, 0);
let end = new Date('2022-01-19');
let end = new Date();
end.setHours(0, 0, 0, 0);
let stmts = [];

View File

@ -3,11 +3,11 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('timeControl_calculateByUser()', () => {
it(`should return today's worked hours`, async() => {
let start = new Date('2022-01-19');
let start = new Date();
start.setHours(0, 0, 0, 0);
start.setDate(start.getDate() - 1);
let end = new Date('2022-01-19');
let end = new Date();
end.setHours(0, 0, 0, 0);
end.setDate(end.getDate() + 1);
@ -48,14 +48,14 @@ describe('timeControl_calculateByUser()', () => {
});
it(`should return the worked hours between last sunday and monday`, async() => {
let lastSunday = new Date('2022-01-19');
let lastSunday = new Date();
let daysSinceSunday = lastSunday.getDay();
if (daysSinceSunday === 0) // this means today is sunday but you need the previous sunday :)
daysSinceSunday = 7;
lastSunday.setHours(23, 0, 0, 0);
lastSunday.setDate(lastSunday.getDate() - daysSinceSunday);
let monday = new Date('2022-01-19');
let monday = new Date();
let daysSinceMonday = daysSinceSunday - 1; // aiming for monday (today could be monday)
monday.setHours(7, 0, 0, 0);
monday.setDate(monday.getDate() - daysSinceMonday);

View File

@ -4,7 +4,7 @@ import getBrowser from '../../helpers/puppeteer';
describe('Client credit insurance path', () => {
let browser;
let page;
let previousMonth = new Date('2022-01-19');
let previousMonth = new Date();
previousMonth.setMonth(previousMonth.getMonth() - 1);
beforeAll(async() => {

View File

@ -120,7 +120,7 @@ describe('Worker calendar path', () => {
});
it('should use the year selector to go to the previous year', async() => {
const date = new Date('2022-01-19');
const date = new Date();
const lastYear = (date.getFullYear() - 1).toString();
await page.autocompleteSearch(selectors.workerCalendar.year, lastYear);

View File

@ -22,7 +22,7 @@ describe('Item fixed prices path', () => {
});
it('should fill the fixed price data', async() => {
const now = new Date('2022-01-19');
const now = new Date();
await page.autocompleteSearch(selectors.itemFixedPrice.fourthWarehouse, 'Warehouse one');
await page.write(selectors.itemFixedPrice.fourthPPU, '1');
await page.write(selectors.itemFixedPrice.fourthPPP, '1');

View File

@ -93,7 +93,7 @@ describe('Ticket Edit basic data path', () => {
it(`should split ticket without negatives`, async() => {
const newAgency = 'Silla247';
const newDate = new Date('2022-01-19');
const newDate = new Date();
newDate.setDate(newDate.getDate() - 1);
await page.accessToSearchResult('14');
@ -128,7 +128,7 @@ describe('Ticket Edit basic data path', () => {
});
it(`should old ticket have old date and agency`, async() => {
const oldDate = new Date('2022-01-19');
const oldDate = new Date();
const oldAgency = 'Super-Man delivery';
await page.accessToSearchResult('14');

View File

@ -4,7 +4,7 @@ import getBrowser from '../../helpers/puppeteer';
describe('Ticket create path', () => {
let browser;
let page;
let nextMonth = new Date('2022-01-19');
let nextMonth = new Date();
nextMonth.setMonth(nextMonth.getMonth() + 1);
let stowawayTicketId;

View File

@ -18,7 +18,7 @@ describe('Route basic Data path', () => {
});
it('should edit the route basic data', async() => {
const nextMonth = new Date('2022-01-19');
const nextMonth = new Date();
nextMonth.setMonth(nextMonth.getMonth() + 1);
await page.autocompleteSearch(selectors.routeBasicData.worker, 'adminBossNick');

View File

@ -18,7 +18,7 @@ describe('InvoiceIn basic data path', () => {
});
it(`should edit the invoiceIn basic data`, async() => {
const now = new Date('2022-01-19');
const now = new Date();
await page.pickDate(selectors.invoiceInBasicData.issued, now);
await page.pickDate(selectors.invoiceInBasicData.operated, now);
await page.autocompleteSearch(selectors.invoiceInBasicData.supplier, 'Verdnatura');

View File

@ -100,7 +100,7 @@ describe('InvoiceOut descriptor path', () => {
});
it(`should check the invoiceOut booked in the summary data`, async() => {
let today = new Date('2022-01-19');
let today = new Date();
let day = today.getDate();
if (day < 10) day = `0${day}`;

View File

@ -4,7 +4,7 @@ import getBrowser from '../../helpers/puppeteer';
describe('Travel create path', () => {
let browser;
let page;
const date = new Date('2022-01-19');
const date = new Date();
const day = 15;
date.setDate(day);

View File

@ -22,7 +22,7 @@ describe('Travel basic data path', () => {
});
it('should set a wrong delivery date then receive an error on submit', async() => {
const lastMonth = new Date('2022-01-19');
const lastMonth = new Date();
lastMonth.setMonth(lastMonth.getMonth() - 1);
await page.pickDate(selectors.travelBasicData.deliveryDate, lastMonth);

View File

@ -123,7 +123,7 @@ describe('Travel descriptor path', () => {
});
it('should update the landed date to a future date to enable cloneWithEntries', async() => {
const nextMonth = new Date('2022-01-19');
const nextMonth = new Date();
nextMonth.setMonth(nextMonth.getMonth() + 1);
await page.pickDate(selectors.travelBasicData.deliveryDate, nextMonth);
await page.waitToClick(selectors.travelBasicData.save);

View File

@ -2,7 +2,7 @@ describe('Component vnCalendar', () => {
let controller;
let $element;
let date = new Date('2022-01-19');
let date = new Date();
date.setHours(0, 0, 0, 0);
date.setDate(1);
@ -48,7 +48,7 @@ describe('Component vnCalendar', () => {
it(`should return the selected element, then emit a 'selection' event`, () => {
jest.spyOn(controller, 'emit');
const day = new Date('2022-01-19');
const day = new Date();
day.setHours(0, 0, 0, 0);
const clickEvent = new Event('click');

View File

@ -4,7 +4,7 @@ describe('Component vnDatePicker', () => {
let $ctrl;
let today;
today = new Date('2022-01-19');
today = new Date();
today.setHours(0, 0, 0, 0);
beforeEach(ngModule('vnCore'));

View File

@ -20,7 +20,7 @@ describe('Component vnInputTime', () => {
describe('field() setter', () => {
it(`should display the formated the date`, () => {
let date = new Date('2022-01-19');
let date = new Date();
$ctrl.field = date;
let displayed = $filter('date')(date, 'HH:mm');

View File

@ -108,6 +108,7 @@ async function launchBackTest(done) {
}
let backSpecFiles = [
'back/helpers.spec.js',
'back/**/*.spec.js',
'loopback/**/*.spec.js',
'modules/*/back/**/*.spec.js'

View File

@ -54,7 +54,7 @@ describe('Claim createFromSales()', () => {
try {
const options = {transaction: tx};
const todayMinusEightDays = new Date('2022-01-19');
const todayMinusEightDays = new Date();
todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8);
const ticket = await models.Ticket.findById(ticketId, null, options);
@ -85,7 +85,7 @@ describe('Claim createFromSales()', () => {
try {
const options = {transaction: tx};
const todayMinusEightDays = new Date('2022-01-19');
const todayMinusEightDays = new Date();
todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8);
const ticket = await models.Ticket.findById(ticketId, null, options);

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
describe('Update Claim', () => {
const newDate = new Date('2022-01-19');
const newDate = new Date();
const originalData = {
ticketFk: 3,
clientFk: 1101,

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
describe('Update Claim', () => {
const newDate = new Date('2022-01-19');
const newDate = new Date();
const original = {
ticketFk: 3,
clientFk: 1101,

View File

@ -92,7 +92,7 @@ module.exports = function(Self) {
throw new UserError('Invalid account');
await Self.rawSql(
`CALL vn.ledger_doCompensation(CURDATE(), ?, ?, ?, ?, ?, ?)`,
`CALL vn.ledger_doCompensation(vn.VN_CURDATE(), ?, ?, ?, ?, ?, ?)`,
[
args.compensationAccount,
args.bankFk,
@ -106,7 +106,7 @@ module.exports = function(Self) {
} else if (accountingType.isAutoConciliated == true) {
const description = `${originalClient.id} : ${originalClient.socialName} - ${accountingType.receiptDescription}`;
const [xdiarioNew] = await Self.rawSql(
`SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
`SELECT xdiario_new(?, vn.VN_CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
[
null,
bank.account,
@ -126,7 +126,7 @@ module.exports = function(Self) {
);
await Self.rawSql(
`SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
`SELECT xdiario_new(?, vn.VN_CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
[
xdiarioNew.ledger,
originalClient.accountingAccount,

View File

@ -74,7 +74,7 @@ module.exports = function(Self) {
]
}, myOptions);
const query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
const query = `SELECT vn.clientGetDebt(?, vn.VN_CURDATE()) AS debt`;
const data = await Self.rawSql(query, [id], myOptions);
client.debt = data[0].debt;

View File

@ -25,7 +25,7 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
const query = `SELECT vn.clientGetDebt(?, vn.VN_CURDATE()) AS debt`;
const [debt] = await Self.rawSql(query, [clientFk], myOptions);
return debt;

View File

@ -50,7 +50,7 @@ module.exports = Self => {
JOIN vn.warehouse w ON t.warehouseFk = w.id
JOIN vn.address ad ON t.addressFk = ad.id
JOIN vn.province pr ON ad.provinceFk = pr.id
WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0
WHERE t.shipped >= vn.VN_CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0
AND t.id <> ? AND t.warehouseFk = ?
ORDER BY t.shipped
LIMIT 10`;

View File

@ -27,7 +27,7 @@ describe('Client updatePortfolio', () => {
}
});
it('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => {
xit('should keep the same portfolioWeight when a salesperson is unassigned of a client', async() => {
const salesPersonId = 19;
const tx = await models.Client.beginTransaction({});

View File

@ -122,11 +122,11 @@ module.exports = Self => {
return clientModel.findOne(filter, options);
}
async function getRecoveries(recoveryModel, clientId, options) {
const today = new Date();
const filter = {
where: {
and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}]
and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: today.getTime()}}]}]
},
limit: 1
};

View File

@ -72,7 +72,7 @@ module.exports = Self => {
LEFT JOIN account.user u ON u.id = c.salesPersonFk
LEFT JOIN account.user uw ON uw.id = co.workerFk
WHERE
d.created = CURDATE()
d.created = vn.VN_CURDATE()
AND d.amount > 0
ORDER BY co.created DESC) d`
);

View File

@ -31,7 +31,7 @@ module.exports = Self => {
SELECT count(*) AS hasActiveRecovery
FROM vn.recovery
WHERE clientFk = ?
AND IFNULL(finished,CURDATE()) >= CURDATE();
AND IFNULL(finished,vn.VN_CURDATE()) >= vn.VN_CURDATE();
`;
const [result] = await Self.rawSql(query, [id], myOptions);

View File

@ -26,7 +26,7 @@ describe('Client', () => {
it('should call the window.open function', () => {
jest.spyOn(window, 'open').mockReturnThis();
const now = new Date('2022-01-19');
const now = new Date();
controller.$.model.userParams = {
from: now,
to: now
@ -48,7 +48,7 @@ describe('Client', () => {
describe('sendEmail()', () => {
it('should make a GET query sending the report', () => {
const now = new Date('2022-01-19');
const now = new Date();
controller.$.model.userParams = {
from: now,
to: now

View File

@ -24,7 +24,7 @@ describe('Client', () => {
describe('onSubmit()', () => {
it('should perform a POST query', () => {
let started = new Date('2022-01-19');
let started = new Date();
controller.creditClassification = {
started: started,
credit: 300,

View File

@ -49,14 +49,14 @@ describe('client defaulter', () => {
describe('chipColor()', () => {
it('should return undefined when the date is the present', () => {
let today = new Date('2022-01-19');
let today = new Date();
let result = controller.chipColor(today);
expect(result).toEqual(undefined);
});
it('should return warning when the date is 10 days in the past', () => {
let pastDate = new Date('2022-01-19');
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 11);
let result = controller.chipColor(pastDate);
@ -64,7 +64,7 @@ describe('client defaulter', () => {
});
it('should return alert when the date is 20 days in the past', () => {
let pastDate = new Date('2022-01-19');
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 21);
let result = controller.chipColor(pastDate);

View File

@ -39,7 +39,7 @@ describe('Client notification', () => {
describe('campaignSelection() setter', () => {
it('should set the campaign from and to properties', () => {
const dated = new Date('2022-01-19');
const dated = new Date();
controller.campaignSelection = {
dated: dated,
scopeDays: 14
@ -62,8 +62,8 @@ describe('Client notification', () => {
controller.$.filters = {hide: () => {}};
controller.campaign = {
id: 1,
from: new Date('2022-01-19'),
to: new Date('2022-01-19')
from: new Date(),
to: new Date()
};
const data = controller.$.model.data;

View File

@ -76,14 +76,14 @@ describe('Client', () => {
describe('chipColor()', () => {
it('should return warning when the date is the present', () => {
let today = new Date('2022-01-19');
let today = new Date();
let result = controller.chipColor(today);
expect(result).toEqual('warning');
});
it('should return success when the date is in the future', () => {
let futureDate = new Date('2022-01-19');
let futureDate = new Date();
futureDate = futureDate.setDate(futureDate.getDate() + 10);
let result = controller.chipColor(futureDate);
@ -91,7 +91,7 @@ describe('Client', () => {
});
it('should return undefined when the date is in the past', () => {
let pastDate = new Date('2022-01-19');
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 10);
let result = controller.chipColor(pastDate);

View File

@ -202,7 +202,7 @@ module.exports = Self => {
LEFT JOIN itemType t ON t.id = i.typeFk
LEFT JOIN intrastat intr ON intr.id = i.intrastatFk
LEFT JOIN origin ori ON ori.id = i.originFk
LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(CURDATE(),INTERVAL 1 YEAR)
LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(vn.VN_CURDATE(),INTERVAL 1 YEAR)
LEFT JOIN supplier s ON s.id = e.supplierFk`
);

View File

@ -318,10 +318,10 @@ describe('Entry latests buys filter()', () => {
const options = {transaction: tx};
try {
const from = new Date('2022-01-19');
const from = new Date();
from.setHours(0, 0, 0, 0);
const to = new Date('2022-01-19');
const to = new Date();
to.setHours(23, 59, 59, 999);
const ctx = {

View File

@ -146,8 +146,8 @@ describe('InvoiceIn filter()', () => {
const options = {transaction: tx};
try {
const from = new Date('2022-01-19');
const to = new Date('2022-01-19');
const from = new Date();
const to = new Date();
from.setHours(0, 0, 0, 0);
to.setHours(23, 59, 59, 999);
to.setDate(to.getDate() + 1);

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('InvoiceOut filter()', () => {
let today = new Date('2022-01-19');
let today = new Date();
today.setHours(2, 0, 0, 0);
it('should return the invoice out matching ref', async() => {

View File

@ -19,8 +19,8 @@ describe('InvoiceOut globalInvoicing()', () => {
try {
ctx.args = {
invoiceDate: new Date('2022-01-19'),
maxShipped: new Date('2022-01-19'),
invoiceDate: new Date(),
maxShipped: new Date(),
fromClientId: clientId,
toClientId: clientId,
companyFk: companyFk

View File

@ -73,8 +73,8 @@ describe('InvoiceOut', () => {
jest.spyOn(controller.vnApp, 'showError');
controller.invoice = {
invoiceDate: new Date('2022-01-19'),
maxShipped: new Date('2022-01-19')
invoiceDate: new Date(),
maxShipped: new Date()
};
controller.responseHandler('accept');
@ -86,8 +86,8 @@ describe('InvoiceOut', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
controller.invoice = {
invoiceDate: new Date('2022-01-19'),
maxShipped: new Date('2022-01-19'),
invoiceDate: new Date(),
maxShipped: new Date(),
fromClientId: 1101,
toClientId: 1101
};

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('upsertFixedPrice()', () => {
const now = new Date('2022-01-19');
const now = new Date();
const fixedPriceId = 1;
let originalFixedPrice;

View File

@ -42,8 +42,8 @@ module.exports = Self => {
sum(ws.saleWaste) AS dwindle
FROM bs.waste ws
WHERE buyer = ? AND family = ?
AND year = YEAR(TIMESTAMPADD(WEEK,-1,CURDATE()))
AND week = WEEK(TIMESTAMPADD(WEEK,-1,CURDATE()), 1)
AND year = YEAR(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()))
AND week = WEEK(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()), 1)
GROUP BY buyer, itemFk
) sub
ORDER BY family, percentage DESC`, [buyer, family], myOptions);

View File

@ -27,8 +27,8 @@ module.exports = Self => {
sum(ws.saleTotal) AS total,
sum(ws.saleWaste) AS dwindle
FROM bs.waste ws
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1,CURDATE()))
AND week = WEEK(TIMESTAMPADD(WEEK,-1,CURDATE()), 1)
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()))
AND week = WEEK(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()), 1)
GROUP BY buyer, family
) sub
ORDER BY percentage DESC`, null, myOptions);

View File

@ -8,7 +8,7 @@ describe('item getVisibleAvailable()', () => {
try {
const itemFk = 1;
const warehouseFk = 1;
const dated = new Date('2022-01-19');
const dated = new Date();
const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options);
@ -29,7 +29,7 @@ describe('item getVisibleAvailable()', () => {
try {
const itemFk = 1;
const warehouseFk = 1;
const dated = new Date('2022-01-19');
const dated = new Date();
dated.setDate(dated.getDate() - 1);
const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options);

View File

@ -24,7 +24,7 @@ describe('fixed price', () => {
});
it('should perform an http request to update the price', () => {
const now = new Date('2022-01-19');
const now = new Date();
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPATCH('FixedPrices/upsertFixedPrice').respond();

View File

@ -15,7 +15,7 @@ describe(' Component vnRequestSearchPanel', () => {
it('should clear the scope days when setting the from property', () => {
controller.filter.scopeDays = 1;
controller.from = new Date('2022-01-19');
controller.from = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.from).toBeDefined();
@ -26,7 +26,7 @@ describe(' Component vnRequestSearchPanel', () => {
it('should clear the scope days when setting the to property', () => {
controller.filter.scopeDays = 1;
controller.to = new Date('2022-01-19');
controller.to = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.to).toBeDefined();
@ -35,8 +35,8 @@ describe(' Component vnRequestSearchPanel', () => {
describe('scopeDays() setter', () => {
it('should clear the date range when setting the scopeDays property', () => {
controller.filter.from = new Date('2022-01-19');
controller.filter.to = new Date('2022-01-19');
controller.filter.from = new Date();
controller.filter.to = new Date();
controller.scopeDays = 1;

View File

@ -93,7 +93,7 @@ describe('Item', () => {
});
it(`should return "warning" if date is today`, () => {
let date = new Date('2022-01-19');
let date = new Date();
let result = controller.compareDate(date);
expect(result).toEqual('warning');

View File

@ -49,7 +49,7 @@ module.exports = Self => {
LEFT JOIN account.user u ON c.salesPersonFk = u.id
LEFT JOIN worker w ON c.salesPersonFk = w.id
LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk
AND CURDATE() BETWEEN sc.started AND sc.ended
AND vn.VN_CURDATE() BETWEEN sc.started AND sc.ended
LEFT JOIN workerTeamCollegues wtc
ON wtc.collegueFk = IFNULL(sc.workerSubstitute, c.salesPersonFk)`);

View File

@ -272,7 +272,7 @@ module.exports = Self => {
FROM tmp.filter f
LEFT JOIN alertLevel al ON al.id = f.alertLevel
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
AND f.shipped >= CURDATE()`);
AND f.shipped >= vn.VN_CURDATE()`);
stmts.push('CALL ticket_getProblems(FALSE)');
stmts.push(`

View File

@ -26,9 +26,9 @@ describe('SalesMonitor salesFilter()', () => {
try {
const options = {transaction: tx};
const yesterday = new Date('2022-01-19');
const yesterday = new Date();
yesterday.setHours(0, 0, 0, 0);
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(23, 59, 59, 59);
const ctx = {req: {accessToken: {userId: 9}}, args: {
@ -54,10 +54,10 @@ describe('SalesMonitor salesFilter()', () => {
try {
const options = {transaction: tx};
const yesterday = new Date('2022-01-19');
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(23, 59, 59, 59);
const ctx = {req: {accessToken: {userId: 9}}, args: {
@ -209,10 +209,10 @@ describe('SalesMonitor salesFilter()', () => {
try {
const options = {transaction: tx};
const yesterday = new Date('2022-01-19');
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(23, 59, 59, 59);
const ctx = {req: {accessToken: {userId: 18}}, args: {}};
@ -238,10 +238,10 @@ describe('SalesMonitor salesFilter()', () => {
try {
const options = {transaction: tx};
const yesterday = new Date('2022-01-19');
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(23, 59, 59, 59);
const ctx = {req: {accessToken: {userId: 18}}, args: {}};

View File

@ -38,7 +38,7 @@ describe('Monitor Component vnMonitorSalesSearchPanel', () => {
it('should clear the scope days when setting the from property', () => {
controller.filter.scopeDays = 1;
controller.from = new Date('2022-01-19');
controller.from = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.from).toBeDefined();
@ -49,7 +49,7 @@ describe('Monitor Component vnMonitorSalesSearchPanel', () => {
it('should clear the scope days when setting the to property', () => {
controller.filter.scopeDays = 1;
controller.to = new Date('2022-01-19');
controller.to = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.to).toBeDefined();
@ -58,8 +58,8 @@ describe('Monitor Component vnMonitorSalesSearchPanel', () => {
describe('scopeDays() setter', () => {
it('should clear the date range when setting the scopeDays property', () => {
controller.filter.from = new Date('2022-01-19');
controller.filter.to = new Date('2022-01-19');
controller.filter.from = new Date();
controller.filter.to = new Date();
controller.scopeDays = 1;

View File

@ -32,7 +32,7 @@ describe('Component vnMonitorSalesTickets', () => {
let params = controller.fetchParams({
scopeDays: 2
});
const from = new Date('2022-01-19');
const from = new Date();
from.setHours(0, 0, 0, 0);
const to = new Date(from.getTime());
to.setDate(to.getDate() + params.scopeDays);
@ -66,14 +66,14 @@ describe('Component vnMonitorSalesTickets', () => {
describe('compareDate()', () => {
it('should return warning when the date is the present', () => {
let today = new Date('2022-01-19');
let today = new Date();
let result = controller.compareDate(today);
expect(result).toEqual('warning');
});
it('should return sucess when the date is in the future', () => {
let futureDate = new Date('2022-01-19');
let futureDate = new Date();
futureDate = futureDate.setDate(futureDate.getDate() + 10);
let result = controller.compareDate(futureDate);
@ -81,7 +81,7 @@ describe('Component vnMonitorSalesTickets', () => {
});
it('should return undefined when the date is in the past', () => {
let pastDate = new Date('2022-01-19');
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 10);
let result = controller.compareDate(pastDate);
@ -99,7 +99,7 @@ describe('Component vnMonitorSalesTickets', () => {
describe('dateRange()', () => {
it('should return two dates with the hours at the start and end of the given date', () => {
const now = new Date('2022-01-19');
const now = new Date();
const today = now.getDate();

View File

@ -9,7 +9,7 @@ describe('order new()', () => {
try {
const options = {transaction: tx};
const landed = new Date('2022-01-19');
const landed = new Date();
const addressFk = 6;
const agencyModeFk = 1;
@ -30,7 +30,7 @@ describe('order new()', () => {
try {
const options = {transaction: tx};
const landed = new Date('2022-01-19');
const landed = new Date();
const addressFk = 121;
const agencyModeFk = 1;

View File

@ -46,7 +46,7 @@ describe('Order', () => {
it('should set agencyModeFk to null and get the available agencies if the order has landed and client', async() => {
controller.order.agencyModeFk = 999;
controller.order.addressFk = 999;
controller.order.landed = new Date('2022-01-19');
controller.order.landed = new Date();
const expectedAgencies = [{id: 1}, {id: 2}];

View File

@ -26,14 +26,14 @@ describe('Component vnOrderIndex', () => {
describe('compareDate()', () => {
it('should return warning when the date is the present', () => {
let curDate = new Date('2022-01-19');
let curDate = new Date();
let result = controller.compareDate(curDate);
expect(result).toEqual('warning');
});
it('should return sucess when the date is in the future', () => {
let futureDate = new Date('2022-01-19');
let futureDate = new Date();
futureDate = futureDate.setDate(futureDate.getDate() + 10);
let result = controller.compareDate(futureDate);
@ -41,7 +41,7 @@ describe('Component vnOrderIndex', () => {
});
it('should return undefined when the date is in the past', () => {
let pastDate = new Date('2022-01-19');
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 10);
let result = controller.compareDate(pastDate);

View File

@ -101,7 +101,7 @@ module.exports = Self => {
LEFT JOIN vn.ticket t ON t.routeFk = r.id
LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id
LEFT JOIN vn.supplier s ON s.id = sat.supplierFk
WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL
WHERE r.created > DATE_ADD(vn.VN_CURDATE(), INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL
GROUP BY r.id
) a`
);

View File

@ -3,7 +3,7 @@ const models = require('vn-loopback/server/server').models;
describe('AgencyTerm filter()', () => {
const authUserId = 9;
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(2, 0, 0, 0);
it('should return all results matching the filter', async() => {
@ -57,10 +57,10 @@ describe('AgencyTerm filter()', () => {
const options = {transaction: tx};
try {
const from = new Date('2022-01-19');
const from = new Date();
from.setHours(0, 0, 0, 0);
const to = new Date('2022-01-19');
const to = new Date();
to.setHours(23, 59, 59, 999);
const ctx = {

View File

@ -73,7 +73,7 @@ module.exports = Self => {
},
]
}, myOptions);
console.log(tickets);
return tickets;
};
};

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
describe('route clone()', () => {
const createdDate = new Date('2022-01-19');
const createdDate = new Date();
it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => {
const ids = [996, 997, 998, 999];

View File

@ -2,17 +2,17 @@ const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('Route filter()', () => {
let today = new Date('2022-01-19');
const today = new Date();
today.setHours(2, 0, 0, 0);
it('should return the routes matching "search"', async() => {
let ctx = {
const ctx = {
args: {
search: 1,
}
};
let result = await app.models.Route.filter(ctx);
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1);
@ -23,12 +23,11 @@ describe('Route filter()', () => {
const options = {transaction: tx};
try {
const from = new Date('2022-01-19');
const from = new Date();
from.setHours(0, 0, 0, 0);
const to = new Date('2022-01-19');
const to = new Date();
to.setHours(23, 59, 59, 999);
const ctx = {
args: {
from: from,
@ -48,43 +47,43 @@ describe('Route filter()', () => {
});
it('should return the routes matching "m3"', async() => {
let ctx = {
const ctx = {
args: {
m3: 0.1,
}
};
let result = await app.models.Route.filter(ctx);
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
});
it('should return the routes matching "description"', async() => {
let ctx = {
const ctx = {
args: {
description: 'third route',
}
};
let result = await app.models.Route.filter(ctx);
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
});
it('should return the routes matching "workerFk"', async() => {
let ctx = {
const ctx = {
args: {
workerFk: 56,
}
};
let result = await app.models.Route.filter(ctx);
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(5);
});
it('should return the routes matching "warehouseFk"', async() => {
let ctx = {
const ctx = {
args: {
warehouseFk: 1,
}
@ -102,25 +101,25 @@ describe('Route filter()', () => {
});
it('should return the routes matching "vehicleFk"', async() => {
let ctx = {
const ctx = {
args: {
vehicleFk: 2,
}
};
let result = await app.models.Route.filter(ctx);
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
});
it('should return the routes matching "agencyModeFk"', async() => {
let ctx = {
const ctx = {
args: {
agencyModeFk: 7,
}
};
let result = await app.models.Route.filter(ctx);
const result = await app.models.Route.filter(ctx);
expect(result.length).toEqual(1);
});

View File

@ -4,11 +4,22 @@ const LoopBackContext = require('loopback-context');
describe('route getSuggestedTickets()', () => {
const routeID = 1;
const ticketId = 12;
beforeAll(() => {
jasmine.clock().uninstall();
});
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
jasmine.clock().mockDate(baseTime);
});
it('should return an array of suggested tickets', async() => {
const activeCtx = {
accessToken: {userId: 19},
headers: {origin: 'http://localhost'}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
@ -21,7 +32,7 @@ describe('route getSuggestedTickets()', () => {
await ticketInRoute.updateAttributes({
routeFk: null,
landed: new Date('2022-01-19')
landed: new Date()
}, options);
const result = await app.models.Route.getSuggestedTickets(routeID, options);

View File

@ -8,10 +8,17 @@ describe('route insertTicket()', () => {
accessToken: {userId: deliveryId},
};
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
jasmine.clock().mockDate(baseTime);
});
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
jasmine.clock().uninstall();
});
it('should add the ticket to a route', async() => {
@ -23,7 +30,7 @@ describe('route insertTicket()', () => {
const ticketInRoute = await app.models.Ticket.findById(ticketId, null, options);
await ticketInRoute.updateAttributes({
routeFk: null,
landed: new Date('2022-01-19')
landed: new Date()
}, options);
const result = await app.models.Route.insertTicket(routeId, ticketId, options);

View File

@ -1,6 +1,16 @@
const models = require('vn-loopback/server/server').models;
describe('route unlink()', () => {
beforeAll(() => {
jasmine.clock().uninstall();
});
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
jasmine.clock().mockDate(baseTime);
});
it('should show no tickets since the link between zone and route for the give agencymode was removed', async() => {
const tx = await models.ZoneAgencyMode.beginTransaction({});
const agencyModeId = 1;

View File

@ -62,7 +62,7 @@ describe('Component vnRouteIndex', () => {
describe('cloneSelectedRoutes()', () => {
it('should perform an http request to Routes/clone', () => {
controller.createdDate = new Date('2022-01-19');
controller.createdDate = new Date();
$httpBackend.expect('POST', 'Routes/clone').respond();
controller.cloneSelectedRoutes();

View File

@ -15,7 +15,7 @@ describe('Route Component vnRoute', () => {
let params = controller.fetchParams({
scopeDays: 2
});
const from = new Date('2022-01-19');
const from = new Date();
from.setHours(0, 0, 0, 0);
const to = new Date(from.getTime());
to.setDate(to.getDate() + params.scopeDays);

View File

@ -15,7 +15,7 @@ describe('Route Component vnRouteSearchPanel', () => {
it('should clear the scope days when setting the from property', () => {
controller.filter.scopeDays = 1;
controller.from = new Date('2022-01-19');
controller.from = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.from).toBeDefined();
@ -26,7 +26,7 @@ describe('Route Component vnRouteSearchPanel', () => {
it('should clear the scope days when setting the to property', () => {
controller.filter.scopeDays = 1;
controller.to = new Date('2022-01-19');
controller.to = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.to).toBeDefined();
@ -35,8 +35,8 @@ describe('Route Component vnRouteSearchPanel', () => {
describe('scopeDays() setter', () => {
it('should clear the date range when setting the scopeDays property', () => {
controller.filter.from = new Date('2022-01-19');
controller.filter.to = new Date('2022-01-19');
controller.filter.from = new Date();
controller.filter.to = new Date();
controller.scopeDays = 1;

View File

@ -28,7 +28,7 @@ describe('Supplier', () => {
it('should call the window.open function', () => {
jest.spyOn(window, 'open').mockReturnThis();
const now = new Date('2022-01-19');
const now = new Date();
controller.$.model.userParams = {
from: now,
to: now
@ -85,7 +85,7 @@ describe('Supplier', () => {
{id: 1, email: 'batman@gothamcity.com'}
]);
const now = new Date('2022-01-19');
const now = new Date();
controller.$.model.userParams = {
from: now,
to: now

View File

@ -39,7 +39,7 @@ module.exports = Self => {
INNER JOIN vn.sale s ON s.ticketFk = t.id
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, CURDATE())
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, vn.VN_CURDATE())
AND t.id = ? AND cb.id IS NULL
ORDER BY t.landed DESC, t.id DESC`;

View File

@ -9,7 +9,7 @@ describe('ticket changeState()', () => {
accessToken: {userId: 9},
};
const ctx = {req: activeCtx};
const now = new Date('2022-01-19');
const now = new Date();
const sampleTicket = {
shipped: now,
landed: now,

View File

@ -305,7 +305,7 @@ module.exports = Self => {
FROM tmp.filter f
LEFT JOIN alertLevel al ON al.id = f.alertLevel
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
AND f.shipped >= CURDATE()`);
AND f.shipped >= vn.VN_CURDATE()`);
stmts.push('CALL ticket_getProblems(FALSE)');
stmt = new ParameterizedSQL(`

View File

@ -81,7 +81,7 @@ module.exports = function(Self) {
WHERE id IN(?) AND refFk IS NULL
`, [ticketsIds], myOptions);
await Self.rawSql('CALL invoiceOut_new(?, CURDATE(), null, @invoiceId)', [serial], myOptions);
await Self.rawSql('CALL invoiceOut_new(?, vn.VN_CURDATE(), null, @invoiceId)', [serial], myOptions);
const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], myOptions);

View File

@ -56,13 +56,12 @@ describe('ticket canBeInvoiced()', () => {
it('should return falsy for a ticket shipping in future', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const ticket = await models.Ticket.findById(ticketId, null, options);
const shipped = new Date('2022-01-19');
const shipped = new Date();
shipped.setDate(shipped.getDate() + 1);
await ticket.updateAttribute('shipped', shipped, options);

View File

@ -3,8 +3,8 @@ const models = require('vn-loopback/server/server').models;
describe('ticket componentUpdate()', () => {
const userID = 1101;
const ticketID = 11;
const today = new Date('2022-01-19');
const tomorrow = new Date('2022-01-19');
const today = new Date();
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

View File

@ -26,9 +26,9 @@ describe('ticket filter()', () => {
try {
const options = {transaction: tx};
const yesterday = new Date('2022-01-19');
const yesterday = new Date();
yesterday.setHours(0, 0, 0, 0);
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(23, 59, 59, 59);
const ctx = {req: {accessToken: {userId: 9}}, args: {
@ -54,10 +54,10 @@ describe('ticket filter()', () => {
try {
const options = {transaction: tx};
const yesterday = new Date('2022-01-19');
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
const today = new Date('2022-01-19');
const today = new Date();
today.setHours(23, 59, 59, 59);
const ctx = {req: {accessToken: {userId: 9}}, args: {

View File

@ -2,6 +2,16 @@ const models = require('vn-loopback/server/server').models;
let UserError = require('vn-loopback/util/user-error');
describe('ticket getPossibleStowaways()', () => {
beforeAll(() => {
jasmine.clock().uninstall();
});
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
jasmine.clock().mockDate(baseTime);
});
it(`should throw an error if Can't create stowaway for this ticket`, async() => {
const tx = await models.Ticket.beginTransaction({});

View File

@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models;
let UserError = require('vn-loopback/util/user-error');
describe('ticket new()', () => {
const today = new Date('2022-01-19');
const today = new Date();
const ctx = {req: {accessToken: {userId: 1}}};
it('should throw an error if the client isnt frozen and isnt active', async() => {

View File

@ -8,7 +8,7 @@ describe('sale priceDifference()', () => {
try {
const options = {transaction: tx};
const tomorrow = new Date('2022-01-19');
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const ctx = {req: {accessToken: {userId: 1106}}};
@ -45,8 +45,8 @@ describe('sale priceDifference()', () => {
const ctx = {req: {accessToken: {userId: 1106}}};
ctx.args = {
id: 1,
landed: new Date('2022-01-19'),
shipped: new Date('2022-01-19'),
landed: new Date(),
shipped: new Date(),
addressId: 121,
zoneId: 3,
warehouseId: 1
@ -68,7 +68,7 @@ describe('sale priceDifference()', () => {
try {
const options = {transaction: tx};
const tomorrow = new Date('2022-01-19');
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const ctx = {req: {accessToken: {userId: 1106}}};

View File

@ -24,7 +24,7 @@ describe('ticket restore()', () => {
let error;
const tx = await app.models.Ticket.beginTransaction({});
const now = new Date('2022-01-19');
const now = new Date();
now.setHours(now.getHours() - 1);
try {
@ -46,7 +46,7 @@ describe('ticket restore()', () => {
it('should restore the ticket making its state no longer deleted', async() => {
const tx = await app.models.Ticket.beginTransaction({});
const now = new Date('2022-01-19');
const now = new Date();
try {
const options = {transaction: tx};

View File

@ -67,7 +67,7 @@ describe('Ticket', () => {
jest.spyOn(controller, 'getShipped');
controller.ticket.addressFk = 99;
controller.addressId = 100;
const landed = new Date('2022-01-19');
const landed = new Date();
const expectedResult = {
landed: landed,
addressFk: 100,
@ -101,7 +101,7 @@ describe('Ticket', () => {
describe('shipped() getter', () => {
it('should return the shipped property', () => {
const shipped = new Date('2022-01-19');
const shipped = new Date();
controller.ticket.shipped = shipped;
expect(controller.shipped).toEqual(shipped);
@ -111,7 +111,7 @@ describe('Ticket', () => {
describe('shipped() setter', () => {
it('should set shipped property and call getLanded() method ', () => {
jest.spyOn(controller, 'getLanded');
const shipped = new Date('2022-01-19');
const shipped = new Date();
const expectedResult = {
shipped: shipped,
addressFk: 121,
@ -126,7 +126,7 @@ describe('Ticket', () => {
describe('landed() getter', () => {
it('should return the landed property', () => {
const landed = new Date('2022-01-19');
const landed = new Date();
controller.ticket.landed = landed;
expect(controller.landed).toEqual(landed);
@ -136,7 +136,7 @@ describe('Ticket', () => {
describe('landed() setter', () => {
it('should set shipped property and call getShipped() method ', () => {
jest.spyOn(controller, 'getShipped');
const landed = new Date('2022-01-19');
const landed = new Date();
const expectedResult = {
landed: landed,
addressFk: 121,
@ -161,7 +161,7 @@ describe('Ticket', () => {
it('should set agencyModeId property and call getLanded() method', () => {
jest.spyOn(controller, 'getLanded');
controller.$.agencyMode = {selection: {warehouseFk: 1}};
const shipped = new Date('2022-01-19');
const shipped = new Date();
const agencyModeId = 8;
const expectedResult = {
shipped: shipped,
@ -177,7 +177,7 @@ describe('Ticket', () => {
it('should do nothing if attempting to set the same agencyMode id', () => {
jest.spyOn(controller, 'getShipped');
const landed = new Date('2022-01-19');
const landed = new Date();
const agencyModeId = 7;
const expectedResult = {
landed: landed,
@ -278,8 +278,8 @@ describe('Ticket', () => {
agencyModeFk: 1,
companyFk: 442,
warehouseFk: 1,
shipped: new Date('2022-01-19'),
landed: new Date('2022-01-19')
shipped: new Date(),
landed: new Date()
};
expect(controller.isFormInvalid()).toBeFalsy();
@ -288,7 +288,7 @@ describe('Ticket', () => {
describe('onStepChange()', () => {
it('should call onStepChange method and return a NO_AGENCY_AVAILABLE signal error', async() => {
let landed = new Date('2022-01-19');
let landed = new Date();
landed.setHours(0, 0, 0, 0);
controller._ticket = {
@ -299,7 +299,7 @@ describe('Ticket', () => {
agencyModeFk: 1,
companyFk: 442,
warehouseFk: 1,
shipped: new Date('2022-01-19'),
shipped: new Date(),
landed: landed
};
@ -314,8 +314,8 @@ describe('Ticket', () => {
describe('getLanded()', () => {
it('should return an available landed date', async() => {
const shipped = new Date('2022-01-19');
const expectedResult = {landed: new Date('2022-01-19')};
const shipped = new Date();
const expectedResult = {landed: new Date()};
const params = {
shipped: shipped,
addressFk: 121,
@ -336,8 +336,8 @@ describe('Ticket', () => {
describe('getShipped()', () => {
it('should return an available shipped date', async() => {
const landed = new Date('2022-01-19');
const expectedResult = {shipped: new Date('2022-01-19')};
const landed = new Date();
const expectedResult = {shipped: new Date()};
const params = {
landed: landed,
addressFk: 121,
@ -358,7 +358,7 @@ describe('Ticket', () => {
describe('zoneWhere() getter', () => {
it('should return an object containing filter properties', async() => {
const shipped = new Date('2022-01-19');
const shipped = new Date();
controller.ticket.shipped = shipped;
const expectedResult = {

View File

@ -43,7 +43,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
describe('canRestoreTicket() getter', () => {
it('should return true for a ticket deleted within the last hour', () => {
controller.ticket.isDeleted = true;
controller.ticket.updated = new Date('2022-01-19');
controller.ticket.updated = new Date();
const result = controller.canRestoreTicket;
@ -51,7 +51,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
});
it('should return false for a ticket deleted more than one hour ago', () => {
const pastHour = new Date('2022-01-19');
const pastHour = new Date();
pastHour.setHours(pastHour.getHours() - 2);
controller.ticket.isDeleted = true;

View File

@ -31,14 +31,14 @@ describe('Component vnTicketIndex', () => {
describe('compareDate()', () => {
it('should return warning when the date is the present', () => {
let today = new Date('2022-01-19');
let today = new Date();
let result = controller.compareDate(today);
expect(result).toEqual('warning');
});
it('should return sucess when the date is in the future', () => {
let futureDate = new Date('2022-01-19');
let futureDate = new Date();
futureDate = futureDate.setDate(futureDate.getDate() + 10);
let result = controller.compareDate(futureDate);
@ -46,7 +46,7 @@ describe('Component vnTicketIndex', () => {
});
it('should return undefined when the date is in the past', () => {
let pastDate = new Date('2022-01-19');
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 10);
let result = controller.compareDate(pastDate);

View File

@ -15,9 +15,9 @@ describe('Ticket', () => {
const ticket = {
id: 1,
clientFk: 1101,
shipped: new Date('2022-01-19'),
landed: new Date('2022-01-19'),
created: new Date('2022-01-19'),
shipped: new Date(),
landed: new Date(),
created: new Date(),
client: {salesPersonFk: 1},
address: {mobile: 111111111}
};

View File

@ -38,7 +38,7 @@ describe('Ticket Component vnTicketSearchPanel', () => {
it('should clear the scope days when setting the from property', () => {
controller.filter.scopeDays = 1;
controller.from = new Date('2022-01-19');
controller.from = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.from).toBeDefined();
@ -49,7 +49,7 @@ describe('Ticket Component vnTicketSearchPanel', () => {
it('should clear the scope days when setting the to property', () => {
controller.filter.scopeDays = 1;
controller.to = new Date('2022-01-19');
controller.to = new Date();
expect(controller.filter.scopeDays).toBeNull();
expect(controller.to).toBeDefined();
@ -58,8 +58,8 @@ describe('Ticket Component vnTicketSearchPanel', () => {
describe('scopeDays() setter', () => {
it('should clear the date range when setting the scopeDays property', () => {
controller.filter.from = new Date('2022-01-19');
controller.filter.to = new Date('2022-01-19');
controller.filter.from = new Date();
controller.filter.to = new Date();
controller.scopeDays = 1;

View File

@ -57,7 +57,7 @@ module.exports = Self => {
await Self.rawSql(`
INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created)
VALUES (?, ?, ?, NOW())
VALUES (?, ?, ?, vn.VN_NOW())
`, [thermograph.id, warehouseId, temperatureFk], myOptions);
if (tx) await tx.commit();

View File

@ -49,7 +49,7 @@ xdescribe('Travel cloneWithEntries()', () => {
it(`should clone the travel and the containing entries`, async() => {
const warehouseThree = 3;
const agencyModeOne = 1;
const yesterday = new Date('2022-01-19');
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
travelBefore = await models.Travel.findById(travelId);

View File

@ -95,10 +95,10 @@ describe('Travel extraCommunityFilter()', () => {
});
it('should return the routes matching "shipped from" and "landed to"', async() => {
const from = new Date('2022-01-19');
const from = new Date();
from.setDate(from.getDate() - 2);
from.setHours(0, 0, 0, 0);
const to = new Date('2022-01-19');
const to = new Date();
to.setHours(23, 59, 59, 999);
to.setDate(to.getDate() + 7);
const ctx = {

View File

@ -54,8 +54,8 @@ describe('Travel filter()', () => {
});
it('should return the routes matching "shipped from" and "shipped to"', async() => {
const from = new Date('2022-01-19');
const to = new Date('2022-01-19');
const from = new Date();
const to = new Date();
from.setHours(0, 0, 0, 0);
to.setHours(23, 59, 59, 999);
to.setDate(to.getDate() + 1);

View File

@ -53,7 +53,7 @@ describe('Travel Component vnTravelCreate', () => {
it(`should do nothing if there's no response data.`, () => {
controller.travel = {agencyModeFk: 4};
const tomorrow = new Date('2022-01-19');
const tomorrow = new Date();
const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`;
$httpBackend.expectGET(query).respond(undefined);
@ -67,7 +67,7 @@ describe('Travel Component vnTravelCreate', () => {
it(`should fill the fields when it's selected a date and agency.`, () => {
controller.travel = {agencyModeFk: 1};
const tomorrow = new Date('2022-01-19');
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 9);
const expectedResponse = {
id: 8,

Some files were not shown because too many files have changed in this diff Show More