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

Teste Unitário resolveProfessor.spec.js #110

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
47 changes: 47 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Coverage

on:
push:
pull_request:

jobs:
build:

runs-on: ubuntu-latest

env:
CODECOV_TOKEN: 613992d7-a6fc-4f73-8b0f-bfbe632ff352

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

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install and Run Yarn
run: npm install -g yarn && cd app && yarn

- name: Install NYC
run: npm install -D nyc --save-dev -g

- name: Start Docker Containers
run: cd app && docker-compose -f "docker-compose.yaml" up -d --build

- name: Install Dependendcies
run: cd app && yarn install

- name: Run Tests and Generate Coverage Report
run: cd app && nyc npm run test && nyc report --reporter=text-lcov > coverage.lcov

- name: Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
files: ./app/coverage.lcov

- name: Stop Docker Containers
run: cd app && docker-compose -f "docker-compose.yaml" down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# ufabc-next-server

[![Build Status](https://travis-ci.com/ufabc-next/ufabc-matricula-server.svg?branch=master)](https://travis-ci.com/ufabc-next/ufabc-matricula-server)
[![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)
<img alt="GitHub Package.json Version" src="https://img.shields.io/github/package-json/v/ufabc-next/ufabc-next-server" /> <img alt="GitHub Top Language" src="https://img.shields.io/github/languages/top/ufabc-next/ufabc-next-server" /> ![GitHub repo size](https://img.shields.io/github/repo-size/UFABCNextOps/ufabc-next-server)

[![Build status](https://ci.appveyor.com/api/projects/status/lsob9vj7eyuejun2?svg=true)](https://ci.appveyor.com/project/JhonataSantana/ufabc-next-server)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/c97a33d865fb4b35b257b538f1661ad7)](https://www.codacy.com/gh/UFABCNextOps/ufabc-next-server/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=UFABCNextOps/ufabc-next-server&amp;utm_campaign=Badge_Grade)
[![codecov](https://codecov.io/gh/UFABCNextOps/ufabc-next-server/branch/master/graph/badge.svg?token=NTRX2LN5T0)](https://codecov.io/gh/UFABCNextOps/ufabc-next-server)

<img alt="Github License" src="https://img.shields.io/github/license/ufabc-next/ufabc-next-server" />

### Para executar o server

Expand Down
114 changes: 57 additions & 57 deletions app/helpers/season/findIdeais.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,69 @@ const findIdeais = require('./findIdeais')

describe('helpers.season.findIdeais', function() {

it('Should return first quad courses', function () {
const expectedCourses = [
'BCM0506-15', // COMUNICACAO E REDES
'BCJ0203-15', // ELETROMAG
'BIN0406-15', // IPE
'BCN0405-15', // IEDO
'BIR0004-15', // EPISTEMOLOGICAS
'BHO0102-15', // DESENVOL. E SUSTE.
'BHO0002-15', // PENSA. ECONOMICO
'BHP0201-15', // TEMAS E PROBLEMAS
'BHO0101-15', // ESTADO E RELA
'BIR0603-15', // CTS
'BHQ0003-15', // INTEPRE. BRASIL
'BHQ0001-15', // IDENT.E CULTURA
]
const date = new Date("2021-04-10")
const func = findIdeais(date)
it('Should return first quad courses', function () {
const expectedCourses = [
'BCM0506-15', // COMUNICACAO E REDES
'BCJ0203-15', // ELETROMAG
'BIN0406-15', // IPE
'BCN0405-15', // IEDO
'BIR0004-15', // EPISTEMOLOGICAS
'BHO0102-15', // DESENVOL. E SUSTE.
'BHO0002-15', // PENSA. ECONOMICO
'BHP0201-15', // TEMAS E PROBLEMAS
'BHO0101-15', // ESTADO E RELA
'BIR0603-15', // CTS
'BHQ0003-15', // INTEPRE. BRASIL
'BHQ0001-15', // IDENT.E CULTURA
]
const date = new Date('2021-04-10')
const func = findIdeais(date)

expectedCourses.forEach(function (course,index) {
assert.equal(course, func[index])
})
expectedCourses.forEach(function (course,index) {
assert.equal(course, func[index])
})
})

it('Should return second quad courses', function () {
const expectedCourses = [
'BCM0504-15', // NI
'BCN0404-15', // GA
'BCN0402-15', // FUV
'BCJ0204-15', // FEMEC
'BCL0306-15', // BIODIVERSIDADE
'BCK0103-15', // QUANTICA
'BCL0308-15', // BIOQUIMICA
'BIQ0602-15', // EDS
'BHO1335-15', // FORMACAO SISTEMA INTERNACIONAL
'BHO1101-15', // INTRODUCAO A ECONOMIA
'BHO0001-15', // INTRODUCAO AS HUMANIDADES
'BHP0202-15', // PENSAMENTO CRITICO
]
const date = new Date("2021-07-10")
const func = findIdeais(date)
it('Should return second quad courses', function () {
const expectedCourses = [
'BCM0504-15', // NI
'BCN0404-15', // GA
'BCN0402-15', // FUV
'BCJ0204-15', // FEMEC
'BCL0306-15', // BIODIVERSIDADE
'BCK0103-15', // QUANTICA
'BCL0308-15', // BIOQUIMICA
'BIQ0602-15', // EDS
'BHO1335-15', // FORMACAO SISTEMA INTERNACIONAL
'BHO1101-15', // INTRODUCAO A ECONOMIA
'BHO0001-15', // INTRODUCAO AS HUMANIDADES
'BHP0202-15', // PENSAMENTO CRITICO
]
const date = new Date('2021-07-10')
const func = findIdeais(date)

expectedCourses.forEach(function (course,index) {
assert.equal(course, func[index])
})
expectedCourses.forEach(function (course,index) {
assert.equal(course, func[index])
})
})

it('Should return third quad courses', function () {
const expectedCourses = [
'BCJ0205-15', // FETERM
'BCM0505-15', // PI
'BCN0407-15', // FVV
'BCL0307-15', // TQ
'BCK0104-15', // IAM
'BIR0603-15', // CTS
'BHP0001-15', // ETICA E JUSTICA
'BHQ0301-15', // TERRITORIO E SOCIEDADE
// ESTUDO ÉTNICOS RACIAIS
]
const date = new Date("2021-11-21")
const func = findIdeais(date)
it('Should return third quad courses', function () {
const expectedCourses = [
'BCJ0205-15', // FETERM
'BCM0505-15', // PI
'BCN0407-15', // FVV
'BCL0307-15', // TQ
'BCK0104-15', // IAM
'BIR0603-15', // CTS
'BHP0001-15', // ETICA E JUSTICA
'BHQ0301-15', // TERRITORIO E SOCIEDADE
// ESTUDO ÉTNICOS RACIAIS
]
const date = new Date('2021-11-21')
const func = findIdeais(date)

expectedCourses.forEach(function (course,index) {
assert.equal(course, func[index])
})
expectedCourses.forEach(function (course,index) {
assert.equal(course, func[index])
})
})
})
33 changes: 33 additions & 0 deletions app/helpers/transform/resolveProfessor.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const assert = require('assert')
const resolveProfessor = require('./resolveProfessor.js')

describe('helpers.transform.resolveProfessor', function() {

it('Should return Missing Teacher error', function () {
const professor = {'name': 'Paulo Meirelles'}
const profProcurado = {'name': 'Joaquin Melo'}

assert.throws(function() {
resolveProfessor(profProcurado, professor, {})
})
})

it('Should return null', function () {
const nullVariable = resolveProfessor('Falso', null, {})
assert.equal(nullVariable, null)
})

it('Should return a professor ', function () {
const professores = [
{name: 'Paulo Meirelles'}, {name: 'Joaquin Melo'},
{name: 'Fabio Carneiro'}, {name: 'Andre Rodrigues'},
{name: 'Igor Mourão'}, {name: 'Bruno Cruz'}]

const profProcurado = 'Joaquin Melo'

const profRetornado = resolveProfessor(profProcurado, professores, {})

assert.equal(profRetornado.name, 'Joaquin Melo')
})

})
21 changes: 21 additions & 0 deletions app/helpers/transform/transformMatriculas.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const assert = require('assert')
const transformMatriculas = require('./transformMatriculas.js')

describe('helpers.transform.transformMatriculas ', function() {

it('Should concat student id in class', function () {
const disciplinas = {
'11066615': ['Funções de Uma Variável', 'Processamento da Informação',
'Engenharia de Software', 'Física Quântica'],
'11075416': ['Funções de Uma Variável', 'Processamento da Informação',
'Laboratório de Engenharia de Software', 'Fenônomenos Eletromagnéticos'],
'11000114': ['Funções de Uma Variável', 'Materiais e Suas Propriedades',
'Teoria dos Grafos']}

const matriculas = transformMatriculas(disciplinas)

assert.equal(matriculas['Funções de Uma Variável'].length, 3)
assert.equal(matriculas['Processamento da Informação'].length, 2)
assert.equal(matriculas['Laboratório de Engenharia de Software'].length, 1)
})
})
59 changes: 59 additions & 0 deletions app/helpers/validate/teachers.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const assert = require('assert')

const teachers = require('./teachers')

describe('teachers', function () {
it('should return empty list when has not errors', function () {
const disciplinas = [
{
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 6 spaces but found 8.

Suggested change
{
{

teoria: {
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 8 spaces but found 12.

Suggested change
teoria: {
teoria: {

name: 'Vanessa Kruth',
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 10 spaces but found 16.

Suggested change
name: 'Vanessa Kruth',
name: 'Vanessa Kruth',

error: null,
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 10 spaces but found 16.

Suggested change
error: null,
error: null,

},
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 8 spaces but found 12.

Suggested change
},
},

pratica: {
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 8 spaces but found 12.

Suggested change
pratica: {
pratica: {

name: 'Vanessa Kruth',
error: null,
}
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 8 spaces but found 12.

Suggested change
}
}

},
{
teoria: {
name: 'Isidro',
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 10 spaces but found 16.

Suggested change
name: 'Isidro',
name: 'Isidro',

error: null,
},
pratica: {
name: 'Isidro',
error: null,
}
},
];
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Extra semicolon.

Suggested change
];
]


assert.equal(0, Array.from(teachers(disciplinas)).length)
})

it('should return list with one error', function () {
const disciplinas = [
{
teoria: {
name: 'Vanessa Kruth',
error: null,
},
pratica: {
name: 'Vanessa Kruth',
error: null,
}
},
{
teoria: {
name: 'Isidro',
error: 'Sala não encontrada',
Copy link
Member

Choose a reason for hiding this comment

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

Codacy has a fix for the issue: Expected indentation of 10 spaces but found 16.

Suggested change
error: 'Sala não encontrada',
error: 'Sala não encontrada',

},
pratica: {
name: 'Isidro',
error: null,
}
},
];

assert.equal(1, Array.from(teachers(disciplinas)).length)
})
})
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start:watch": "apidoc -i api/ -o doc/ && forever --watch --watchFolder ./ ./server.js --colors",
"start:docker": "yarn build:docker && docker run -it -p 8010:8010 edu-web",
"populate": "node populate/index.js",
"coverage": "NODE_ENV=test nyc yarn test && nyc report --reporter=text-lcov > coverage.lcov && codecov"
"coverage": "NODE_ENV=test nyc npm run test && nyc report --reporter=text-lcov > coverage.lcov"
},
"dependencies": {
"agenda": "^2.0.2",
Expand Down