From a797a2db8b926af9ac4dd912441eaa38fe7e663d Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Fri, 23 Oct 2020 13:34:57 +0200 Subject: [PATCH] fixed the absences unit test --- .../methods/calendar/specs/absences.spec.js | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index 5cd27127b..42b97e2fc 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -1,7 +1,6 @@ const app = require('vn-loopback/server/server'); -// 2066 -xdescribe('Worker absences()', () => { +describe('Worker absences()', () => { it('should get the absence calendar for a full year contract', async() => { let ctx = {req: {accessToken: {userId: 106}}}; let workerFk = 106; @@ -84,14 +83,16 @@ xdescribe('Worker absences()', () => { yearStart.setDate(1); const yearEnd = new Date(); - yearEnd.setHours(23, 59, 59, 59); - yearEnd.setMonth(11); - yearEnd.setDate(31); + const currentYear = yearEnd.getFullYear(); + yearEnd.setFullYear(currentYear + 1); + yearEnd.setHours(0, 0, 0, 0); + yearEnd.setMonth(0); + yearEnd.setDate(1); const startedTime = yearStart.getTime(); const endedTime = yearEnd.getTime(); const dayTimestamp = 1000 * 60 * 60 * 24; - const daysInYear = Math.floor((endedTime - startedTime) / dayTimestamp); + const daysInYear = Math.round((endedTime - startedTime) / dayTimestamp); // sets the holidays per year to the amount of days in the current year let holidaysConfig = await app.models.WorkCenterHoliday.findOne({ @@ -102,17 +103,11 @@ xdescribe('Worker absences()', () => { let originalHolidaysValue = holidaysConfig.days; - await app.models.WorkCenterHoliday.updateAll( - { - workCenterFk: 1, - year: today.getFullYear() - }, - { - days: daysInYear - } - ); + await holidaysConfig.updateAttribute('days', daysInYear); + // normal test begins - const contract = await app.models.WorkerLabour.findById(106); + const userId = 106; + const contract = await app.models.WorkerLabour.findById(userId); const contractStartDate = contract.started; const startingContract = new Date(); @@ -121,14 +116,13 @@ xdescribe('Worker absences()', () => { startingContract.setDate(1); await app.models.WorkerLabour.rawSql( - `UPDATE postgresql.business SET date_start = ? WHERE business_id = ?`, - [startingContract, contract.businessFk] + `UPDATE postgresql.business SET date_start = ?, date_end = ? WHERE business_id = ?`, + [startingContract, yearEnd, contract.businessFk] ); - let ctx = {req: {accessToken: {userId: 106}}}; - let workerFk = 106; + let ctx = {req: {accessToken: {userId: userId}}}; - let result = await app.models.Calendar.absences(ctx, workerFk, yearStart, yearEnd); + let result = await app.models.Calendar.absences(ctx, userId, yearStart, yearEnd); let calendar = result[0]; let absences = result[1];