Skip to content

Commit

Permalink
test(Payroll)
Browse files Browse the repository at this point in the history
- Implement integration test for Payroll Indice
  • Loading branch information
lomamech committed Feb 28, 2024
1 parent 687a9b3 commit 8d5d70b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 74 deletions.
6 changes: 4 additions & 2 deletions server/controllers/payroll/configuration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ async function updateEmployeesBasicIndice(idPeriod, dateTo) {
// this query the date of the very first increment as well as the last value of the base index,
// the responsibility index linked to the function and date of hire
const sqlFindOldEmployees = `
SELECT emp.uuid, emp.date_embauche, lastIndice.date AS lastDateIncrease, lastIndice.grade_indice,
sfi.value AS function_indice_value, emp.grade_uuid, emp.fonction_id, pa.display_name
SELECT emp.uuid, emp.date_embauche, lastIndice.date AS lastDateIncrease,
MAX(lastIndice.grade_indice) AS grade_indice, sfi.value AS function_indice_value, emp.grade_uuid,
emp.fonction_id, pa.display_name
FROM employee AS emp
JOIN config_employee_item AS it ON it.employee_uuid = emp.uuid
JOIN config_employee AS conf ON conf.id = it.config_employee_id
Expand All @@ -229,6 +230,7 @@ async function updateEmployeesBasicIndice(idPeriod, dateTo) {
LEFT JOIN staffing_function_indice AS sfi ON sfi.fonction_id = emp.fonction_id
JOIN patient AS pa ON pa.uuid = emp.patient_uuid
WHERE pay.id = ?
GROUP BY emp.uuid
ORDER BY pa.display_name ASC;
`;

Expand Down
2 changes: 1 addition & 1 deletion test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ INSERT INTO `patient` (`uuid`, `project_id`, `reference`, `debtor_uuid`, `displa
INSERT INTO `creditor` (`uuid`, `group_uuid`, `text`) VALUES (0x75ED6B1141764BF7821D34BA638B0647, 0xB0FA5ED204F94CB392F761D6404696E7, 'Crediteur [Employee indice 1]');
INSERT INTO `creditor` (`uuid`, `group_uuid`, `text`) VALUES (0x6150E9B14D214DC28E845BFAAB40DD5E, 0xB0FA5ED204F94CB392F761D6404696E7, 'Crediteur [Employee indice 2]');

INSERT INTO `employee` (`uuid`, `code`, `date_embauche`, `grade_uuid`, `nb_spouse`, `nb_enfant`, `individual_salary`, `bank`, `bank_account`, `fonction_id`, `service_uuid`, `creditor_uuid`, `locked`, `patient_uuid`, `reference`) VALUES (0x10F64A41DA594962AA9A90CF0D42257C, 'IMA-ASSR-1', DATE_ADD(CURRENT_DATE, INTERVAL -2 YEAR), 0x71E9F21CD9B111E58AB778EB2F2A46E0, 0, 0, 0, NULL, NULL, 2, 0xB1816006555845F993A0C222B5EFA6CB, 0x75ED6B1141764BF7821D34BA638B0647, NULL, 0x4B23E6B9187F4CE69696542F798B5F32, 3);
INSERT INTO `employee` (`uuid`, `code`, `date_embauche`, `grade_uuid`, `nb_spouse`, `nb_enfant`, `individual_salary`, `bank`, `bank_account`, `fonction_id`, `service_uuid`, `creditor_uuid`, `locked`, `patient_uuid`, `reference`) VALUES (0x10F64A41DA594962AA9A90CF0D42257C, 'IMA-ASSR-1', DATE_ADD(CURRENT_DATE, INTERVAL -25 MONTH) , 0x71E9F21CD9B111E58AB778EB2F2A46E0, 0, 0, 0, NULL, NULL, 2, 0xB1816006555845F993A0C222B5EFA6CB, 0x75ED6B1141764BF7821D34BA638B0647, NULL, 0x4B23E6B9187F4CE69696542F798B5F32, 3);
INSERT INTO `employee` (`uuid`, `code`, `date_embauche`, `grade_uuid`, `nb_spouse`, `nb_enfant`, `individual_salary`, `bank`, `bank_account`, `fonction_id`, `service_uuid`, `creditor_uuid`, `locked`, `patient_uuid`, `reference`) VALUES (0xD321099D01CD41029686B87CB70B9311, 'IMA-ASSP-2', DATE_ADD(CURRENT_DATE, INTERVAL -2 YEAR), 0x61E9F21CD9B111E48AB678EB2F2A46E0, 0, 2, 0, NULL, NULL, 1, 0xE3988489EF6641DF88FA8B8ED6AA03AC, 0x6150E9B14D214DC28E845BFAAB40DD5E, NULL, 0xA6643C4F310145BA961B54FD83D71E7C, 4);

INSERT INTO `config_employee_item` (`id`, `config_employee_id`, `employee_uuid`) VALUES
Expand Down
114 changes: 43 additions & 71 deletions test/integration/staffingIndices.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-unused-expressions:off */
/* global expect, agent */

const moment = require('moment');
const helpers = require('./helpers');

/*
Expand Down Expand Up @@ -60,22 +60,18 @@ describe('test/integration/staffingIndices The staffing indices API', () => {
};

const year = new Date().getFullYear();
const yearPlus2 = year + 2;
const datePlus2Year = moment().add(2, 'year').format('YYYY-MM-DD');

const payrollConfigYearPlus2 = {
label : `Account Configuration ${yearPlus2}`,
dateFrom : `${yearPlus2}-01-01`,
dateTo : `${yearPlus2}-01-31`,
config_rubric_id : 2,
config_accounting_id : 1,
config_weekend_id : 1,
config_employee_id : 2,
};
const datePlus2YearSub1Month = moment(datePlus2Year).clone().subtract(1, 'months').format('YYYY-MM-DD');
const datePlus2YearSub1MonthBegin = moment(datePlus2YearSub1Month).clone().startOf('month').format('YYYY-MM-DD');
const datePlus2YearSub1MonthEnd = moment(datePlus2YearSub1Month).clone().endOf('month').format('YYYY-MM-DD');

const yearPlus2 = year + 2;

const payrollConfigYearPlus2Month = {
label : `Account Configuration ${yearPlus2} plus one month`,
dateFrom : `${yearPlus2}-02-01`,
dateTo : `${yearPlus2}-02-28`,
const payrollConfigYearPlus2Sub1Month = {
label : `Account Configuration ${yearPlus2} substract one month`,
dateFrom : datePlus2YearSub1MonthBegin,
dateTo : datePlus2YearSub1MonthEnd,
config_rubric_id : 2,
config_accounting_id : 1,
config_weekend_id : 1,
Expand Down Expand Up @@ -210,20 +206,19 @@ describe('test/integration/staffingIndices The staffing indices API', () => {
it(`POST /PAYROLL_CONFIG should Payroll Configuration Year+2 for Checking
the increase in base indices when creating a futuristic pay period`, () => {
return agent.post('/payroll_config')
.send(payrollConfigYearPlus2)
.send(payrollConfigYearPlus2Sub1Month)
.then((res) => {
payrollConfigYearPlus2.id = res.body.id;
payrollConfigYearPlus2Sub1Month.id = res.body.id;
helpers.api.created(res);

// This test must verify that the two configured employees must benefit from
// the increase in their base index for two years the first employee has a base index of 66
// with a rate of 5% in accordance with his date of hire and his last configuration
// its index after configuring the new pay period must be 69

// And the second employee has a base index of 138
// with a rate of 5% in accordance with his date of hire and his last configuration
// its index after configuring the new pay period must be 144
// To test the new functionality intended to increase the base indices,
// the system will first calculate the number of years of employee seniority
// in relation to the pay period as well as the difference in years between
// the last increment of the base index by in relation to the pay period,
// and if this difference is greater than zero, the basic index will be
// incremented as a percentage proportionally to the number of years.

//
return agent.get('/staffing_indices')
.then(res2 => {
expect(res2).to.have.status(200);
Expand All @@ -232,60 +227,37 @@ describe('test/integration/staffingIndices The staffing indices API', () => {
let checkIncrementationGradeIndice = 0;

res2.body.forEach(element => {
if (element.grade_indice === 145) {
// For the following example the first was hired on January 27, 2022, and
// its last base index dates from February 27, 2024 and it is 66
// The pay period is January 2026
// The system will first calculate their year of seniority in relation to the pay period
// Seniority = (2026-01-31) - (2022-01-27) is equal to 4 years (1)
// Last increment = (2026-01-31) - (2024-02-27) is equal to 2 years (2)
// Base Index Growth Rate being 5%, the base index of this employee will be increased in
// accordance with the difference in years (1)-(2) => 4 years - 2 years = 2 years,
// - Year 1: 66 + (66 x 0.05) = 69.03
// - Year 2: 69.03 + (69.03 x 0.05) = 72.77 which the system will round to 73
if (element.grade_indice === 73) {
checkIncrementationGradeIndice++;
}

if (element.grade_indice === 69) {
checkIncrementationGradeIndice++;
}
});
expect(checkIncrementationGradeIndice).to.equal(2);
expect(res2.body).to.have.length(9);
})
.catch(helpers.handler);
})
.catch(helpers.handler);
});

// With the following test, which takes place in the period corresponding
// to the same period in which the employees were hired, they must benefit from the increase in their base index
it(`POST /PAYROLL_CONFIG should Payroll Configuration Year+2 + One month for Checking
the increase in base indices when creating a futuristic pay period`, () => {
return agent.post('/payroll_config')
.send(payrollConfigYearPlus2Month)
.then((res) => {
payrollConfigYearPlus2Month.id = res.body.id;
helpers.api.created(res);

// This test must verify that the two configured employees must benefit from
// the increase in their base index for two years the first employee has a base index of 69
// with a rate of 5% in accordance with his date of hire and his last configuration
// its index after configuring the new pay period must be 76

// And the second employee has a base index of 144
// with a rate of 5% in accordance with his date of hire and his last configuration
// its index after configuring the new pay period must be 160

return agent.get('/staffing_indices')
.then(res2 => {
expect(res2).to.have.status(200);
expect(res2.body).to.be.an('array');

let checkIncrementationGradeIndice = 0;

res2.body.forEach(element => {
if (element.grade_indice === 160) {
// For the following example the second was hired on february 27, 2022, and
// its last base index dates from February 27, 2024 and it is 138
// The pay period is January 2026
// The system will first calculate their year of seniority in relation to the pay period
// Seniority = (2026-01-31) - (2022-02-27) is equal to 3 years (1)
// Last increment = (2026-01-31) - (2024-02-27) is equal to 2 years (2)
// Base Index Growth Rate being 5%, the base index of this employee will be increased in
// accordance with the difference in years (1)-(2) => 3 years - 2 years = 1 year
// - Year 1: 138 + (138 x 0.05) = 144.9 which the system will round to 145
if (element.grade_indice === 145) {
checkIncrementationGradeIndice++;
}

if (element.grade_indice === 76) {
checkIncrementationGradeIndice++;
}
});

expect(checkIncrementationGradeIndice).to.equal(2);
expect(res2.body).to.have.length(11);
expect(6).to.equal(11);
expect(res2.body).to.have.length(9);
})
.catch(helpers.handler);
})
Expand Down

0 comments on commit 8d5d70b

Please sign in to comment.