Skip to content

Commit

Permalink
Merge pull request #567 from joaovitors1g/main
Browse files Browse the repository at this point in the history
Adiciona feriado nacional do dia da consciência negra a partir de 2024
  • Loading branch information
lucianopf committed Apr 30, 2024
2 parents 324fcfd + 18228a7 commit b23cb02
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
8 changes: 8 additions & 0 deletions services/holidays/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export function getNationalHolidays(year) {
['11-15', 'Proclamação da República'],
['12-25', 'Natal'],
];

if (year >= 2024) {
fixedHolidays.splice(fixedHolidays.length - 1, 0, [
'11-20',
'Dia da consciência negra',
]);
}

return fixedHolidays.map(([date, name]) => ({
date: `${year}-${date}`,
name,
Expand Down
26 changes: 26 additions & 0 deletions tests/feriados-v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,30 @@ describe('/feriados/v1 (E2E)', () => {
expect.arrayContaining(getHolidays(2019, ['Páscoa', 'Tiradentes']))
);
});

test('Feriado da consciência negra não deve existir em ano anterior a 2024', async () => {
expect.assertions(2);

const requestUrl = `${global.SERVER_URL}/api/feriados/v1/2023`;
const { data } = await axios.get(requestUrl);

expect(data).toHaveLength(12);
expect(data).toEqual(
expect.not.arrayContaining(
getHolidays(2024, ['Dia da consciência negra'])
)
);
});

test('Feriado da consciência negra deve existir a partir de 2024', async () => {
expect.assertions(2);

const requestUrl = `${global.SERVER_URL}/api/feriados/v1/2024`;
const { data } = await axios.get(requestUrl);

expect(data).toHaveLength(13);
expect(data).toEqual(
expect.arrayContaining(getHolidays(2024, ['Dia da consciência negra']))
);
});
});
18 changes: 15 additions & 3 deletions tests/helpers/feriados/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const fixedHolidaysName = [
'Nossa Senhora Aparecida',
'Finados',
'Proclamação da República',
'Dia da consciência negra',
'Natal',
];

Expand Down Expand Up @@ -61,8 +62,8 @@ const getEasterHolidays = (year, holidaysName = easterHolidaysName) =>
},
].filter(({ name }) => holidaysName.includes(name));

const getFixedHolidays = (year, holidaysName = fixedHolidaysName) =>
[
const getFixedHolidays = (year, holidaysName = fixedHolidaysName) => {
const holidays = [
{
date: `${year}-01-01`,
name: 'Confraternização mundial',
Expand Down Expand Up @@ -103,7 +104,18 @@ const getFixedHolidays = (year, holidaysName = fixedHolidaysName) =>
name: 'Natal',
type: 'national',
},
].filter(({ name }) => holidaysName.includes(name));
];

if (year >= 2024) {
holidays.splice(holidays.length - 1, 0, {
date: `${year}-11-20`,
name: 'Dia da consciência negra',
type: 'national',
});
}

return holidays.filter(({ name }) => holidaysName.includes(name));
};

const getHolidays = (
year,
Expand Down

0 comments on commit b23cb02

Please sign in to comment.