4258-worker_time-control_tests #1014
|
@ -1967,7 +1967,8 @@ INSERT INTO `postgresql`.`calendar_employee` (`business_id`, `calendar_state_id`
|
|||
(1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -20 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 20 DAY))),
|
||||
(1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -13 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 8 DAY))),
|
||||
(1107, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -14 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 9 DAY))),
|
||||
(1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 7 DAY)));
|
||||
(1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 7 DAY))),
|
||||
(1107, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL - 16 DAY));
|
||||
|
||||
INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`, `apiKey`)
|
||||
VALUES
|
||||
|
@ -2237,8 +2238,8 @@ INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`)
|
|||
VALUES
|
||||
(1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in'),
|
||||
(1106, CONCAT(util.VN_CURDATE(), ' 10:00'), TRUE, 'middle'),
|
||||
(1106, CONCAT(util.VN_CURDATE(), ' 10:10'), TRUE, 'middle'),
|
||||
(1106, CONCAT(util.VN_CURDATE(), ' 15:00'), TRUE, 'out');
|
||||
(1106, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle'),
|
||||
(1106, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out');
|
||||
|
||||
INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `code`)
|
||||
VALUES
|
||||
|
@ -2606,3 +2607,7 @@ INSERT INTO `vn`.`sectorCollection` (`userFk`, `sectorFk`)
|
|||
INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk`)
|
||||
VALUES
|
||||
(1, 1);
|
||||
|
||||
INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`)
|
||||
VALUES
|
||||
(1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13);
|
|
@ -44093,6 +44093,7 @@ WHERE
|
|||
RETURN vPhyto;
|
||||
END ;;
|
||||
DELIMITER ;
|
||||
|
||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||
|
|
|
@ -911,52 +911,16 @@ export default {
|
|||
dialogTimeInput: '.vn-dialog.shown vn-input-time[ng-model="$ctrl.newTimeEntry.timed"]',
|
||||
dialogTimeDirection: '.vn-dialog.shown vn-autocomplete[ng-model="$ctrl.newTimeEntry.direction"]',
|
||||
mondayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(1) > vn-icon-button',
|
||||
tuesdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(2) > vn-icon-button',
|
||||
wednesdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(3) > vn-icon-button',
|
||||
thursdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-icon-button',
|
||||
fridayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(5) > vn-icon-button',
|
||||
saturdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(6) > vn-icon-button',
|
||||
sundayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(7) > vn-icon-button',
|
||||
firstEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(1) > vn-chip > div:nth-child(2)',
|
||||
firstEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(1) > vn-chip > div:nth-child(2)',
|
||||
firstEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(1) > vn-chip > div:nth-child(2)',
|
||||
firstEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(1) > vn-chip > div:nth-child(2)',
|
||||
firstEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(1) > vn-chip > div:nth-child(2)',
|
||||
firstEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(1) > vn-chip > div:nth-child(2)',
|
||||
firstEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(1) > vn-chip > div:nth-child(2)',
|
||||
firstEntryOfMondayDelete: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(1) > vn-chip > vn-icon[icon="cancel"]',
|
||||
secondEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(2) > vn-chip > div:nth-child(2)',
|
||||
alexm marked this conversation as resolved
Outdated
|
||||
secondEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(2) > vn-chip > div:nth-child(2)',
|
||||
secondEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(2) > vn-chip > div:nth-child(2)',
|
||||
secondEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(2) > vn-chip > div:nth-child(2)',
|
||||
secondEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(2) > vn-chip > div:nth-child(2)',
|
||||
secondEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(2) > vn-chip > div:nth-child(2)',
|
||||
secondEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(2) > vn-chip > div:nth-child(2)',
|
||||
thirdEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(3) > vn-chip > div:nth-child(2)',
|
||||
thirdEntryOfMondayDelete: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(3) > vn-chip > vn-icon[icon="cancel"]',
|
||||
thirdEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(3) > vn-chip > div:nth-child(2)',
|
||||
thirdEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(3) > vn-chip > div:nth-child(2)',
|
||||
thirdEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(3) > vn-chip > div:nth-child(2)',
|
||||
thirdEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(3) > vn-chip > div:nth-child(2)',
|
||||
thirdEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(3) > vn-chip > div:nth-child(2)',
|
||||
thirdEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(3) > vn-chip > div:nth-child(2)',
|
||||
fourthEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(4) > vn-chip > div:nth-child(2)',
|
||||
fourthEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(4) > vn-chip > div:nth-child(2)',
|
||||
fourthEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(4) > vn-chip > div:nth-child(2)',
|
||||
fourthEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(4) > vn-chip > div:nth-child(2)',
|
||||
fourthEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(4) > vn-chip > div:nth-child(2)',
|
||||
fourthEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(4) > vn-chip > div:nth-child(2)',
|
||||
fourthEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(4) > vn-chip > div:nth-child(2)',
|
||||
mondayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(1)',
|
||||
tuesdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(2)',
|
||||
wednesdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(3)',
|
||||
thursdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(4)',
|
||||
fridayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(5)',
|
||||
saturdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(6)',
|
||||
sundayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(7)',
|
||||
weekWorkedHours: 'vn-worker-time-control vn-side-menu vn-label-value > section > span',
|
||||
nextMonthButton: 'vn-worker-time-control vn-side-menu vn-calendar vn-button[icon=keyboard_arrow_right]',
|
||||
previousMonthButton: 'vn-worker-time-control vn-side-menu vn-calendar vn-button[icon=keyboard_arrow_left]',
|
||||
monthName: 'vn-worker-time-control vn-side-menu vn-calendar div > .title',
|
||||
secondWeekDay: 'vn-worker-time-control vn-side-menu vn-calendar .day:nth-child(8) > .day-number',
|
||||
thrirdWeekDay: 'vn-worker-time-control vn-side-menu vn-calendar .day:nth-child(15) > .day-number',
|
||||
navigateBackToIndex: 'vn-worker-descriptor [name="goToModuleIndex"]'
|
||||
},
|
||||
workerCalendar: {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||
import selectors from '../../helpers/selectors.js';
|
||||
import getBrowser from '../../helpers/puppeteer';
|
||||
|
||||
|
@ -10,414 +11,105 @@ describe('Worker time control path', () => {
|
|||
await page.loginAndModule('salesBoss', 'worker');
|
||||
await page.accessToSearchResult('HankPym');
|
||||
await page.accessToSection('worker.card.timeControl');
|
||||
await page.waitToClick(selectors.workerTimeControl.previousMonthButton);
|
||||
await page.waitToClick(selectors.workerTimeControl.secondWeekDay);
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
describe('as salesBoss', () => {
|
||||
describe('on Monday', () => {
|
||||
it('should scan in Hank Pym', async() => {
|
||||
const scanTime = '07:00';
|
||||
const eightAm = '08:00';
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
eightAm eightAm
|
||||
const fourPm = '16:00';
|
||||
const hankPymId = 1107;
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfMonday, 'innerText');
|
||||
it('should go to the next month', async() => {
|
||||
const date = new Date();
|
||||
date.setMonth(date.getMonth() + 1);
|
||||
const month = date.toLocaleString('default', {month: 'long'});
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
await page.waitToClick(selectors.workerTimeControl.nextMonthButton);
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.monthName, 'innerText');
|
||||
|
||||
it(`should scan out Hank Pym for break`, async() => {
|
||||
const scanTime = '10:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should scan in Hank Pym for a wrong hour and forget to scan in from the break`, async() => {
|
||||
const scanTime = '18:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.thirdEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should delete the wrong entry for Hank Pym`, async() => {
|
||||
const wrongScanTime = '18:00';
|
||||
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.thirdEntryOfMonday, wrongScanTime);
|
||||
await page.waitToClick(selectors.workerTimeControl.thirdEntryOfMondayDelete);
|
||||
await page.respondToDialog('accept');
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('Entry removed');
|
||||
});
|
||||
|
||||
it(`should scan out Hank Pym to leave early`, async() => {
|
||||
const scanTime = '14:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.thirdEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should add the break's scan in for Hank Pym and be in the right order`, async() => {
|
||||
const scanTime = '10:20';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.fourthEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual('14:00');
|
||||
});
|
||||
|
||||
it(`should the third entry be the scan in from break`, async() => {
|
||||
const scanTime = '10:20';
|
||||
|
||||
const result = await page
|
||||
.waitToGetProperty(selectors.workerTimeControl.thirdEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 6:40 hours`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.mondayWorkedHours, '06:40 h.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('on Tuesday', () => {
|
||||
it('should happily scan in Hank Pym', async() => {
|
||||
const scanTime = '08:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.tuesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfTuesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should happily scan out Hank Pym for break`, async() => {
|
||||
const scanTime = '10:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.tuesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfTuesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should happily scan in Hank Pym from the break`, async() => {
|
||||
const scanTime = '10:20';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.tuesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.thirdEntryOfTuesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should happily scan out Hank Pym for the day`, async() => {
|
||||
const scanTime = '16:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.tuesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.fourthEntryOfTuesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 7:40 hours`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.tuesdayWorkedHours, '07:40 h.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('on Wednesday', () => {
|
||||
it('should cheerfully scan in Hank Pym', async() => {
|
||||
const scanTime = '09:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.wednesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfWednesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should cheerfully scan out Hank Pym for break`, async() => {
|
||||
const scanTime = '10:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.wednesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfWednesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should cheerfully scan in Hank Pym from the break`, async() => {
|
||||
const scanTime = '10:20';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.wednesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.thirdEntryOfWednesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should cheerfully scan out Hank Pym for the day`, async() => {
|
||||
const scanTime = '17:00';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.wednesdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.fourthEntryOfWednesday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 7:40 cheerfull hours`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.wednesdayWorkedHours, '07:40 h.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('on Thursday', () => {
|
||||
it('should joyfully scan in Hank Pym', async() => {
|
||||
const scanTime = '09:59';
|
||||
|
||||
await page.waitToClick(selectors.workerTimeControl.thursdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfThursday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should joyfully scan out Hank Pym for break`, async() => {
|
||||
const scanTime = '10:00';
|
||||
await page.waitToClick(selectors.workerTimeControl.thursdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfThursday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should joyfully scan in Hank Pym from the break`, async() => {
|
||||
const scanTime = '10:20';
|
||||
await page.waitToClick(selectors.workerTimeControl.thursdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.thirdEntryOfThursday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should joyfully scan out Hank Pym for the day`, async() => {
|
||||
const scanTime = '17:59';
|
||||
await page.waitToClick(selectors.workerTimeControl.thursdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.fourthEntryOfThursday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 7:40 joyfull hours`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.thursdayWorkedHours, '07:40 h.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('on Friday', () => {
|
||||
it('should smilingly scan in Hank Pym', async() => {
|
||||
const scanTime = '07:30';
|
||||
await page.waitToClick(selectors.workerTimeControl.fridayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfFriday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should smilingly scan out Hank Pym for break`, async() => {
|
||||
const scanTime = '10:00';
|
||||
await page.waitToClick(selectors.workerTimeControl.fridayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfFriday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should smilingly scan in Hank Pym from the break`, async() => {
|
||||
const scanTime = '10:20';
|
||||
await page.waitToClick(selectors.workerTimeControl.fridayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'intermediate');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.thirdEntryOfFriday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should smilingly scan out Hank Pym for the day`, async() => {
|
||||
const scanTime = '15:30';
|
||||
await page.waitToClick(selectors.workerTimeControl.fridayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.fourthEntryOfFriday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 7:40 hours with a smile on his face`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.fridayWorkedHours, '07:40 h.');
|
||||
});
|
||||
});
|
||||
expect(result).toContain(month);
|
||||
});
|
||||
|
||||
describe('as HHRR', () => {
|
||||
describe('on Saturday', () => {
|
||||
it('should log in as hr and pick the worker module', async() => {
|
||||
await page.loginAndModule('hr', 'worker');
|
||||
});
|
||||
it('should go to current month', async() => {
|
||||
const date = new Date();
|
||||
const month = date.toLocaleString('default', {month: 'long'});
|
||||
|
||||
it('should search for a worker and access to its summary', async() => {
|
||||
await page.accessToSearchResult('HankPym');
|
||||
await page.waitForState('worker.card.summary');
|
||||
});
|
||||
await page.waitToClick(selectors.workerTimeControl.previousMonthButton);
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.monthName, 'innerText');
|
||||
|
||||
it('should access to the time control section', async() => {
|
||||
await page.accessToSection('worker.card.timeControl');
|
||||
await page.waitForState('worker.card.timeControl');
|
||||
await page.waitToClick(selectors.workerTimeControl.previousMonthButton);
|
||||
await page.waitToClick(selectors.workerTimeControl.secondWeekDay);
|
||||
});
|
||||
|
||||
it('should lovingly scan in Hank Pym', async() => {
|
||||
const scanTime = '06:00';
|
||||
await page.waitForTimeout(1000); // without this timeout the dialog doesn't pop up
|
||||
await page.waitToClick(selectors.workerTimeControl.saturdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfSaturday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should lovingly scan out Hank Pym for the day with no break to leave a bit early`, async() => {
|
||||
const scanTime = '13:40';
|
||||
await page.waitToClick(selectors.workerTimeControl.saturdayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfSaturday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 7:40 hours with all his will`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.saturdayWorkedHours, '07:40 h.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('on Sunday', () => {
|
||||
it('should gladly scan in Hank Pym', async() => {
|
||||
const scanTime = '05:00';
|
||||
await page.waitToClick(selectors.workerTimeControl.sundayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfSunday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should gladly scan out Hank Pym for the day with no break to leave a bit early`, async() => {
|
||||
const scanTime = '12:40';
|
||||
await page.waitToClick(selectors.workerTimeControl.sundayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, scanTime);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfSunday, 'innerText');
|
||||
|
||||
expect(result).toEqual(scanTime);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 7:40 glad hours`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.sundayWorkedHours, '07:40 h.');
|
||||
});
|
||||
|
||||
it(`should check Hank Pym doesn't have hours set on the next months second week`, async() => {
|
||||
await page.waitToClick(selectors.workerTimeControl.nextMonthButton);
|
||||
await page.waitToClick(selectors.workerTimeControl.secondWeekDay);
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '00:00 h.');
|
||||
});
|
||||
|
||||
it(`should check he didn't scan in this week yet`, async() => {
|
||||
await page.waitToClick(selectors.workerTimeControl.navigateBackToIndex);
|
||||
await page.accessToSearchResult('salesBoss');
|
||||
await page.accessToSection('worker.card.timeControl');
|
||||
|
||||
const wholeWeekHours = await page
|
||||
.waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText');
|
||||
|
||||
expect(wholeWeekHours).toEqual('00:00 h.');
|
||||
});
|
||||
});
|
||||
expect(result).toContain(month);
|
||||
});
|
||||
|
||||
describe('after all this amazing week', () => {
|
||||
it('should log in Hank', async() => {
|
||||
await page.loginAndModule('HankPym', 'worker');
|
||||
await page.accessToSearchResult('HankPym');
|
||||
await page.accessToSection('worker.card.timeControl');
|
||||
await page.waitToClick(selectors.workerTimeControl.previousMonthButton);
|
||||
await page.waitToClick(selectors.workerTimeControl.secondWeekDay);
|
||||
});
|
||||
it('should go 1 month in the past', async() => {
|
||||
const date = new Date();
|
||||
date.setMonth(date.getMonth() - 1);
|
||||
const timestamp = Math.round(date.getTime() / 1000);
|
||||
const month = date.toLocaleString('default', {month: 'long'});
|
||||
|
||||
it('should check his weekly hours are alright', async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '52:40 h.');
|
||||
});
|
||||
await page.loginAndModule('salesBoss', 'worker');
|
||||
await page.goto(`http://localhost:5000/#!/worker/${hankPymId}/time-control?timestamp=${timestamp}`);
|
||||
await page.waitToClick(selectors.workerTimeControl.secondWeekDay);
|
||||
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.monthName, 'innerText');
|
||||
|
||||
expect(result).toContain(month);
|
||||
});
|
||||
|
||||
it(`should return error when insert 'out' of first entry`, async() => {
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, eightAm);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toBeDefined();
|
||||
});
|
||||
|
||||
it(`should insert 'in' monday`, async() => {
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, eightAm);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'in');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual(eightAm);
|
||||
});
|
||||
|
||||
it(`should insert 'out' monday`, async() => {
|
||||
await page.waitToClick(selectors.workerTimeControl.mondayAddTimeButton);
|
||||
await page.pickTime(selectors.workerTimeControl.dialogTimeInput, fourPm);
|
||||
await page.autocompleteSearch(selectors.workerTimeControl.dialogTimeDirection, 'out');
|
||||
await page.respondToDialog('accept');
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.secondEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual(fourPm);
|
||||
});
|
||||
|
||||
it(`should check Hank Pym worked 8:20 hours`, async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.mondayWorkedHours, '08:20 h.');
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '08:20 h.');
|
||||
});
|
||||
|
||||
it('should remove first entry of monday', async() => {
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.firstEntryOfMonday, eightAm);
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.secondEntryOfMonday, fourPm);
|
||||
await page.waitToClick(selectors.workerTimeControl.firstEntryOfMondayDelete);
|
||||
await page.respondToDialog('accept');
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('Entry removed');
|
||||
});
|
||||
|
||||
it(`should be the 'out' the first entry of monday`, async() => {
|
||||
const result = await page.waitToGetProperty(selectors.workerTimeControl.firstEntryOfMonday, 'innerText');
|
||||
|
||||
expect(result).toEqual(fourPm);
|
||||
});
|
||||
|
||||
it('should change week of month', async() => {
|
||||
await page.waitToClick(selectors.workerTimeControl.thrirdWeekDay);
|
||||
await page.waitForTextInElement(selectors.workerTimeControl.mondayWorkedHours, '00:00 h.');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -124,5 +124,13 @@
|
|||
"isWithoutNegatives": "isWithoutNegatives",
|
||||
"routeFk": "routeFk",
|
||||
"Not enough privileges to edit a client with verified data": "Not enough privileges to edit a client with verified data",
|
||||
"Can't change the password of another worker": "Can't change the password of another worker"
|
||||
"Can't change the password of another worker": "Can't change the password of another worker",
|
||||
"No hay un contrato en vigor": "There is no existing contract",
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
There is no existing contract There is no existing contract
|
||||
"No está permitido trabajar": "Not allowed to work",
|
||||
"Dirección incorrecta": "Wrong direction",
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
si Direccion en este caso se refiere a "in", "middle" o "out", seria entonces: Wrong direction si Direccion en este caso se refiere a "in", "middle" o "out", seria entonces: Wrong direction
|
||||
"No se permite fichar a futuro": "It is not allowed to sign in the future",
|
||||
"Descanso diario 12h.": "Daily rest 12h.",
|
||||
"Fichadas impares": "Odd signs",
|
||||
"Descanso diario 9h.": "Daily rest 9h.",
|
||||
"Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h."
|
||||
}
|
|
@ -227,5 +227,12 @@
|
|||
"This ticket is already a refund": "Este ticket ya es un abono",
|
||||
"isWithoutNegatives": "isWithoutNegatives",
|
||||
"routeFk": "routeFk",
|
||||
"Can't change the password of another worker": "No se puede cambiar la contraseña de otro trabajador"
|
||||
"Can't change the password of another worker": "No se puede cambiar la contraseña de otro trabajador",
|
||||
"No hay un contrato en vigor": "No hay un contrato en vigor",
|
||||
"No se permite fichar a futuro": "No se permite fichar a futuro",
|
||||
"No está permitido trabajar": "No está permitido trabajar",
|
||||
"Fichadas impares": "Fichadas impares",
|
||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
||||
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
||||
"Dirección incorrecta": "Dirección incorrecta"
|
||||
}
|
|
@ -46,30 +46,11 @@ module.exports = Self => {
|
|||
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
|
||||
const minTime = new Date(args.timed);
|
||||
minTime.setHours(0, 0, 0, 0);
|
||||
query = `CALL vn.workerTimeControl_clockIn(?,?,?)`;
|
||||
const [response] = await Self.rawSql(query, [workerId, args.timed, args.direction], myOptions);
|
||||
if (response[0] && response[0].error)
|
||||
throw new UserError(response[0].error);
|
||||
|
||||
query = `SELECT * FROM vn.workerLabour WHERE workerFk = ? AND (ended >= ? OR ended IS NULL);`;
|
||||
const [workerLabour] = await Self.rawSql(query, [workerId, minTime]);
|
||||
const absence = await models.Calendar.findOne({
|
||||
where: {
|
||||
businessFk: workerLabour.businessFk,
|
||||
dated: minTime
|
||||
}
|
||||
});
|
||||
if (absence) {
|
||||
const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk, null, myOptions);
|
||||
const isNotHalfAbsence = absenceType.code != 'halfHoliday'
|
||||
&& absenceType.code != 'halfPaidLeave'
|
||||
&& absenceType.code != 'halfFurlough';
|
||||
if (isNotHalfAbsence)
|
||||
throw new UserError(`The worker has a marked absence that day`);
|
||||
}
|
||||
return models.WorkerTimeControl.create({
|
||||
userFk: workerId,
|
||||
direction: args.direction,
|
||||
timed: args.timed,
|
||||
manual: true
|
||||
}, myOptions);
|
||||
return response;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
const models = app.models;
|
||||
|
||||
describe('workerTimeControl add/delete timeEntry()', () => {
|
||||
const HHRRId = 37;
|
||||
|
@ -8,6 +8,14 @@ describe('workerTimeControl add/delete timeEntry()', () => {
|
|||
const employeeId = 1;
|
||||
const salesPersonId = 1106;
|
||||
const salesBossId = 19;
|
||||
const hankPymId = 1107;
|
||||
const jessicaJonesId = 1110;
|
||||
const monday = 1;
|
||||
const tuesday = 2;
|
||||
const thursday = 4;
|
||||
const friday = 5;
|
||||
const saturday = 6;
|
||||
const sunday = 7;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 50},
|
||||
};
|
||||
|
@ -19,190 +27,675 @@ describe('workerTimeControl add/delete timeEntry()', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should fail to add a time entry if the target user is not a subordinate', async() => {
|
||||
activeCtx.accessToken.userId = employeeId;
|
||||
const workerId = 2;
|
||||
describe('as Role errors', () => {
|
||||
it('should fail to add a time entry if the target user is not a subordinate', async() => {
|
||||
activeCtx.accessToken.userId = employeeId;
|
||||
const workerId = 2;
|
||||
|
||||
let error;
|
||||
let error;
|
||||
|
||||
try {
|
||||
ctx.args = {timed: new Date(), direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
try {
|
||||
ctx.args = {timed: new Date(), direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toBe(`You don't have enough privileges`);
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toBe(`You don't have enough privileges`);
|
||||
});
|
||||
|
||||
it('should fail to add if the current and the target user are the same and is not team boss', async() => {
|
||||
activeCtx.accessToken.userId = employeeId;
|
||||
const workerId = employeeId;
|
||||
let error;
|
||||
|
||||
try {
|
||||
ctx.args = {timed: new Date(), direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toBe(`You don't have enough privileges`);
|
||||
});
|
||||
|
||||
it('should add if the current user is team boss and the target user is himself', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
is himself (esto estaba mal) is himself (esto estaba mal)
|
||||
activeCtx.accessToken.userId = teamBossId;
|
||||
const workerId = teamBossId;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const todayAtOne = new Date();
|
||||
todayAtOne.setHours(1, 0, 0, 0);
|
||||
|
||||
ctx.args = {timed: todayAtOne, direction: 'in'};
|
||||
const [createdTimeEntry] = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should try but fail to delete his own time entry', async() => {
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = salesBossId;
|
||||
|
||||
let error;
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const todayAtOne = new Date();
|
||||
todayAtOne.setHours(1, 0, 0, 0);
|
||||
|
||||
ctx.args = {timed: todayAtOne, direction: 'in'};
|
||||
const [createdTimeEntry] = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
activeCtx.accessToken.userId = salesPersonId;
|
||||
await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toBe(`You don't have enough privileges`);
|
||||
});
|
||||
|
||||
it('should delete the created time entry for the team boss as himself', async() => {
|
||||
activeCtx.accessToken.userId = teamBossId;
|
||||
const workerId = teamBossId;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const todayAtOne = new Date();
|
||||
todayAtOne.setHours(1, 0, 0, 0);
|
||||
|
||||
ctx.args = {timed: todayAtOne, direction: 'in'};
|
||||
const [createdTimeEntry] = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
|
||||
await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
|
||||
const deletedTimeEntry = await models.WorkerTimeControl.findById(createdTimeEntry.id, null, options);
|
||||
|
||||
expect(deletedTimeEntry).toBeNull();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should delete the created time entry for the team boss as HHRR', async() => {
|
||||
activeCtx.accessToken.userId = HHRRId;
|
||||
const workerId = teamBossId;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const todayAtOne = new Date();
|
||||
todayAtOne.setHours(1, 0, 0, 0);
|
||||
|
||||
ctx.args = {timed: todayAtOne, direction: 'in'};
|
||||
const [createdTimeEntry] = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
|
||||
await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
|
||||
const deletedTimeEntry = await models.WorkerTimeControl.findById(createdTimeEntry.id, null, options);
|
||||
|
||||
expect(deletedTimeEntry).toBeNull();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should edit the created time entry for the team boss as HHRR', async() => {
|
||||
activeCtx.accessToken.userId = HHRRId;
|
||||
const workerId = teamBossId;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const todayAtOne = new Date();
|
||||
todayAtOne.setHours(1, 0, 0, 0);
|
||||
|
||||
ctx.args = {timed: todayAtOne, direction: 'in'};
|
||||
const [createdTimeEntry] = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
|
||||
ctx.args = {direction: 'out'};
|
||||
const updatedTimeEntry = await models.WorkerTimeControl.updateTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
|
||||
expect(updatedTimeEntry.direction).toEqual('out');
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to add if the current and the target user are the same and is not team boss', async() => {
|
||||
activeCtx.accessToken.userId = employeeId;
|
||||
const workerId = employeeId;
|
||||
let error;
|
||||
describe('WorkerTimeControl_clockIn calls', () => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
quitale el "as" en este contexto no tiene sentido. quitale el "as" en este contexto no tiene sentido.
|
||||
it('should fail to add a time entry if the target user has an absence that day', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
user is absent user is absent
user has an absence
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - 16);
|
||||
date.setHours(8, 0, 0);
|
||||
let error;
|
||||
|
||||
try {
|
||||
ctx.args = {timed: new Date(), direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toBe(`You don't have enough privileges`);
|
||||
});
|
||||
|
||||
it('should add if the current user is team boss and the target user is a himself', async() => {
|
||||
activeCtx.accessToken.userId = teamBossId;
|
||||
const workerId = teamBossId;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
const todayAtSix = new Date();
|
||||
todayAtSix.setHours(18, 30, 0, 0);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
ctx.args = {timed: todayAtSix, direction: 'in'};
|
||||
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
expect(error.message).toBe(`No está permitido trabajar`);
|
||||
});
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
it('should fail to add a time entry for a worker without an existing contract', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
should fail to add a time entry for a worker without an existing contract should fail to add a time entry for a worker without an existing contract
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
const date = new Date();
|
||||
date.setFullYear(date.getFullYear() - 2);
|
||||
let error;
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
it('should fail to add a time entry if the target user has absent that day', async() => {
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = salesPersonId;
|
||||
let error;
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
const calendar = await app.models.Calendar.findById(3);
|
||||
expect(error.message).toBe(`No hay un contrato en vigor`);
|
||||
});
|
||||
|
||||
try {
|
||||
ctx.args = {timed: new Date(calendar.dated), direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
describe('direction errors', () => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
quita "as" quita "as"
|
||||
it('should throw an error when trying "in" direction twice', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
creo que quieres decir esto?
creo que quieres decir esto?
`Should throw an error when trying "in" direction twice`
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
expect(error.message).toBe(`The worker has a marked absence that day`);
|
||||
});
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
it('should try but fail to delete his own time entry', async() => {
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = salesBossId;
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
let error;
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
date.setHours(10, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
const todayAtSeven = new Date();
|
||||
todayAtSeven.setHours(19, 30, 0, 0);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
ctx.args = {timed: todayAtSeven, direction: 'in'};
|
||||
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
expect(error.message).toBe(`Dirección incorrecta`);
|
||||
});
|
||||
|
||||
activeCtx.accessToken.userId = salesPersonId;
|
||||
await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
it('should throw an error when trying "in" direction after insert "in" and "middle"', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
No creo que te este retornando un error, creo que te hara un throw.
No creo que te este retornando un error, creo que te hara un throw.
`Should throw an error when trying "in" direction twice with "middle" in between`
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.statusCode).toBe(400);
|
||||
expect(error.message).toBe(`You don't have enough privileges`);
|
||||
});
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
it('should delete the created time entry for the team boss as himself', async() => {
|
||||
activeCtx.accessToken.userId = teamBossId;
|
||||
const workerId = teamBossId;
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(9, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'middle'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
date.setHours(10, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
const todayAtFive = new Date();
|
||||
todayAtFive.setHours(17, 30, 0, 0);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
ctx.args = {timed: todayAtFive, direction: 'in'};
|
||||
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
expect(error.message).toBe(`Dirección incorrecta`);
|
||||
});
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
it('Should throw an error when trying "out" before closing a "middle" couple', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
`Should throw an error when trying "out" before closing a "middle" couple`
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
const deletedTimeEntry = await models.WorkerTimeControl.findById(createdTimeEntry.id, null, options);
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
expect(deletedTimeEntry).toBeNull();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(9, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'middle'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
it('should delete the created time entry for the team boss as HHRR', async() => {
|
||||
activeCtx.accessToken.userId = HHRRId;
|
||||
const workerId = teamBossId;
|
||||
try {
|
||||
date.setHours(10, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
const todayAtFive = new Date();
|
||||
todayAtFive.setHours(17, 30, 0, 0);
|
||||
expect(error.message).toBe(`Dirección incorrecta`);
|
||||
});
|
||||
|
||||
ctx.args = {timed: todayAtFive, direction: 'in'};
|
||||
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
it('should throw an error when trying "middle" after "out"', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
`Should throw an error when trying "middle" after "out"`
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
const deletedTimeEntry = await models.WorkerTimeControl.findById(createdTimeEntry.id, null, options);
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(9, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
expect(deletedTimeEntry).toBeNull();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
try {
|
||||
date.setHours(10, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'middle'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
it('should edit the created time entry for the team boss as HHRR', async() => {
|
||||
activeCtx.accessToken.userId = HHRRId;
|
||||
const workerId = teamBossId;
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
expect(error.message).toBe(`Dirección incorrecta`);
|
||||
});
|
||||
|
||||
const todayAtFive = new Date();
|
||||
todayAtFive.setHours(17, 30, 0, 0);
|
||||
it('should throw an error when trying "out" direction twice', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
`Should throw an error when trying "out" direction twice`
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
ctx.args = {timed: todayAtFive, direction: 'in'};
|
||||
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
expect(createdTimeEntry.id).toBeDefined();
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
ctx.args = {direction: 'out'};
|
||||
const updatedTimeEntry = await models.WorkerTimeControl.updateTimeEntry(ctx, createdTimeEntry.id, options);
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(9, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
expect(updatedTimeEntry.direction).toEqual('out');
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
date.setHours(10, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toBe(`Dirección incorrecta`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('12h rest', () => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
cambialo por '12h rest' (sin "as") las traducciones que has usado usan la palabra "rest" y no "break" cambialo por '12h rest' (sin "as")
las traducciones que has usado usan la palabra "rest" y no "break"
|
||||
it('should throw an error when the 12h rest is not fulfilled yet', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
`should throw when the 12h rest is not fulfilled yet' `should throw when the 12h rest is not fulfilled yet'
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(16, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
try {
|
||||
date = weekDay(date, tuesday);
|
||||
date.setHours(4, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toBe(`Descanso diario 12h.`);
|
||||
});
|
||||
|
||||
it('should not fail as the 12h rest is fulfilled', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
should not fail as the 12h rest is fulfilled should not fail as the 12h rest is fulfilled
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(16, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
try {
|
||||
date = weekDay(date, tuesday);
|
||||
date.setHours(4, 1, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).not.toBeDefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe('for 3500kg drivers with enforced 9h rest', () => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
`for 3500kg drivers with enforced 9h rest`
|
||||
it('should throw an error when the 9h enforced rest is not fulfilled', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
Que esta pasando con los returns? XD 'should throw when the 9h enforced rest is not fulfilled' Que esta pasando con los returns? XD
'should throw when the 9h enforced rest is not fulfilled'
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = jessicaJonesId;
|
||||
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(16, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
try {
|
||||
date = weekDay(date, tuesday);
|
||||
date.setHours(1, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toBe(`Descanso diario 9h.`);
|
||||
});
|
||||
|
||||
it('should not fail when the 9h enforced rest is fulfilled', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
solo por consistencia con la palabra rest 'Should not fail when the 9h enforced rest is fulfilled' solo por consistencia con la palabra rest
'Should not fail when the 9h enforced rest is fulfilled'
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = jessicaJonesId;
|
||||
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - 21);
|
||||
date = weekDay(date, monday);
|
||||
let error;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
date.setHours(16, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
try {
|
||||
date = weekDay(date, tuesday);
|
||||
date.setHours(1, 1, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).not.toBeDefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe('for 36h weekly rest', () => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
for 36h weekly rest for 36h weekly rest
|
||||
it('should throw an error when the 36h weekly rest is not fulfilled', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
should throw when the 36h weekly rest is not fulfilled should throw when the 36h weekly rest is not fulfilled
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
let date = new Date();
|
||||
date.setMonth(date.getMonth() - 2);
|
||||
date.setDate(1);
|
||||
let error;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
await populateWeek(date, monday, sunday, ctx, workerId, options);
|
||||
date = nextWeek(date);
|
||||
await populateWeek(date, monday, thursday, ctx, workerId, options);
|
||||
date = weekDay(date, friday);
|
||||
date.setHours(6, 59, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
try {
|
||||
date.setHours(7, 1, 0);
|
||||
ctx.args = {timed: date, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toBe(`Descanso semanal 36h. / 72h.`);
|
||||
});
|
||||
|
||||
it('should throw an error when the 36h weekly rest is not fulfilled again', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
este enunciado es confuso, esta dependiendo de data creada en otro "it" ? este enunciado es confuso, esta dependiendo de data creada en otro "it" ?
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
let date = new Date();
|
||||
date.setMonth(date.getMonth() - 2);
|
||||
date.setDate(1);
|
||||
let error;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
await populateWeek(date, monday, sunday, ctx, workerId, options);
|
||||
date = nextWeek(date);
|
||||
await populateWeek(date, monday, thursday, ctx, workerId, options);
|
||||
|
||||
try {
|
||||
date = weekDay(date, saturday);
|
||||
date.setHours(3, 59, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toBe(`Descanso semanal 36h. / 72h.`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('for 72h weekly rest', () => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
for 72h weekly rest for 72h weekly rest
|
||||
it('should throw when the 72h weekly rest is not fulfilled yet', async() => {
|
||||
alexm marked this conversation as resolved
Outdated
carlosjr
commented
'Should throw when the 72h weekly rest is not fulfilled yet' 'Should throw when the 72h weekly rest is not fulfilled yet'
'Should throw when the weekly rest is not fulfilled yet' (por contexto omito las horas)
|
||||
activeCtx.accessToken.userId = salesBossId;
|
||||
const workerId = hankPymId;
|
||||
|
||||
let date = new Date();
|
||||
date.setMonth(date.getMonth() - 2);
|
||||
date.setDate(1);
|
||||
let error;
|
||||
|
||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
await populateWeek(date, monday, sunday, ctx, workerId, options);
|
||||
date = nextWeek(date);
|
||||
await populateWeek(date, monday, thursday, ctx, workerId, options);
|
||||
date = nextWeek(date);
|
||||
await populateWeek(date, monday, friday, ctx, workerId, options);
|
||||
date = nextWeek(date);
|
||||
await populateWeek(date, monday, saturday, ctx, workerId, options);
|
||||
date = nextWeek(date);
|
||||
await populateWeek(date, monday, saturday, ctx, workerId, options);
|
||||
date = lastWeek(date);
|
||||
|
||||
try {
|
||||
date = weekDay(date, sunday);
|
||||
date.setHours(8, 0, 0);
|
||||
ctx.args = {timed: date, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.message).toBe(`Descanso semanal 36h. / 72h.`);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function weekDay(date, dayToSet) {
|
||||
const currentDay = date.getDay();
|
||||
const distance = dayToSet - currentDay;
|
||||
|
||||
date.setDate(date.getDate() + distance);
|
||||
return date;
|
||||
}
|
||||
|
||||
function nextWeek(date) {
|
||||
const sunday = 7;
|
||||
const currentDay = date.getDay();
|
||||
let newDate = date;
|
||||
if (currentDay != 0)
|
||||
newDate = weekDay(date, sunday);
|
||||
|
||||
newDate.setDate(newDate.getDate() + 1);
|
||||
return newDate;
|
||||
}
|
||||
|
||||
function lastWeek(date) {
|
||||
const monday = 1;
|
||||
newDate = weekDay(date, monday);
|
||||
|
||||
newDate.setDate(newDate.getDate() - 1);
|
||||
return newDate;
|
||||
}
|
||||
|
||||
async function populateWeek(date, dayStart, dayEnd, ctx, workerId, options) {
|
||||
const dateStart = new Date(weekDay(date, dayStart));
|
||||
const dateEnd = new Date(dateStart);
|
||||
dateEnd.setDate(dateStart.getDate() + dayEnd);
|
||||
|
||||
for (let i = dayStart; i <= dayEnd; i++) {
|
||||
dateStart.setHours(8, 0, 0);
|
||||
ctx.args = {timed: dateStart, direction: 'in'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
dateStart.setHours(16, 0, 0);
|
||||
ctx.args = {timed: dateStart, direction: 'out'};
|
||||
await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
|
||||
dateStart.setDate(dateStart.getDate() + 1);
|
||||
}
|
||||
}
|
||||
|
|
monthName es mas breve