Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 4221-intrastat
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-07-20 14:12:08 +02:00
commit cb3e488df9
3 changed files with 54 additions and 3 deletions

View File

@ -2230,6 +2230,10 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`)
(8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'), (8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'),
(10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'); (10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun');
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`)
VALUES
(9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR));
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`) INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`)
VALUES VALUES
(1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in'), (1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in'),

View File

@ -44,12 +44,16 @@ module.exports = Self => {
OR (type = 'range' OR (type = 'range'
AND ( AND (
(started BETWEEN ? AND ?) (started BETWEEN ? AND ?)
OR (ended BETWEEN ? AND ?) OR
(ended BETWEEN ? AND ?)
OR
(started <= ? AND ended >= ?)
) )
) )
) )
ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`; ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`;
const events = await Self.rawSql(query, [zoneFk, started, ended, started, ended, started, ended], myOptions); const events = await Self.rawSql(query,
[zoneFk, started, ended, started, ended, started, ended, started, ended], myOptions);
query = ` query = `
SELECT * SELECT *

View File

@ -6,8 +6,9 @@ describe('zone getEventsFiltered()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const today = new Date();
let result = await models.Zone.getEventsFiltered(10, '2021-10-01', '2021-10-02', options); const result = await models.Zone.getEventsFiltered(10, today, today, options);
expect(result.events.length).toEqual(1); expect(result.events.length).toEqual(1);
expect(result.exclusions.length).toEqual(0); expect(result.exclusions.length).toEqual(0);
@ -18,4 +19,46 @@ describe('zone getEventsFiltered()', () => {
throw e; throw e;
} }
}); });
describe('event range type', () => {
it('should return events and exclusions for the zone 9 in a range of dates', async() => {
const tx = await models.Zone.beginTransaction({});
try {
const options = {transaction: tx};
const today = new Date();
const result = await models.Zone.getEventsFiltered(9, today, today, options);
expect(result.events.length).toEqual(1);
expect(result.exclusions.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should not return events and exclusions for the zone 9 in a range of dates', async() => {
const tx = await models.Zone.beginTransaction({});
try {
const options = {transaction: tx};
const date = new Date();
date.setFullYear(date.getFullYear() - 2);
const dateTomorrow = new Date(date.setDate(date.getDate() + 1));
const result = await models.Zone.getEventsFiltered(9, date, dateTomorrow, options);
expect(result.events.length).toEqual(0);
expect(result.exclusions.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});
}); });