tests(addTimeEntry): twelve days consecutives
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2022-10-24 13:46:29 +02:00
parent 04be661b68
commit 19fd434c0d
1 changed files with 75 additions and 2 deletions

View File

@ -2,7 +2,7 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
describe('workerTimeControl add/delete timeEntry()', () => { fdescribe('workerTimeControl add/delete timeEntry()', () => {
const HHRRId = 37; const HHRRId = 37;
const teamBossId = 13; const teamBossId = 13;
const employeeId = 1; const employeeId = 1;
@ -615,7 +615,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() => { it('should throw when the 72h weekly rest is not fulfilled yet', async() => {
activeCtx.accessToken.userId = salesBossId; activeCtx.accessToken.userId = salesBossId;
const workerId = hankPymId; const workerId = hankPymId;
@ -653,6 +653,66 @@ describe('workerTimeControl add/delete timeEntry()', () => {
expect(error.message).toBe(`Descanso semanal 36h. / 72h.`); 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.`);
});
}); });
}); });
}); });
@ -699,3 +759,16 @@ async function populateWeek(date, dayStart, dayEnd, ctx, workerId, options) {
dateStart.setDate(dateStart.getDate() + 1); 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);
}
}