2019-03-22 11:51:44 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
describe('Worker absences()', () => {
|
2019-04-23 11:29:52 +00:00
|
|
|
afterAll(async done => {
|
|
|
|
const hiredWorker = await app.models.WorkerLabour.findById(106);
|
|
|
|
|
|
|
|
const endedDate = new Date();
|
|
|
|
endedDate.setFullYear(endedDate.getFullYear() + 1);
|
|
|
|
endedDate.setHours(0, 0, 0, 0);
|
|
|
|
endedDate.setMonth(0);
|
|
|
|
endedDate.setDate(1);
|
|
|
|
|
|
|
|
await hiredWorker.updateAttributes({ended: endedDate});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2019-03-26 09:25:11 +00:00
|
|
|
it('should get the absence calendar for the given dates then evaluate the type of absences', async() => {
|
2019-03-22 11:51:44 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 106}}};
|
|
|
|
let workerFk = 106;
|
|
|
|
|
|
|
|
const started = new Date();
|
|
|
|
started.setHours(0, 0, 0, 0);
|
|
|
|
started.setMonth(0);
|
|
|
|
started.setDate(1);
|
|
|
|
|
|
|
|
const monthIndex = 11;
|
|
|
|
const ended = new Date();
|
|
|
|
ended.setHours(0, 0, 0, 0);
|
|
|
|
ended.setMonth(monthIndex + 1);
|
|
|
|
ended.setDate(0);
|
|
|
|
|
|
|
|
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
|
|
|
let calendar = result[0];
|
|
|
|
let absences = result[1];
|
|
|
|
|
2019-04-23 11:29:52 +00:00
|
|
|
expect(calendar.totalHolidays).toEqual(27.5);
|
|
|
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
|
|
|
|
|
|
|
let firstType = absences[0].absenceType().name;
|
|
|
|
let sixthType = absences[5].absenceType().name;
|
|
|
|
|
|
|
|
expect(firstType).toEqual('Leave of absence');
|
|
|
|
expect(sixthType).toEqual('Holidays');
|
|
|
|
});
|
|
|
|
|
2019-07-31 07:17:26 +00:00
|
|
|
it(`should fire the worker 106 on Juny and see he/she has 14`, async() => {
|
|
|
|
let workerFk = 106;
|
|
|
|
const firedWorker = await app.models.WorkerLabour.findById(workerFk);
|
2019-04-23 11:29:52 +00:00
|
|
|
|
|
|
|
const endedDate = new Date();
|
2019-07-31 07:17:26 +00:00
|
|
|
endedDate.setDate(30);
|
2019-04-23 11:29:52 +00:00
|
|
|
endedDate.setMonth(5);
|
2019-07-31 07:17:26 +00:00
|
|
|
endedDate.setHours(0, 0, 0, 0);
|
2019-04-23 11:29:52 +00:00
|
|
|
|
|
|
|
await firedWorker.updateAttributes({ended: endedDate});
|
|
|
|
|
2019-07-31 07:17:26 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2019-04-23 11:29:52 +00:00
|
|
|
|
|
|
|
const started = new Date();
|
|
|
|
started.setHours(0, 0, 0, 0);
|
|
|
|
started.setMonth(0);
|
|
|
|
started.setDate(1);
|
|
|
|
|
|
|
|
const monthIndex = 11;
|
|
|
|
const ended = new Date();
|
|
|
|
ended.setHours(0, 0, 0, 0);
|
|
|
|
ended.setMonth(monthIndex + 1);
|
|
|
|
ended.setDate(0);
|
|
|
|
|
|
|
|
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
|
|
|
let calendar = result[0];
|
|
|
|
let absences = result[1];
|
|
|
|
|
2019-07-31 07:17:26 +00:00
|
|
|
expect(calendar.totalHolidays).toEqual(13.5);
|
2019-04-23 11:29:52 +00:00
|
|
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
|
|
|
|
|
|
|
let firstType = absences[0].absenceType().name;
|
|
|
|
let sixthType = absences[5].absenceType().name;
|
|
|
|
|
|
|
|
expect(firstType).toEqual('Leave of absence');
|
|
|
|
expect(sixthType).toEqual('Holidays');
|
|
|
|
});
|
|
|
|
|
2019-06-21 07:43:47 +00:00
|
|
|
it(`should fire the worker 106 on March and see he/she has 7`, async() => {
|
2019-04-23 11:29:52 +00:00
|
|
|
const firedWorker = await app.models.WorkerLabour.findById(106);
|
|
|
|
|
|
|
|
const endedDate = new Date();
|
|
|
|
endedDate.setHours(0, 0, 0, 0);
|
|
|
|
endedDate.setMonth(2);
|
|
|
|
endedDate.setDate(31);
|
|
|
|
|
|
|
|
await firedWorker.updateAttributes({ended: endedDate});
|
|
|
|
|
|
|
|
let ctx = {req: {accessToken: {userId: 106}}};
|
|
|
|
let workerFk = 106;
|
|
|
|
|
|
|
|
const started = new Date();
|
|
|
|
started.setHours(0, 0, 0, 0);
|
|
|
|
started.setMonth(0);
|
|
|
|
started.setDate(1);
|
|
|
|
|
|
|
|
const monthIndex = 11;
|
|
|
|
const ended = new Date();
|
|
|
|
ended.setHours(0, 0, 0, 0);
|
|
|
|
ended.setMonth(monthIndex + 1);
|
|
|
|
ended.setDate(0);
|
|
|
|
|
|
|
|
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
|
|
|
let calendar = result[0];
|
|
|
|
let absences = result[1];
|
|
|
|
|
2019-06-21 07:43:47 +00:00
|
|
|
expect(calendar.totalHolidays).toEqual(7);
|
2019-04-23 11:29:52 +00:00
|
|
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
|
|
|
|
|
|
|
let firstType = absences[0].absenceType().name;
|
|
|
|
let sixthType = absences[5].absenceType().name;
|
|
|
|
|
|
|
|
expect(firstType).toEqual('Leave of absence');
|
|
|
|
expect(sixthType).toEqual('Holidays');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should fire the worker 106 on january and see he/she has x`, async() => {
|
|
|
|
const firedWorker = await app.models.WorkerLabour.findById(106);
|
|
|
|
|
|
|
|
const endedDate = new Date();
|
|
|
|
endedDate.setHours(0, 0, 0, 0);
|
|
|
|
endedDate.setMonth(0);
|
|
|
|
endedDate.setDate(28);
|
|
|
|
|
|
|
|
await firedWorker.updateAttributes({ended: endedDate});
|
|
|
|
|
|
|
|
let ctx = {req: {accessToken: {userId: 106}}};
|
|
|
|
let workerFk = 106;
|
|
|
|
|
|
|
|
const started = new Date();
|
|
|
|
started.setHours(0, 0, 0, 0);
|
|
|
|
started.setMonth(0);
|
|
|
|
started.setDate(1);
|
|
|
|
|
|
|
|
const monthIndex = 11;
|
|
|
|
const ended = new Date();
|
|
|
|
ended.setHours(0, 0, 0, 0);
|
|
|
|
ended.setMonth(monthIndex + 1);
|
|
|
|
ended.setDate(0);
|
|
|
|
|
|
|
|
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
|
|
|
let calendar = result[0];
|
|
|
|
let absences = result[1];
|
|
|
|
|
|
|
|
expect(calendar.totalHolidays).toEqual(2);
|
2019-03-22 11:51:44 +00:00
|
|
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
|
|
|
|
2019-03-26 09:25:11 +00:00
|
|
|
let firstType = absences[0].absenceType().name;
|
|
|
|
let sixthType = absences[5].absenceType().name;
|
|
|
|
|
|
|
|
expect(firstType).toEqual('Leave of absence');
|
|
|
|
expect(sixthType).toEqual('Holidays');
|
2019-03-22 11:51:44 +00:00
|
|
|
});
|
|
|
|
});
|