2019-03-22 11:51:44 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
describe('Worker absences()', () => {
|
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-09 11:38:02 +00:00
|
|
|
expect(calendar.totalHolidays).toEqual(21);
|
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
|
|
|
});
|
|
|
|
});
|