From c355595384232f3a4adcb6568383ff384b05ec09 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 8 May 2024 11:47:04 +0200 Subject: [PATCH] refs #6882 fix back, tback te2e --- e2e/paths/03-worker/05_calendar.spec.js | 4 +-- .../back/methods/worker/createAbsence.js | 4 +-- .../worker/specs/createAbsence.spec.js | 31 ++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/e2e/paths/03-worker/05_calendar.spec.js b/e2e/paths/03-worker/05_calendar.spec.js index f0af0a053..d4f9be28b 100644 --- a/e2e/paths/03-worker/05_calendar.spec.js +++ b/e2e/paths/03-worker/05_calendar.spec.js @@ -27,7 +27,7 @@ describe('Worker calendar path', () => { }); describe('as hr', () => { - it('should set two days as holidays on the calendar and check the total holidays increased by 1.5', async() => { + it('should set two days as holidays on the calendar and check the total holidays increased by 1', async() => { await page.waitToClick(selectors.workerCalendar.holidays); await page.waitForTimeout(reasonableTimeBetweenClicks); await page.click(selectors.workerCalendar.penultimateMondayOfJanuary); @@ -56,7 +56,7 @@ describe('Worker calendar path', () => { await page.waitForTimeout(reasonableTimeBetweenClicks); await page.click(selectors.workerCalendar.secondFridayOfJun); - expect(await page.getProperty(selectors.workerCalendar.totalHolidaysUsed, 'innerText')).toContain(' 1.5 '); + expect(await page.getProperty(selectors.workerCalendar.totalHolidaysUsed, 'innerText')).toContain(' 1 '); }); }); diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index cb3811fb6..f62c66c8b 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -110,8 +110,8 @@ module.exports = Self => { if (holiday && isFestive) throw new UserError(`Cannot add holidays on this day`); - if ((isHalfHoliday && hasHalfHoliday) && isFestive) - throw new UserError(`Cannot add more than one '1/2 day vacation'`); + if (isHalfHoliday && (hasHalfHoliday || isFestive)) + throw new UserError(`Cannot add more than one '1/2 day vacation`); const absence = await models.Calendar.create({ businessFk: labour.businessFk, diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index 346e43c51..212ed2b97 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -101,7 +101,36 @@ describe('Worker createAbsence()', () => { error = e; } - expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation'`); + expect(error.message).toEqual(`Cannot add more than one '1/2 day vacation`); + }); + + it(`should throw an error when adding a "Holiday" absence if there's a festivity`, async() => { + const ctx = { + req: {accessToken: {userId: 9}}, + args: { + id: 3, + businessFk: 3, + absenceTypeId: 1, + dated: '2001-12-08T23:00:00.000Z' + } + }; + const workerId = 1; + + const tx = await app.models.Calendar.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await app.models.Worker.createAbsence(ctx, workerId, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toEqual(`Cannot add holidays on this day`); }); it(`should throw an error when adding a absence if the worker has hours recorded that day and not is a half absence`, async() => {