fixed the absences unit test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-10-23 13:34:57 +02:00
parent 8d1bc228b3
commit a797a2db8b
1 changed files with 15 additions and 21 deletions

View File

@ -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];