fixed the absences unit test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
8d1bc228b3
commit
a797a2db8b
|
@ -1,7 +1,6 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
// 2066
|
describe('Worker absences()', () => {
|
||||||
xdescribe('Worker absences()', () => {
|
|
||||||
it('should get the absence calendar for a full year contract', async() => {
|
it('should get the absence calendar for a full year contract', async() => {
|
||||||
let ctx = {req: {accessToken: {userId: 106}}};
|
let ctx = {req: {accessToken: {userId: 106}}};
|
||||||
let workerFk = 106;
|
let workerFk = 106;
|
||||||
|
@ -84,14 +83,16 @@ xdescribe('Worker absences()', () => {
|
||||||
yearStart.setDate(1);
|
yearStart.setDate(1);
|
||||||
|
|
||||||
const yearEnd = new Date();
|
const yearEnd = new Date();
|
||||||
yearEnd.setHours(23, 59, 59, 59);
|
const currentYear = yearEnd.getFullYear();
|
||||||
yearEnd.setMonth(11);
|
yearEnd.setFullYear(currentYear + 1);
|
||||||
yearEnd.setDate(31);
|
yearEnd.setHours(0, 0, 0, 0);
|
||||||
|
yearEnd.setMonth(0);
|
||||||
|
yearEnd.setDate(1);
|
||||||
const startedTime = yearStart.getTime();
|
const startedTime = yearStart.getTime();
|
||||||
const endedTime = yearEnd.getTime();
|
const endedTime = yearEnd.getTime();
|
||||||
const dayTimestamp = 1000 * 60 * 60 * 24;
|
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
|
// sets the holidays per year to the amount of days in the current year
|
||||||
let holidaysConfig = await app.models.WorkCenterHoliday.findOne({
|
let holidaysConfig = await app.models.WorkCenterHoliday.findOne({
|
||||||
|
@ -102,17 +103,11 @@ xdescribe('Worker absences()', () => {
|
||||||
|
|
||||||
let originalHolidaysValue = holidaysConfig.days;
|
let originalHolidaysValue = holidaysConfig.days;
|
||||||
|
|
||||||
await app.models.WorkCenterHoliday.updateAll(
|
await holidaysConfig.updateAttribute('days', daysInYear);
|
||||||
{
|
|
||||||
workCenterFk: 1,
|
|
||||||
year: today.getFullYear()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
days: daysInYear
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// normal test begins
|
// 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 contractStartDate = contract.started;
|
||||||
|
|
||||||
const startingContract = new Date();
|
const startingContract = new Date();
|
||||||
|
@ -121,14 +116,13 @@ xdescribe('Worker absences()', () => {
|
||||||
startingContract.setDate(1);
|
startingContract.setDate(1);
|
||||||
|
|
||||||
await app.models.WorkerLabour.rawSql(
|
await app.models.WorkerLabour.rawSql(
|
||||||
`UPDATE postgresql.business SET date_start = ? WHERE business_id = ?`,
|
`UPDATE postgresql.business SET date_start = ?, date_end = ? WHERE business_id = ?`,
|
||||||
[startingContract, contract.businessFk]
|
[startingContract, yearEnd, contract.businessFk]
|
||||||
);
|
);
|
||||||
|
|
||||||
let ctx = {req: {accessToken: {userId: 106}}};
|
let ctx = {req: {accessToken: {userId: userId}}};
|
||||||
let workerFk = 106;
|
|
||||||
|
|
||||||
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 calendar = result[0];
|
||||||
let absences = result[1];
|
let absences = result[1];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue