Compare commits

...

2 Commits

Author SHA1 Message Date
Carlos Andrés 97b0a6b1ae Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 4707-tests_workerTimeControl
gitea/salix/pipeline/head There was a failure building this commit Details
2023-10-19 11:32:45 +02:00
Alex Moreno 19fd434c0d tests(addTimeEntry): twelve days consecutives
gitea/salix/pipeline/head There was a failure building this commit Details
2022-10-24 13:46:29 +02:00
1 changed files with 75 additions and 2 deletions

View File

@ -2,7 +2,7 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('workerTimeControl add/delete timeEntry()', () => {
fdescribe('workerTimeControl add/delete timeEntry()', () => {
const HHRRId = 37;
const teamBossId = 13;
const employeeId = 1;
@ -628,7 +628,7 @@ describe('workerTimeControl add/delete timeEntry()', () => {
});
});
describe('for 72h weekly rest', () => {
fdescribe('for 72h weekly rest', () => {
it('should throw when the 72h weekly rest is not fulfilled yet', async() => {
pending('https://redmine.verdnatura.es/issues/4707');
activeCtx.accessToken.userId = salesBossId;
@ -667,6 +667,66 @@ describe('workerTimeControl add/delete timeEntry()', () => {
expect(error.message).toBe(`Descanso semanal 36h. / 72h.`);
});
it('should throw when set twelve days consecutives', async() => {
activeCtx.accessToken.userId = salesBossId;
const workerId = 1110;
const scopeDays = 11;
const dayStart = new Date();
dayStart.setDate(dayStart.getDate() - scopeDays);
let error;
const tx = await models.WorkerTimeControl.beginTransaction({});
const options = {transaction: tx};
await populateScopeDays(dayStart, scopeDays, ctx, workerId, options);
try {
ctx.args = {direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toBe(`Descanso semanal 36h. / 72h.`);
});
fit('should throw when set seven days consecutives', async() => {
activeCtx.accessToken.userId = salesBossId;
const workerId = 1110;
const dayStart = new Date();
dayStart.setDate(dayStart.getDate() - 8);
const scopeDays = 6;
let error;
const tx = await models.WorkerTimeControl.beginTransaction({});
const options = {transaction: tx};
await populateScopeDays(dayStart, scopeDays, ctx, workerId, options);
try {
ctx.args = {direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
console.log(await models.WorkerTimeControl.rawSql(`SELECT * FROM workerTimeControl WHERE userFk = ?`,
[1110], options));
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toBe(`Descanso semanal 36h. / 72h.`);
});
});
});
});
@ -713,3 +773,16 @@ async function populateWeek(date, dayStart, dayEnd, ctx, workerId, options) {
dateStart.setDate(dateStart.getDate() + 1);
}
}
async function populateScopeDays(dayStart, scopeDays, ctx, workerId, options) {
for (let i = 0; i < scopeDays; i++) {
const auxDate = new Date();
auxDate.setDate(dayStart.getDate() + i);
auxDate.setHours(8, 0, 0);
ctx.args = {timed: auxDate, direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
auxDate.setHours(16, 0, 0);
ctx.args = {timed: auxDate, direction: 'out'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
}
}