forked from org-nexus-projects/ufabc-next-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Add unit tests to coefficients calc #4
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
Closed
Closed
Changes from 22 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
8132017
add template
KleversonNascimento e84069f
Update pull_request_template.md
KleversonNascimento 447244a
Atualizando README.md do ufabc-next-server
hadeoliveira ee70af1
Create user info route test
vitordiricio af9689a
teste
KleversonNascimento 1068e67
add test to coefficients calc
KleversonNascimento bfbc822
remove only condittion
KleversonNascimento 9d758f1
remove old change
KleversonNascimento 771659d
teste
KleversonNascimento 4c0bfa7
add unit tests workflow
KleversonNascimento 98f53b4
test
KleversonNascimento 3a2eb99
test
KleversonNascimento 35066fa
test
KleversonNascimento 740ca06
test
KleversonNascimento 2468cb0
test
KleversonNascimento 8e6e6ac
change pr trigger
KleversonNascimento ada1361
change step names
KleversonNascimento 942968e
change job name
KleversonNascimento cf49b29
rebase
KleversonNascimento 13bc61f
use ssh
KleversonNascimento cc9c17d
fix yarn lock
KleversonNascimento 8cbb3eb
Revert "fix yarn lock"
KleversonNascimento 0f94b59
Revert "use ssh"
KleversonNascimento bf4a55d
use yarn
KleversonNascimento e6fe173
fix format
KleversonNascimento 169426c
teste
KleversonNascimento 53b69c3
fix lint questions
KleversonNascimento e06bb8a
add to workflow
KleversonNascimento 668d14e
split steps
KleversonNascimento 8f0ee41
finish
KleversonNascimento 1cf4aab
rebase
KleversonNascimento a1add3c
Atualizando com correções no README
hadeoliveira b40923d
Fix and skip broken tests
felipetiozo 976f543
Merge pull request #100 from ufabc-next/fix/broken-tests
felipetiozo 66bbe74
Merge pull request #97 from UFABCNextOps/update-readme-server
felipetiozo 9b3f8a9
Merge pull request #99 from vitordiricio/tests/add-users-info-test
felipetiozo b9fde92
Merge pull request #96 from UFABCNextOps/pr-template
felipetiozo 0f0b574
Merge pull request #6 from UFABCNextOps/init-ci
felipetiozo 00901ef
Add unit tests to POST /v1/comments route
felipetiozo dc29584
Remove unnecessary .only
felipetiozo 3649ac4
Merge pull request #101 from ufabc-next/feature/comments-tests
felipetiozo ca30ecb
Merge branch 'ufabc-next:master' into master
hadeoliveira bd8cc12
Inclusao do teste unitario referente ao helpers/season/findIdeais
hadeoliveira 6f60763
Fix: Correção de validação do teste
hadeoliveira 711a695
Fix: correção dos teste findIdeais
hadeoliveira 67d9640
Merge pull request #102 from UFABCNextOps/unit-tests-helpers
felipetiozo 3f69ea3
Merge pull request #9 from UFABCNextOps/init-lint
KleversonNascimento 9419cea
apply suggestions
KleversonNascimento 83cc3e1
change export
KleversonNascimento 3c98d4e
fix tests
KleversonNascimento 7873c5c
Merge branch 'master' into add-some-tests
KleversonNascimento af8905b
fix lint
KleversonNascimento bb4bb8c
remove unused import
KleversonNascimento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Unit tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - edited | ||
| - synchronize | ||
|
|
||
| jobs: | ||
| unit-tests: | ||
| timeout-minutes: 10 | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v1 | ||
|
|
||
| - name: Install Yarn | ||
| run: npm install -g yarn | ||
|
|
||
| - name: Start docker containers | ||
| run: cd app && docker-compose -f "docker-compose.yaml" up -d --build | ||
|
|
||
| - name: Install node | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: 16.x | ||
|
|
||
| - name: Install dependencies | ||
| run: cd app && yarn install | ||
|
|
||
| - name: Run unit tests | ||
| run: cd app && yarn run test | ||
|
|
||
| - name: Stop docker containers | ||
| if: always() | ||
| run: cd app && docker-compose -f "docker-compose.yaml" down |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| const assert = require('assert') | ||
|
|
||
| const func = require('./coefficients') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Boa, mudei |
||
|
|
||
| describe('helpers.calculate.coefficients', function () { | ||
| describe('isAprovado', function () { | ||
| it('should return true when student is approved', function () { | ||
| assert.equal(true, func.isAprovado('A')) | ||
| assert.equal(true, func.isAprovado('B')) | ||
| assert.equal(true, func.isAprovado('C')) | ||
| assert.equal(true, func.isAprovado('D')) | ||
| }) | ||
|
|
||
| it('should return false when student is not approved', function () { | ||
| assert.equal(false, func.isAprovado('F')) | ||
| assert.equal(false, func.isAprovado('O')) | ||
| assert.equal(false, func.isAprovado('I')) | ||
| }) | ||
| }) | ||
|
|
||
| describe('parseCategory', function () { | ||
| it('should return correct category', function () { | ||
| assert.equal('free', func.parseCategory('Livre Escolha')) | ||
| assert.equal('mandatory', func.parseCategory('Obrigatória')) | ||
| assert.equal('limited', func.parseCategory('Opção Limitada')) | ||
| assert.equal(null, func.parseCategory('invalid category')) | ||
| }) | ||
| }) | ||
|
|
||
| describe('convertGradeToNumber', function () { | ||
| it('should return correct number', function () { | ||
| assert.equal(4, func.convertGradeToNumber('A')) | ||
| assert.equal(1, func.convertGradeToNumber('D')) | ||
| assert.equal(0, func.convertGradeToNumber('F')) | ||
| assert.equal(0, func.convertGradeToNumber('O')) | ||
| assert.equal(-1, func.convertGradeToNumber('E')) | ||
| assert.equal(-1, func.convertGradeToNumber('I')) | ||
| }) | ||
| }) | ||
|
|
||
| describe('calculateAlunoCoefficientsData', function () { | ||
| it('should return correct cp accumulated', function () { | ||
| const result = func.calculateAlunoCoefficientsData(mockedDisciplines, mockedGraduation) | ||
| assert.equal(0.089, result['2020'][3].cp_acumulado) | ||
| assert.equal(0.211, result['2021'][1].cp_acumulado) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| const mockedDisciplines = [{ | ||
| ano: 2020, | ||
| periodo: 3, | ||
| creditos: 3, | ||
| categoria: 'Obrigatória' | ||
| }, | ||
| { | ||
| ano: 2020, | ||
| periodo: 3, | ||
| creditos: 5, | ||
| categoria: 'Livre Escolha' | ||
| }, | ||
| { | ||
| ano: 2020, | ||
| periodo: 3, | ||
| creditos: 5, | ||
| categoria: 'Obrigatória' | ||
| }, | ||
| { | ||
| ano: 2020, | ||
| periodo: 3, | ||
| creditos: 4, | ||
| categoria: 'Opção Limitada' | ||
| }, | ||
| { | ||
| ano: 2021, | ||
| periodo: 1, | ||
| creditos: 5, | ||
| categoria: 'Obrigatória' | ||
| }, | ||
| { | ||
| ano: 2021, | ||
| periodo: 1, | ||
| creditos: 3, | ||
| categoria: 'Opção Limitada' | ||
| }, | ||
| { | ||
| ano: 2021, | ||
| periodo: 1, | ||
| creditos: 5, | ||
| categoria: 'Obrigatória' | ||
| }, | ||
| { | ||
| ano: 2021, | ||
| periodo: 1, | ||
| creditos: 2, | ||
| categoria: 'Opção Limitada' | ||
| }, | ||
| { | ||
| ano: 2021, | ||
| periodo: 1, | ||
| creditos: 3, | ||
| categoria: 'Livre Escolha' | ||
| }, | ||
| { | ||
| ano: 2021, | ||
| periodo: 1, | ||
| creditos: 5, | ||
| categoria: 'Opção Limitada' | ||
| }, | ||
| ] | ||
|
|
||
| const mockedGraduation = { | ||
| credits_total: 190, | ||
| limited_credits_number: 70, | ||
| free_credits_number: 30, | ||
| mandatory_credits_number: 90 | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: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 especificafunc.isAprovado()There was a problem hiding this comment.
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: org-nexus-projects#103