Skip to content
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8132017
add template
KleversonNascimento Oct 21, 2021
e84069f
Update pull_request_template.md
KleversonNascimento Oct 21, 2021
447244a
Atualizando README.md do ufabc-next-server
hadeoliveira Oct 26, 2021
ee70af1
Create user info route test
vitordiricio Oct 27, 2021
af9689a
teste
KleversonNascimento Oct 26, 2021
1068e67
add test to coefficients calc
KleversonNascimento Oct 27, 2021
bfbc822
remove only condittion
KleversonNascimento Oct 27, 2021
9d758f1
remove old change
KleversonNascimento Oct 27, 2021
771659d
teste
KleversonNascimento Oct 26, 2021
4c0bfa7
add unit tests workflow
KleversonNascimento Oct 27, 2021
98f53b4
test
KleversonNascimento Oct 27, 2021
3a2eb99
test
KleversonNascimento Oct 27, 2021
35066fa
test
KleversonNascimento Oct 27, 2021
740ca06
test
KleversonNascimento Oct 27, 2021
2468cb0
test
KleversonNascimento Oct 27, 2021
8e6e6ac
change pr trigger
KleversonNascimento Oct 27, 2021
ada1361
change step names
KleversonNascimento Oct 27, 2021
942968e
change job name
KleversonNascimento Oct 27, 2021
cf49b29
rebase
KleversonNascimento Oct 27, 2021
13bc61f
use ssh
KleversonNascimento Oct 27, 2021
cc9c17d
fix yarn lock
KleversonNascimento Oct 27, 2021
8cbb3eb
Revert "fix yarn lock"
KleversonNascimento Oct 27, 2021
0f94b59
Revert "use ssh"
KleversonNascimento Oct 27, 2021
bf4a55d
use yarn
KleversonNascimento Oct 27, 2021
e6fe173
fix format
KleversonNascimento Oct 27, 2021
169426c
teste
KleversonNascimento Oct 26, 2021
53b69c3
fix lint questions
KleversonNascimento Oct 27, 2021
e06bb8a
add to workflow
KleversonNascimento Oct 27, 2021
668d14e
split steps
KleversonNascimento Oct 27, 2021
8f0ee41
finish
KleversonNascimento Oct 27, 2021
1cf4aab
rebase
KleversonNascimento Oct 27, 2021
a1add3c
Atualizando com correções no README
hadeoliveira Oct 27, 2021
b40923d
Fix and skip broken tests
felipetiozo Oct 27, 2021
976f543
Merge pull request #100 from ufabc-next/fix/broken-tests
felipetiozo Oct 27, 2021
66bbe74
Merge pull request #97 from UFABCNextOps/update-readme-server
felipetiozo Oct 27, 2021
9b3f8a9
Merge pull request #99 from vitordiricio/tests/add-users-info-test
felipetiozo Oct 28, 2021
b9fde92
Merge pull request #96 from UFABCNextOps/pr-template
felipetiozo Oct 28, 2021
0f0b574
Merge pull request #6 from UFABCNextOps/init-ci
felipetiozo Oct 28, 2021
00901ef
Add unit tests to POST /v1/comments route
felipetiozo Oct 28, 2021
dc29584
Remove unnecessary .only
felipetiozo Oct 28, 2021
3649ac4
Merge pull request #101 from ufabc-next/feature/comments-tests
felipetiozo Oct 28, 2021
ca30ecb
Merge branch 'ufabc-next:master' into master
hadeoliveira Oct 28, 2021
bd8cc12
Inclusao do teste unitario referente ao helpers/season/findIdeais
hadeoliveira Oct 30, 2021
6f60763
Fix: Correção de validação do teste
hadeoliveira Oct 31, 2021
711a695
Fix: correção dos teste findIdeais
hadeoliveira Nov 3, 2021
67d9640
Merge pull request #102 from UFABCNextOps/unit-tests-helpers
felipetiozo Nov 4, 2021
3f69ea3
Merge pull request #9 from UFABCNextOps/init-lint
KleversonNascimento Nov 4, 2021
9419cea
apply suggestions
KleversonNascimento Nov 4, 2021
83cc3e1
change export
KleversonNascimento Nov 4, 2021
3c98d4e
fix tests
KleversonNascimento Nov 5, 2021
7873c5c
Merge branch 'master' into add-some-tests
KleversonNascimento Nov 5, 2021
af8905b
fix lint
KleversonNascimento Nov 5, 2021
bb4bb8c
remove unused import
KleversonNascimento Nov 5, 2021
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
41 changes: 41 additions & 0 deletions .github/workflows/unit_tests.yml
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
49 changes: 29 additions & 20 deletions app/helpers/calculate/coefficients.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const math = require('mathjs')
const _ = require('lodash')

module.exports = function calculateAlunoCoefficientsData(disciplinas, graduation) {
function calculateAlunoCoefficientsData(disciplinas, graduation) {

var hash_disciplinas = {}
disciplinas.forEach(function (disciplina) {
Expand Down Expand Up @@ -36,7 +36,7 @@ module.exports = function calculateAlunoCoefficientsData(disciplinas, graduation
for(let disciplina in hash_disciplinas[year][period]) {
var current_disciplina = hash_disciplinas[year][period][disciplina]
var creditos = parseInt(current_disciplina.creditos)
var convertable = convertLetterToNumber(current_disciplina.conceito) * creditos
var convertable = convertGradeToNumber(current_disciplina.conceito) * creditos

const category = parseCategory(current_disciplina.categoria)

Expand Down Expand Up @@ -113,27 +113,36 @@ module.exports = function calculateAlunoCoefficientsData(disciplinas, graduation
return hash_disciplinas
}

function isAprovado (letter) {
if(letter !== 'F' && letter !== '0' && letter !== 'O' && letter !== 'I') return true
function isAprovado (grade) {
const disapprovingGrades = ['F', '0', 'O', 'I']

return !disapprovingGrades.includes(grade)
}

function convertLetterToNumber(letter) {
if(letter === 'A') return 4
else if(letter === 'B') return 3
else if(letter === 'C') return 2
else if(letter === 'D') return 1
else if(letter === 'F') return 0
else if(letter === 'O') return 0

else if(letter === '-') return -1
else if(letter === 'E') return -1
else if(letter === 'I') return -1
function convertGradeToNumber(grade) {
const gradeToNumberMap = {
'A': 4,
'B': 3,
'C': 2,
'D': 1,
'F': 0,
'O': 0,
'-': -1,
'E': -1,
'I': -1
}

return gradeToNumberMap[grade]
}

function parseCategory(category) {
if(category === 'Livre Escolha') return 'free'
else if(category === 'Obrigatória') return 'mandatory'
else if(category === 'Opção Limitada') return 'limited'
const categoryParser = {
'Livre Escolha': 'free',
'Obrigatória': 'mandatory',
'Opção Limitada': 'limited'
}

return categoryParser[category]
}

return null
}
module.exports = {calculateAlunoCoefficientsData, isAprovado, convertGradeToNumber, parseCategory}

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: org-nexus-projects#103

117 changes: 117 additions & 0 deletions app/helpers/calculate/coefficients.spec.js
Original file line number Diff line number Diff line change
@@ -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


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
}