fixed the absences unit test #423

Merged
bernat merged 2 commits from 2066-fix_absences_back_unit_test into dev 2020-10-23 14:01:15 +00:00
2 changed files with 20 additions and 23 deletions

View File

@ -55,15 +55,18 @@ describe('Client credit insurance path', () => {
expect(message.text).toEqual('The grade must be similar to the last one'); expect(message.text).toEqual('The grade must be similar to the last one');
}); });
it('should provide a correct grade and succesfully save a new credit then be redirected to the credit index', async() => { it('should provide a correct grade and succesfully save a new credit', async() => {
await page.write(selectors.clientCreditInsurance.newInsuranceGrade, '999'); await page.write(selectors.clientCreditInsurance.newInsuranceGrade, '999');
await page.waitToClick(selectors.clientCreditInsurance.saveNewInsuranceCredit); await page.waitToClick(selectors.clientCreditInsurance.saveNewInsuranceCredit);
const message = await page.waitForSnackbar(); const message = await page.waitForSnackbar();
await page.waitForState('client.card.creditInsurance.insurance.index');
expect(message.text).toEqual('Data saved!'); expect(message.text).toEqual('Data saved!');
}); });
it('should be redirected to the credit index', async() => {
await page.waitForState('client.card.creditInsurance.insurance.index');
});
it('should check the amount of credits is the expected', async() => { it('should check the amount of credits is the expected', async() => {
const result = await page.countElement(selectors.clientCreditInsurance.anyCreditInsuranceLine); const result = await page.countElement(selectors.clientCreditInsurance.anyCreditInsuranceLine);

View File

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