Skip to content

Add unit tests to coefficients calc#4

Closed
KleversonNascimento wants to merge 53 commits intoremove-fleak-testsfrom
add-some-tests
Closed

Add unit tests to coefficients calc#4
KleversonNascimento wants to merge 53 commits intoremove-fleak-testsfrom
add-some-tests

Conversation

@KleversonNascimento
Copy link
Copy Markdown

Change Request

Description

Add unit tests to methods that calculate coefficients

How do I test this?

yarn test

Checklist

  • I have performed a self-review of my own code;
  • I have added tests that prove my fix is effective or that my feature works;
  • Add labels to distinguish the pull request. For example bug, ready to review etc.

Comment thread app/helpers/calculate/coefficients.js Outdated

return null
} No newline at end of file
module.exports = {calculateAlunoCoefficientsData, isAprovado, convertGradeToNumber, parseCategory} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deixar o module.exports exportando dessa forma pode quebrar outros lugares que importam esse arquivo e esperam uma função diretamente (como no app/agenda/processors/enrollments/updateUserEnrollments.js#L24). Nesse caso para conseguir testar essas funções menores, como o convertGradeToNumber, voce pode dar um export exclusivo nela e ainda sim manter module.exports exportando a função principal. Então ficando:

module.exports.parseCategory = function parseCategory(category) {
  if (category === "Livre Escolha") return "free";
  else if (category === "Obrigatória") return "mandatory";
  else if (category === "Opção Limitada") return "limited";

  return null;
};

E dentro do teste, voce consegue acessar da mesma maneira, com excessão da função principal que voce pode chamar direto func() sem precisar acessar alguma chave especifica func.isAprovado()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Valeu! Corrigi e abri o PR com essa e as outras alterações em: ufabc-next#103

@@ -0,0 +1,117 @@
const assert = require('assert')

const func = require('./coefficients')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nesse caso, não estamos tratando de uma func, então poderia ser chamado de coefficients mesmo

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Boa, mudei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants