Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
60 changes: 60 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Unit tests & lint

on:
push:
branches:
- master
pull_request:
types:
- opened
- edited
- synchronize

jobs:
lint:
timeout-minutes: 5
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

- name: Install node
uses: actions/setup-node@v1
with:
node-version: 16.x

- name: Install dependencies
run: npm install

- name: Check lint
run: npm run lint

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
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/c6cd37818d9c4ab6b244bfefd5b83597)](https://www.codacy.com/app/fesnt/ufabc-matricula-server?utm_source=github.com&utm_medium=referral&utm_content=ufabc-next/ufabc-matricula-server&utm_campaign=Badge_Grade)
[![codecov](https://codecov.io/gh/ufabc-next/ufabc-matricula-server/branch/master/graph/badge.svg)](https://codecov.io/gh/ufabc-next/ufabc-matricula-server)

Back-end server in Node.js for UFABC Next services.
### Para executar o server

- Entrar em ufabc-next-server/app e executar o `yarn install`:
- Instalar o **Docker** e o **Docker Compose**
- Dentro de ufabc-next-server/app, como administrador, executar `docker-compose up -d`
- Para iniciar o servidor, executar como `yarn start:watch` a fim de verificar quando um arquivo for atualizado. Dessa forma, o servidor reiniciará automaticamente

### Testes

.
- Para popular o Banco de Dados com uma massa de dados padrão, executar o `yarn populate both`
- `yarn test` para executar os testes unitários

Back-end server in Node.js for UFABC Next services.
35 changes: 22 additions & 13 deletions app/api/comment/create/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ const errors = require('@/errors')
const Fields = require('@/api/comment/Fields')
const pickFields = require('@/helpers/parse/pickFields')

module.exports = async function(context){
module.exports = async function (context) {
const Comment = app.models.comments
const Enrollment = app.models.enrollments

app.helpers.validate.throwMissingParameter(['enrollment', 'comment', 'type'], context.body)
app.helpers.validate.throwMissingParameter(
['enrollment', 'comment', 'type'],
context.body
)

let enrollment = await Enrollment.findById(String(context.body.enrollment))

if(!enrollment) throw new errors.BadRequest(`Este vínculo não existe: ${enrollment.id}`)
if (!enrollment)
throw new errors.BadRequest(
`Este vínculo não existe: ${context.body.enrollment}`
)

return pickFields(await Comment.create({
comment: String(context.body.comment),
type: context.body.type,
enrollment: enrollment.id,
teacher: enrollment[context.body.type],
disciplina: enrollment.disciplina,
subject: enrollment.subject,
ra: enrollment.ra
}), Fields)
}
return pickFields(
await Comment.create({
comment: String(context.body.comment),
type: context.body.type,
enrollment: enrollment.id,
teacher: enrollment[context.body.type],
disciplina: enrollment.disciplina,
subject: enrollment.subject,
ra: enrollment.ra,
}),
Fields
)
}
68 changes: 68 additions & 0 deletions app/api/comment/create/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const app = require('@/app')
const func = require('./func')
const assert = require('assert')
const populate = require('@/populate')

describe('POST /v1/comments', async function () {
let models
let context
let enrollment
beforeEach(async function () {
models = await populate({
operation: 'both',
only: ['enrollments', 'teachers', 'subjects', 'comments'],
})

enrollment = models.enrollments[0]
context = {
body: {
enrollment: enrollment._id,
comment: 'Some comment',
type: 'pratica',
},
}
})
describe('func', async function () {
describe('with valid params', async function () {
it('create and return a filtered comment', async function () {
const resp = await func(context)

assert(resp._id)
assert.equal(resp.comment, context.body.comment)
assert(resp.createdAt)
assert(new Date() > resp.createdAt)
assert.equal(resp.enrollment._id, context.body.enrollment)
assert.equal(resp.subject, enrollment.subject)
assert.equal(resp.teacher, enrollment.mainTeacher)
assert.notEqual(resp.ra, enrollment.ra)

const Comment = app.models.comments
const comment = await Comment.findOne({ _id: resp._id })
assert(comment)
})
})
describe('with invalid params', async function () {
it('should throw if enrollment is missing', async function () {
delete context.body.enrollment
await assertFuncThrows('MissingParameter', func, context)
})
it('should throw if comment is missing', async function () {
delete context.body.comment
await assertFuncThrows('MissingParameter', func, context)
})
it('should throw if type is missing', async function () {
delete context.body.type
await assertFuncThrows('MissingParameter', func, context)
})
it('should throw if enrollment is invalid', async function () {
// Invalid enrollment id
context.body.enrollment = models.comments[0]._id
await assertFuncThrows('BadRequest', func, context)
})
it('should throw if is a duplicated comment', async function () {
await func(context)
await assertFuncThrows('BadRequest', func, context)
})
})
})
})
88 changes: 44 additions & 44 deletions app/api/disciplinas/disciplinaId/kicks/func.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
const _ = require("lodash");
const app = require("@/app");
const errors = require("@/errors");
const _ = require('lodash')
const app = require('@/app')
const errors = require('@/errors')

module.exports = async function (context) {
let { disciplinaId } = context.params;
let { sort } = context.query;
let { disciplinaId } = context.params
let { sort } = context.query

if (!disciplinaId) {
throw new errors.BadRequest.MissingParameter("disciplinaId");
throw new errors.BadRequest.MissingParameter('disciplinaId')
}

const season = app.helpers.season.findSeasonKey();
const Disciplinas = app.models.disciplinas.bySeason(season);
const Alunos = app.models.alunos.bySeason(season);
const findId = app.helpers.courses.findId;
const season = app.helpers.season.findSeasonKey()
const Disciplinas = app.models.disciplinas.bySeason(season)
const Alunos = app.models.alunos.bySeason(season)
const findId = app.helpers.courses.findId

// find disciplina
let disciplina = await Disciplinas.findOne({ disciplina_id: disciplinaId });
let disciplina = await Disciplinas.findOne({ disciplina_id: disciplinaId })

if (!disciplina) {
throw new errors.NotFound("disciplina");
throw new errors.NotFound('disciplina')
}

// create sort mechanism
const kicks = sort ? sort : kickRule(disciplina);
const order = Array(kicks.length || 0).fill("desc");
const kicks = sort ? sort : kickRule(disciplina)
const order = Array(kicks.length || 0).fill('desc')

// turno must have a special treatment
const turnoIndex = kicks.indexOf("turno");
const turnoIndex = kicks.indexOf('turno')
if (turnoIndex != -1) {
order[turnoIndex] = disciplina.turno == "diurno" ? "asc" : "desc";
order[turnoIndex] = disciplina.turno == 'diurno' ? 'asc' : 'desc'
}

const isAfterKick = _(disciplina.after_kick).castArray().compact().value()
.length;
const result = resolveMatriculas(disciplina, isAfterKick);
.length
const result = resolveMatriculas(disciplina, isAfterKick)

const resultMap = new Map([...result.map((r) => [r.aluno_id, r])]);
const resultMap = new Map([...result.map((r) => [r.aluno_id, r])])
let students = await Alunos.aggregate([
{ $match: { aluno_id: { $in: _.map(result, "aluno_id") } } },
{ $unwind: "$cursos" },
]);
{ $match: { aluno_id: { $in: _.map(result, 'aluno_id') } } },
{ $unwind: '$cursos' },
])

const interIds = [
await findId("Bacharelado em Ciência e Tecnologia", season),
await findId("Bacharelado em Ciência e Humanidades", season),
];
await findId('Bacharelado em Ciência e Tecnologia', season),
await findId('Bacharelado em Ciência e Humanidades', season),
]

const obrigatorias = _.pull(disciplina.obrigatorias, ...interIds);
const obrigatorias = _.pull(disciplina.obrigatorias, ...interIds)

students = students.map((s) => {
const reserva = _.includes(obrigatorias, s.cursos.id_curso);
const reserva = _.includes(obrigatorias, s.cursos.id_curso)

return _.extend(
{
Expand All @@ -63,46 +63,46 @@ module.exports = async function (context) {
curso: s.cursos.nome_curso,
},
resultMap.get(s.aluno_id) || {}
);
});
)
})

return _(students).orderBy(kicks, order).uniqBy("aluno_id").value();
};
return _(students).orderBy(kicks, order).uniqBy('aluno_id').value()
}

function kickRule(disciplina) {
const season = app.helpers.season.findSeasonKey();
let coeffRule = null;
const season = app.helpers.season.findSeasonKey()
let coeffRule = null
if (
season == "2020:2" ||
season == "2020:3" ||
season == "2021:1" ||
season == "2021:2" ||
season == "2021:3"
season == '2020:2' ||
season == '2020:3' ||
season == '2021:1' ||
season == '2021:2' ||
season == '2021:3'
) {
coeffRule = ["cp", "cr"];
coeffRule = ['cp', 'cr']
} else {
coeffRule = disciplina.ideal_quad ? ["cr", "cp"] : ["cp", "cr"];
coeffRule = disciplina.ideal_quad ? ['cr', 'cp'] : ['cp', 'cr']
}
return ["reserva", "turno", "ik"].concat(coeffRule);
return ['reserva', 'turno', 'ik'].concat(coeffRule)
}

function resolveMatriculas(disciplina, isAfterKick) {
// if kick has not arrived, not one has been kicked
if (!isAfterKick) {
return (disciplina.alunos_matriculados || []).map((d) => ({
aluno_id: d,
}));
}))
}

// check diff between before_kick and after_kick
let kicked = _.difference(
disciplina.before_kick || [],
disciplina.after_kick || []
);
)

// return who has been kicked
return disciplina.before_kick.map((d) => ({
aluno_id: d,
kicked: kicked.includes(d),
}));
}))
}
Loading