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

Unit tests CI + Lint CI + Coefficients calc unit tests #103

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ed506ff
Update README.md
JhonataSantana Nov 19, 2021
87d4107
Update README.md
JhonataSantana Nov 19, 2021
91d89d4
Update README.md
JhonataSantana Nov 19, 2021
047d249
Update README.md
JhonataSantana Nov 19, 2021
b62c89e
Merge branch 'ufabc-next:master' into master
hadeoliveira Nov 26, 2021
c57d0ee
Update README.md
JhonataSantana Nov 26, 2021
dc8338d
Update README.md
JhonataSantana Nov 26, 2021
2c872a7
Create test.yml
JhonataSantana Nov 28, 2021
658f4cc
Update README.md
JhonataSantana Nov 29, 2021
2594644
Merge branch 'ufabc-next:master' into master
hadeoliveira Dec 5, 2021
b14f074
Delete test.yml
JhonataSantana Dec 8, 2021
e1b4587
Create coverage.yml
JhonataSantana Dec 8, 2021
534e7f5
Merge branch 'ufabc-next:master' into master
hadeoliveira Dec 8, 2021
d9fe8e7
Coverage command repair
JhonataSantana Dec 8, 2021
7ca1f4a
add test
KleversonNascimento Dec 8, 2021
e7c43ee
teste
KleversonNascimento Oct 26, 2021
ee02954
remove old changes
KleversonNascimento Oct 27, 2021
dd88615
teste
KleversonNascimento Oct 26, 2021
4a5bef5
add test to coefficients calc
KleversonNascimento Oct 27, 2021
1c7587e
remove only condittion
KleversonNascimento Oct 27, 2021
e4af359
remove old change
KleversonNascimento Oct 27, 2021
b8dd66f
teste
KleversonNascimento Oct 26, 2021
6161fe1
add unit tests workflow
KleversonNascimento Oct 27, 2021
65a6c83
test
KleversonNascimento Oct 27, 2021
06065b7
test
KleversonNascimento Oct 27, 2021
6042c6b
test
KleversonNascimento Oct 27, 2021
1b6a438
test
KleversonNascimento Oct 27, 2021
8316ec1
test
KleversonNascimento Oct 27, 2021
bcf6ee5
change pr trigger
KleversonNascimento Oct 27, 2021
fc6a2b2
change step names
KleversonNascimento Oct 27, 2021
133e06e
change job name
KleversonNascimento Oct 27, 2021
482c1a8
rebase
KleversonNascimento Oct 27, 2021
4ee75e9
use ssh
KleversonNascimento Oct 27, 2021
6b20634
fix yarn lock
KleversonNascimento Oct 27, 2021
a14f16b
Revert "fix yarn lock"
KleversonNascimento Oct 27, 2021
d039b1f
Revert "use ssh"
KleversonNascimento Oct 27, 2021
0c08b78
use yarn
KleversonNascimento Oct 27, 2021
c0bc329
fix format
KleversonNascimento Oct 27, 2021
e0d6fff
teste
KleversonNascimento Oct 26, 2021
296e9b7
fix lint questions
KleversonNascimento Oct 27, 2021
b363f68
add to workflow
KleversonNascimento Oct 27, 2021
524966b
split steps
KleversonNascimento Oct 27, 2021
b36112f
finish
KleversonNascimento Oct 27, 2021
aae81e1
rebase
KleversonNascimento Oct 27, 2021
9b25b2e
apply suggestions
KleversonNascimento Nov 4, 2021
e7ac8a7
change export
KleversonNascimento Nov 4, 2021
d827385
fix tests
KleversonNascimento Nov 5, 2021
fd1fe28
fix lint
KleversonNascimento Nov 5, 2021
8904a56
remove unused import
KleversonNascimento Nov 5, 2021
359b5bc
remove unused changes
KleversonNascimento Dec 8, 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
24 changes: 12 additions & 12 deletions app/api/comment/create/func.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const app = require("@/app");
const errors = require("@/errors");
const Fields = require("@/api/comment/Fields");
const pickFields = require("@/helpers/parse/pickFields");
const app = require('@/app')
const errors = require('@/errors')
const Fields = require('@/api/comment/Fields')
const pickFields = require('@/helpers/parse/pickFields')

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

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

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

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

return pickFields(
await Comment.create({
Expand All @@ -30,5 +30,5 @@ module.exports = async function (context) {
ra: enrollment.ra,
}),
Fields
);
};
)
}
114 changes: 57 additions & 57 deletions app/api/comment/create/spec.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
const app = require("@/app");
const func = require("./func");
const assert = require("assert");
const populate = require("@/populate");
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;
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"],
});
operation: 'both',
only: ['enrollments', 'teachers', 'subjects', 'comments'],
})

enrollment = models.enrollments[0];
enrollment = models.enrollments[0]
context = {
body: {
enrollment: enrollment._id,
comment: "Some comment",
type: "pratica",
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);
}
})
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);
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 () {
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);
});
});
});
});
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)
})
})
})
})
78 changes: 39 additions & 39 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,15 +63,15 @@ 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" ||
Expand All @@ -80,30 +80,30 @@ function kickRule(disciplina) {
season == "2021:3" ||
season == "2022:1"
) {
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