Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adiciona feriado nacional do dia da consciência negra a partir de 2024 #567

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui não deveria ser 2023?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como estou verificando se o array não contém, uso o getHolidays pra buscar os feriados de 2024 e filtro somente o "Dia da consciência negra", não consegui pensar em outra maneira de validar.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pelo que entendi a lógica está correta, mas em 2024 o dia deveria estar presente, não?
Ou seja, em 2023 não teria o dia em questão e 2024 teria, me diga se eu estiver comendo bola... rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pra validar eu fiz 2 testes, nesse caso de teste em específico estou buscando os feriados de 2023 na API e depois verifico se não contém o feriado "Dia da consciência negra", tem outro teste que verifica para esse caso de 2024 que você mencionou, onde eu busco os feriados de 2024 na API, filtro o "Dia da consciência negra" usando o getHolidays e uso o expect.arrayContaining para validar.

)
);
});

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
Loading