prepare for static dates
gitea/salix/pipeline/head This commit is unstable Details

This commit is contained in:
Alex Moreno 2022-06-09 13:33:01 +02:00
parent 7eec9de0aa
commit eb9bd66ddb
31 changed files with 1510 additions and 1589 deletions

View File

@ -1,4 +1,5 @@
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
baseTime.setHours(8, 0, 0, 0);
jasmine.clock().mockDate(baseTime);
const baseTime = null; // new Date(2022, 0, 19, 8, 0, 0, 0);
if (baseTime) {
jasmine.clock().install();
jasmine.clock().mockDate(baseTime);
}

View File

@ -31,11 +31,13 @@ COPY \
import-changes.sh \
config.ini \
dump/mysqlPlugins.sql \
dump/mockDate.sql \
dump/structure.sql \
dump/dumpedFixtures.sql \
./
RUN gosu mysql docker-init.sh \
&& docker-dump.sh mysqlPlugins \
&& docker-dump.sh mockDate \
&& docker-dump.sh structure \
&& docker-dump.sh dumpedFixtures \
&& gosu mysql docker-temp-stop.sh

View File

@ -1,57 +0,0 @@
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('08: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 08:00:00');
ELSE
RETURN NOW();
END IF;
END ;;
DELIMITER ;

File diff suppressed because it is too large Load Diff

43
db/dump/mockDate.sql Normal file
View File

@ -0,0 +1,43 @@
CREATE SCHEMA IF NOT EXISTS `util`;
USE `util`;
DELIMITER ;;
DROP FUNCTION IF EXISTS `util`.`mockedDate`;
CREATE FUNCTION `util`.`mockedDate`()
RETURNS DATETIME
DETERMINISTIC
BEGIN
RETURN NOW();
-- '2022-01-19 08:00:00'
END ;;
DELIMITER ;
DELIMITER ;;
DROP FUNCTION IF EXISTS `util`.`VN_CURDATE`;
CREATE FUNCTION `util`.`VN_CURDATE`()
RETURNS DATE
DETERMINISTIC
BEGIN
RETURN DATE(mockedDate());
END ;;
DELIMITER ;
DELIMITER ;;
DROP FUNCTION IF EXISTS `util`.`VN_CURTIME`;
CREATE FUNCTION `util`.`VN_CURTIME`()
RETURNS TIME
DETERMINISTIC
BEGIN
RETURN TIME(mockedDate());
END ;;
DELIMITER ;
DELIMITER ;;
DROP FUNCTION IF EXISTS `util`.`VN_NOW`;
CREATE FUNCTION `util`.`VN_NOW`()
RETURNS DATETIME
DETERMINISTIC
BEGIN
RETURN mockedDate();
END ;;
DELIMITER ;

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,9 @@ describe('zone zone_getLanded()', () => {
it(`should return data for a shipped in the past`, async() => {
let stmts = [];
let stmt;
stmts.push('START TRANSACTION');
const date = new Date();
date.setHours(0, 0, 0, 0);
let params = {
addressFk: 121,
@ -14,7 +15,8 @@ describe('zone zone_getLanded()', () => {
warehouseFk: 1,
showExpiredZones: true};
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(vn.VN_CURDATE(), INTERVAL -1 DAY), ?, ?, ?, ?)', [
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL -1 DAY), ?, ?, ?, ?)', [
date,
params.addressFk,
params.agencyModeFk,
params.warehouseFk,
@ -38,6 +40,8 @@ describe('zone zone_getLanded()', () => {
it(`should return data for a shipped tomorrow`, async() => {
let stmts = [];
let stmt;
const date = new Date();
date.setHours(0, 0, 0, 0);
stmts.push('START TRANSACTION');
@ -47,7 +51,8 @@ describe('zone zone_getLanded()', () => {
warehouseFk: 1,
showExpiredZones: false};
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(vn.VN_CURDATE(), INTERVAL +2 DAY), ?, ?, ?, ?)', [
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL +2 DAY), ?, ?, ?, ?)', [
date,
params.addressFk,
params.agencyModeFk,
params.warehouseFk,

View File

@ -51,6 +51,9 @@ module.exports = function(Self) {
Self.createReceipt = async(ctx, options) => {
const models = Self.app.models;
const args = ctx.args;
const date = new Date();
date.setHours(0, 0, 0, 0);
let tx;
const myOptions = {};
@ -92,8 +95,9 @@ module.exports = function(Self) {
throw new UserError('Invalid account');
await Self.rawSql(
`CALL vn.ledger_doCompensation(vn.VN_CURDATE(), ?, ?, ?, ?, ?, ?)`,
`CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`,
[
date,
args.compensationAccount,
args.bankFk,
accountingType.receiptDescription + originalClient.accountingAccount,
@ -106,9 +110,10 @@ 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(?, vn.VN_CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
[
null,
date,
bank.account,
originalClient.accountingAccount,
description,
@ -126,9 +131,10 @@ module.exports = function(Self) {
);
await Self.rawSql(
`SELECT xdiario_new(?, vn.VN_CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
[
xdiarioNew.ledger,
date,
originalClient.accountingAccount,
bank.account,
description,

View File

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

View File

@ -25,8 +25,10 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = `SELECT vn.clientGetDebt(?, vn.VN_CURDATE()) AS debt`;
const [debt] = await Self.rawSql(query, [clientFk], myOptions);
const date = new Date();
date.setHours(0, 0, 0, 0);
const query = `SELECT vn.clientGetDebt(?, ?) AS debt`;
const [debt] = await Self.rawSql(query, [clientFk, date], myOptions);
return debt;
};

View File

@ -32,6 +32,8 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const date = new Date();
date.setHours(0, 0, 0, 0);
const ticket = await Self.app.models.Ticket.findById(ticketId, null, myOptions);
const query = `
SELECT
@ -50,12 +52,12 @@ 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 >= vn.VN_CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0
WHERE t.shipped >= ? AND t.clientFk = ? AND ts.alertLevel = 0
AND t.id <> ? AND t.warehouseFk = ?
ORDER BY t.shipped
LIMIT 10`;
return Self.rawSql(query, [id, ticketId, ticket.warehouseFk], myOptions);
return Self.rawSql(query, [date, id, ticketId, ticket.warehouseFk], myOptions);
};
};

View File

@ -95,7 +95,6 @@ describe('client summary()', () => {
it('should return a summary object without containing active recoveries', async() => {
const clientId = 1101;
const tx = await models.Client.beginTransaction({});
jasmine.clock().uninstall();
try {
const options = {transaction: tx};
@ -109,9 +108,6 @@ describe('client summary()', () => {
await tx.rollback();
throw e;
}
jasmine.clock().install();
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});
it('should return a summary object containing active recoveries', async() => {

View File

@ -51,6 +51,8 @@ module.exports = Self => {
const stmts = [];
const date = new Date();
date.setHours(0, 0, 0, 0);
const stmt = new ParameterizedSQL(
`SELECT *
FROM (
@ -72,7 +74,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 = vn.VN_CURDATE()
d.created = ${date}
AND d.amount > 0
ORDER BY co.created DESC) d`
);

View File

@ -27,13 +27,15 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const date = new Date();
date.setHours(0, 0, 0, 0);
const query = `
SELECT count(*) AS hasActiveRecovery
FROM vn.recovery
WHERE clientFk = ?
AND IFNULL(finished,vn.VN_CURDATE()) >= vn.VN_CURDATE();
AND IFNULL(finished, ?) >= ?;
`;
const [result] = await Self.rawSql(query, [id], myOptions);
const [result] = await Self.rawSql(query, [id, date, date], myOptions);
return result.hasActiveRecovery != 0;
};

View File

@ -145,6 +145,8 @@ module.exports = Self => {
stmts.push('CALL cache.visible_refresh(@calc_id, FALSE, 1)');
const date = new Date();
date.setHours(0, 0, 0, 0);
stmt = new ParameterizedSQL(`
SELECT
i.image,
@ -202,7 +204,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(vn.VN_CURDATE(),INTERVAL 1 YEAR)
LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(${date},INTERVAL 1 YEAR)
LEFT JOIN supplier s ON s.id = e.supplierFk`
);

View File

@ -32,6 +32,8 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const date = new Date();
date.setHours(0, 0, 0, 0);
const wastes = await Self.rawSql(`
SELECT *, 100 * dwindle / total AS percentage
FROM (
@ -42,11 +44,11 @@ module.exports = Self => {
sum(ws.saleWaste) AS dwindle
FROM bs.waste ws
WHERE buyer = ? AND family = ?
AND year = YEAR(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()))
AND week = WEEK(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()), 1)
AND year = YEAR(TIMESTAMPADD(WEEK,-1, ?))
AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1)
GROUP BY buyer, itemFk
) sub
ORDER BY family, percentage DESC`, [buyer, family], myOptions);
ORDER BY family, percentage DESC`, [buyer, family, date, date], myOptions);
const details = [];

View File

@ -19,6 +19,8 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const date = new Date();
date.setHours(0, 0, 0, 0);
const wastes = await Self.rawSql(`
SELECT *, 100 * dwindle / total AS percentage
FROM (
@ -27,11 +29,11 @@ module.exports = Self => {
sum(ws.saleTotal) AS total,
sum(ws.saleWaste) AS dwindle
FROM bs.waste ws
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()))
AND week = WEEK(TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()), 1)
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1, ?))
AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1)
GROUP BY buyer, family
) sub
ORDER BY percentage DESC`, null, myOptions);
ORDER BY percentage DESC`, [date, date], myOptions);
const details = [];

View File

@ -34,6 +34,8 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const date = new Date();
date.setHours(0, 0, 0, 0);
const stmt = new ParameterizedSQL(`
SELECT
u.name AS salesPerson,
@ -47,7 +49,7 @@ module.exports = Self => {
JOIN client c ON c.id = v.userFk
JOIN account.user u ON c.salesPersonFk = u.id
LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk
AND vn.VN_CURDATE() BETWEEN sc.started AND sc.ended
AND ${date} BETWEEN sc.started AND sc.ended
LEFT JOIN workerTeamCollegues wtc
ON wtc.collegueFk = IFNULL(sc.workerSubstitute, c.salesPersonFk)`);

View File

@ -104,6 +104,8 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
const conn = Self.dataSource.connector;
const models = Self.app.models;
const date = new Date();
date.setHours(0, 0, 0, 0);
const args = ctx.args;
const myOptions = {};
@ -272,7 +274,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 >= vn.VN_CURDATE()`);
AND f.shipped >= ${date}`);
stmts.push('CALL ticket_getProblems(FALSE)');
stmts.push(`

View File

@ -74,6 +74,8 @@ module.exports = Self => {
filter = mergeFilters(filter, {where});
const date = new Date();
date.setHours(0, 0, 0, 0);
const stmts = [];
const stmt = new ParameterizedSQL(
`SELECT *
@ -101,7 +103,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(vn.VN_CURDATE(), INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL
WHERE r.created > DATE_ADD(${date}, INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL
GROUP BY r.id
) a`
);

View File

@ -1,16 +1,6 @@
const models = require('vn-loopback/server/server').models;
describe('route unlink()', () => {
beforeAll(() => {
jasmine.clock().uninstall();
});
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date('January 19, 2022 08:00:00');
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

@ -24,6 +24,8 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const date = new Date();
date.setHours(0, 0, 0, 0);
const query = `
SELECT
s.id AS saleFk,
@ -39,11 +41,11 @@ 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, vn.VN_CURDATE())
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, ?)
AND t.id = ? AND cb.id IS NULL
ORDER BY t.landed DESC, t.id DESC`;
const claimableSales = await Self.rawSql(query, [ticketFk], myOptions);
const claimableSales = await Self.rawSql(query, [ticketFk, date], myOptions);
return claimableSales;
};

View File

@ -132,6 +132,8 @@ module.exports = Self => {
Self.filter = async(ctx, filter, options) => {
const userId = ctx.req.accessToken.userId;
const conn = Self.dataSource.connector;
const date = new Date();
date.setHours(0, 0, 0, 0);
const models = Self.app.models;
const args = ctx.args;
@ -305,7 +307,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 >= vn.VN_CURDATE()`);
AND f.shipped >= ${date}`);
stmts.push('CALL ticket_getProblems(FALSE)');
stmt = new ParameterizedSQL(`

View File

@ -26,6 +26,8 @@ module.exports = function(Self) {
Self.makeInvoice = async(ctx, ticketsIds, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const date = new Date();
date.setHours(0, 0, 0, 0);
const myOptions = {};
let tx;
@ -81,7 +83,7 @@ module.exports = function(Self) {
WHERE id IN(?) AND refFk IS NULL
`, [ticketsIds], myOptions);
await Self.rawSql('CALL invoiceOut_new(?, vn.VN_CURDATE(), null, @invoiceId)', [serial], myOptions);
await Self.rawSql('CALL invoiceOut_new(?, ?, null, @invoiceId)', [serial, date], myOptions);
const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], myOptions);

View File

@ -2,16 +2,6 @@ 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('January 19, 2022 08:00:00');
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

@ -40,6 +40,7 @@ module.exports = Self => {
const models = Self.app.models;
let tx;
const myOptions = {};
const date = new Date();
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -57,8 +58,8 @@ module.exports = Self => {
await Self.rawSql(`
INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created)
VALUES (?, ?, ?, vn.VN_NOW())
`, [thermograph.id, warehouseId, temperatureFk], myOptions);
VALUES (?, ?, ?, ?)
`, [thermograph.id, warehouseId, temperatureFk, date], myOptions);
if (tx) await tx.commit();

View File

@ -1,16 +1,6 @@
const app = require('vn-loopback/server/server');
describe('Worker absences()', () => {
beforeAll(() => {
jasmine.clock().uninstall();
});
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});
it('should get the absence calendar for a full year contract', async() => {
const ctx = {req: {accessToken: {userId: 1106}}};
const workerId = 1106;

View File

@ -78,8 +78,6 @@ describe('workerTimeControl add/delete timeEntry()', () => {
});
it('should fail to add a time entry if the target user has absent that day', async() => {
jasmine.clock().uninstall();
activeCtx.accessToken.userId = salesBossId;
const workerId = salesPersonId;
let error;
@ -94,10 +92,6 @@ describe('workerTimeControl add/delete timeEntry()', () => {
}
expect(error.message).toBe(`The worker has a marked absence that day`);
jasmine.clock().install();
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});
it('should try but fail to delete his own time entry', async() => {

View File

@ -80,6 +80,9 @@ module.exports = Self => {
if (hasHoursRecorded && isNotHalfAbsence)
throw new UserError(`The worker has hours recorded that day`);
const date = new Date();
const now = new Date();
date.setHours(0, 0, 0, 0);
const [result] = await Self.rawSql(
`SELECT COUNT(*) halfHolidayCounter
FROM vn.calendar c
@ -88,8 +91,8 @@ module.exports = Self => {
JOIN vn.person pe ON pe.id = p.person_id
WHERE c.dayOffTypeFk = 6
AND pe.workerFk = ?
AND c.dated BETWEEN util.firstDayOfYear(vn.VN_CURDATE())
AND LAST_DAY(DATE_ADD(vn.VN_NOW(), INTERVAL 12-MONTH(vn.VN_NOW()) MONTH))`, [id]);
AND c.dated BETWEEN util.firstDayOfYear(?)
AND LAST_DAY(DATE_ADD(?, INTERVAL 12-MONTH(?) MONTH))`, [id, date, now]);
const hasHalfHoliday = result.halfHolidayCounter > 0;
const isHalfHoliday = absenceType.code === 'halfHoliday';

View File

@ -9,15 +9,6 @@ describe('Worker holidays()', () => {
headers: {origin: 'http://localhost'}
};
const ctx = {req: activeCtx};
beforeAll(() => {
jasmine.clock().uninstall();
});
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});
beforeEach(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({

View File

@ -93,11 +93,13 @@ module.exports = async function(request, response, next) {
await email.send(mailOptions);
}
// Update queue status
const date = new Date();
date.setHours(0, 0, 0, 0);
sql = `UPDATE invoiceOut_queue
SET status = "printed",
printed = NOW()
printed = ?
WHERE invoiceFk = ?`;
connection.query(sql, [invoiceOut.id]);
connection.query(sql, [date, invoiceOut.id]);
connection.query('COMMIT');
} catch (error) {
connection.query('ROLLBACK');