diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 90d49bbe2acae1aa3d36e0b4a42ae3cdf0ead3e2..dc8c4b6d8bd52a50299f89730400bdda9ba54e58 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,7 +18,7 @@ run_tests: - ping -W1 -c1 mongo - mv config.json.example config.json - sed -i -e 's/false/true/g' config.json - - sed -i -e 's/simcaq_dev/simcaq_dev2/g' config.json + - sed -i -e 's/simcaq_dev/simcaq_dev3/g' config.json - gulp build - gulp test tags: diff --git a/src/libs/convert/agreement.js b/src/libs/convert/agreement.js new file mode 100644 index 0000000000000000000000000000000000000000..b3317e2e5178d785f966d3e24ffe990065d54be9 --- /dev/null +++ b/src/libs/convert/agreement.js @@ -0,0 +1,12 @@ +module.exports = function agreement(id) { + switch (id) { + case 1: + return 'Estadual'; + case 2: + return 'Municipal'; + case 3: + return 'Estadual e Municipal'; + default: + return 'Não declarada'; + } +}; diff --git a/src/libs/convert/booleanVariable.js b/src/libs/convert/booleanVariable.js new file mode 100644 index 0000000000000000000000000000000000000000..8ed8e007e2597049009072955c46319e32891a1c --- /dev/null +++ b/src/libs/convert/booleanVariable.js @@ -0,0 +1,8 @@ +module.exports = function booleanVariable(id) { + if (id == null) + return 'Não Declarado'; + else if (id == false) + return 'Não'; + else if (id == true) + return 'Sim'; +}; diff --git a/src/libs/convert/educationType.js b/src/libs/convert/educationType.js new file mode 100644 index 0000000000000000000000000000000000000000..99f4ddd70e8f5885c1a4a4ff4094f2fb2ca40c83 --- /dev/null +++ b/src/libs/convert/educationType.js @@ -0,0 +1,20 @@ +module.exports = function educationType(id) { + switch (id) { + case 1: + return 'Ensino Fundamental'; + case 2: + return 'Ensino Médio'; + case 3: + return 'Médio Normal ou Magistério'; + case 4: + return 'Superior'; + case 5: + return 'Superior com licenciatura'; + case 6: + return 'Especialização'; + case 7: + return 'Mestrado ou Doutorado'; + default: + return 'Não definido'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 99bb7793c456fb5823bb30f3adc26b3bd7895266..ae9ae4634767e7a14a2ea197335d05169ea10618 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -5,8 +5,11 @@ const schoolYear = require(`${libs}/convert/schoolYear`); const admDependency = require(`${libs}/convert/admDependency`); const location = require(`${libs}/convert/location`); const ethnicGroup = require(`${libs}/convert/ethnicGroup`); +const agreement = require(`${libs}/convert/agreement`); +const booleanVariable = require(`${libs}/convert/booleanVariable`); const educationLevel = require(`${libs}/convert/educationLevel`); const educationLevelMod = require(`${libs}/convert/educationLevelMod`); +const educationType = require(`${libs}/convert/educationType`); const ids = { gender_id: gender, @@ -17,7 +20,39 @@ const ids = { adm_dependency_id: admDependency, adm_dependency_detailed_id: admDependency, location_id: location, - ethnic_group_id: ethnicGroup + ethnic_group_id: ethnicGroup, + agreement_id: agreement, + integral_time_id: booleanVariable, + government_agreement_id: booleanVariable, + building_school_id: booleanVariable, + informatics_lab_id: booleanVariable, + science_lab_id: booleanVariable, + directors_room_id: booleanVariable, + teacher_room_id: booleanVariable, + cook_room_id: booleanVariable, + playground_id: booleanVariable, + indor_sports_court_id: booleanVariable, + nusery_id: booleanVariable, + special_attendence_room_id: booleanVariable, + toilet_inside_building_id: booleanVariable, + denpendency_pne_id: booleanVariable, + restroom_pne_id: booleanVariable, + broadband_id: booleanVariable, + energy_id: booleanVariable, + water_id: booleanVariable, + wastepipe_id: booleanVariable, + education_day_care_child_id: booleanVariable, + education_preschool_child_id: booleanVariable, + education_begin_elementary_school_id: booleanVariable, + education_end_elementary_school_id: booleanVariable, + education_middle_school_id: booleanVariable, + education_professional_id: booleanVariable, + education_eja_id: booleanVariable, + library_reading_room_id: booleanVariable, + library_id: booleanVariable, + reading_room_id: booleanVariable, + water_id: booleanVariable, + education_type_id: educationType }; function transform(removeId=false) { @@ -44,6 +79,9 @@ module.exports = { admDependency, location, ethnicGroup, + agreement, + booleanVariable, educationLevel, - educationLevelMod + educationLevelMod, + educationType }; diff --git a/src/libs/middlewares/query.js b/src/libs/middlewares/query.js index ecef42951b95deabe9a11c3d90e9af11dc01d013..97df67e0666a6dde0749ee3cb3c7f1fc0134e81e 100644 --- a/src/libs/middlewares/query.js +++ b/src/libs/middlewares/query.js @@ -5,9 +5,8 @@ const execQuery = require(`${libs}/db/query_exec`); // Middleware that executes a query defined by a squel object in req.sql function query(req, res, next) { let sql = req.sql.toParam(); - log.debug(sql); + log.debug(req.sql.toString()); execQuery(sql.text, sql.values).then((result) => { - log.debug(result); req.result = result; if (result.length === 0) { next({status: 404, message: 'No results found in database'}); diff --git a/src/libs/middlewares/reqQueryFields.js b/src/libs/middlewares/reqQueryFields.js index 577b23598add747c5ee812bf2e68021ae2fb9dee..b85e3f0036ff2084cc6efc56e4be7faf5528a60c 100644 --- a/src/libs/middlewares/reqQueryFields.js +++ b/src/libs/middlewares/reqQueryFields.js @@ -210,23 +210,55 @@ class ReqQueryFields { // Se o valor é um campo a ser incluÃdo no SELECT if(typeof field.field !== 'undefined' && field.field) { log.debug('SELECT'); - req.sql.field(value.table+'.'+value.tableField, value.resultField || value.tableField) - .group(value.table+'.'+value.tableField) - .order(value.table+'.'+value.tableField); + if (Array.isArray(value.resultField)) { + value.tableField.forEach((f, i) => { + req.sql.field(value.table+'.'+f, value.resultField[i] || f) + .group(value.table+'.'+f); + }) + }else{ + req.sql.field(value.table+'.'+value.tableField, value.resultField || value.tableField) + .group(value.table+'.'+value.tableField); + } } // Se o valor é um campo para ser usado no WHERE if(typeof field.where !== 'undefined' && field.where) { log.debug('WHERE'); // Valor do where + let whereValue = param[k]; // Valor sempre vem como string, necessário fazer parse para o banco if(value.where.type === 'integer') whereValue = parseInt(whereValue, 10); if(value.where.type === 'double') whereValue = parseFloat(whereValue); if(value.where.type === 'string') whereValue = '%'+whereValue+'%'; + if(value.where.type === 'boolean') { + if (whereValue.toLowerCase() === 'null') { + whereValue = null; + console.log('Fazendo uma consulta Null'); + } else { + whereValue = (whereValue.toLowerCase() === 'true' || parseInt(whereValue, 10) === 1); + console.log('Fazendo uma consulta True'); + } + } let tbl = value.where.table || value.table; - let whereField = (value.where.type === 'string')? 'LOWER('+tbl+'.'+value.where.field+')' : tbl+'.'+value.where.field; - let lower = (value.where.type === 'string') ? ' LOWER(?) ' : ' ? '; - req.sql.where(whereField + ' ' + value.where.relation + lower, whereValue); + // multiple where, only tested for boolean filds + if (Array.isArray(value.tableField)) { + let lower = (value.where.type === 'string') ? ' LOWER(?) ' : ' ? '; + let whereField = ''; + let whereValues = []; + value.where.field.forEach((f, i, arr) => { + whereValues.push(whereValue); + whereField += (value.where.type === 'string') ? 'LOWER(' + tbl + '.' + value.where.field[i] + ')' : tbl + '.' + value.where.field[i]; + whereField += ' ' + value.where.relation + ' ?'; + if (i < arr.length - 1) { + whereField += ' ' + value.where.condition + ' '; + } + }); + req.sql.where(whereField, ...whereValues); + } else { + let whereField = (value.where.type === 'string') ? 'LOWER(' + tbl + '.' + value.where.field + ')' : tbl + '.' + value.where.field; + let lower = (value.where.type === 'string') ? ' LOWER(?) ' : ' ? '; + req.sql.where(whereField + ' ' + value.where.relation + lower, whereValue); + } } } }); diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index d2119dd2694ab2aa24186a180f3b8bb67b82518f..2e7c9a3efd4267a6e75f5e53ed187eebde464e2a 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -8,7 +8,7 @@ const config = require(`${libs}/config`); const classes = require('./class'); -const cache = require('apicache').options({ debug: config.debug }).middleware; +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; const enrollment = require('./enrollment'); @@ -26,6 +26,10 @@ const simulation = require('./simulation'); const user = require('./user'); +const classroom = require('./classroom'); + +const teacher = require('./teacher'); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API is running' }); }); @@ -40,5 +44,7 @@ api.use('/region', cache('15 day'), region); api.use('/city', cache('15 day'), city); api.use('/school', cache('15 day'), school); api.use('/spatial', cache('1 day'), spatial); +api.use('/classroom', cache('15 day'), classroom); +api.use('/teacher', cache('1 day'), teacher); module.exports = api; diff --git a/src/libs/routes/class.js b/src/libs/routes/class.js index dc0f02588ef387ad7fb6d6503773754de4a54af5..39291ddc4ab0073823c2b34972638da0e2f751ed 100644 --- a/src/libs/routes/class.js +++ b/src/libs/routes/class.js @@ -14,6 +14,8 @@ const response = require(`${libs}/middlewares/response`); const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); +const id2str = require(`${libs}/middlewares/id2str`); + let rqfCount = new ReqQueryFields(); // Complete range of the enrollments dataset. // Returns a tuple of start and ending years of the complete enrollments dataset. @@ -56,13 +58,23 @@ classApp.get('/period', (req, res, next) => { next(); }, query, response('period')); +// Returns integral-time avaible +classApp.get('/integral_time', (req, res, next) => { + req.result = [ + {id: null, name: 'Não DisponÃvel'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('integral_time')); + // Returns all educational levels avaible -classApp.get('/education_level', (req, res, next) => { +classApp.get('/education_level_mod', (req, res, next) => { req.sql.from('etapas_mod_ensino_segmento') .field('id') .field('nome', 'name'); next(); -}, query, response('education_level')); +}, query, response('education_level_mod')); rqfCount.addField({ name: 'filter', @@ -141,78 +153,63 @@ rqfCount.addField({ } }).addValue({ name:'adm_dependency', - table: 'dependencia_adm', - tableField: 'id', - resultField: 'adm_dependency_name', + table: 'turma', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'dependencia_adm_id', - foreignTable: 'turma' + field: 'dependencia_adm_id' } }).addValue({ name: 'location', - table: 'localizacao', - tableField: 'descricao', - resultField: 'location_name', + table: 'turma', + tableField: 'localizacao_id', + resultField: 'location_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'localizacao_id', - foreignTable: 'turma' + field: 'localizacao_id' } }).addValue({ - name:'education_level', - table: 'etapas_mod_ensino_segmento ', - tableField: 'id', - resultField: 'education_level_name', + name:'education_level_mod', + table: 'turma', + tableField: 'etapas_mod_ensino_segmento_id', + resultField: 'education_level_mod_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'etapas_mod_ensino_segmento_id', - foreignTable: 'turma' + field: 'etapas_mod_ensino_segmento_id' } }).addValue({ name: 'adm_dependency_detailed', - table: 'dependencia_adm', - tableField: 'nome', - resultField: 'adm_dependency_detailed_name', + table: 'turma', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_detailed_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'dependencia_adm_priv', - foreignTable: 'turma' + field: 'dependencia_adm_priv' } }).addValue({ name:'period', - table: 'turma_turno', - tableField: 'id', - resultField: 'period_name', + table: 'turma', + tableField: 'turma_turno_id', + resultField: 'period_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'turno', - foreignTable: 'turma' + field: 'turma_turno_id' + } +}).addValue({ + name:'integral_time', + table: 'turma', + tableField: 'tempo_integral', + resultField: 'integral_time_id', + where: { + relation: '=', + type: 'boolean', + field: 'tempo_integral' } }).addValue({ name: 'school', @@ -242,6 +239,6 @@ classApp.get('/', rqfCount.parse(), rqfCount.build(), (req, res, next) => { .order('turma.ano_censo') .where('turma.tipo_turma_id = 0 OR turma.tipo_turma_id = 1 OR turma.tipo_turma_id = 2 OR turma.tipo_turma_id = 3'); next(); -}, query, response('class')); +}, query, id2str.transform(true), response('class')); module.exports = classApp; diff --git a/src/libs/routes/classroom.js b/src/libs/routes/classroom.js new file mode 100644 index 0000000000000000000000000000000000000000..7140bba1b34a03138bbac1fccdf73f07c721ebe6 --- /dev/null +++ b/src/libs/routes/classroom.js @@ -0,0 +1,181 @@ +const express = require('express'); + +const classroomApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +let rqf = new ReqQueryFields(); + +let rqfCount = new ReqQueryFields(); + +// Complete range of the enrollments dataset. +// Returns a tuple of start and ending years of the complete enrollments dataset. +classroomApp.get('/year_range', (req, res, next) => { + req.sql.from('escola') + .field('MIN(escola.ano_censo)', 'start_year') + .field('MAX(escola.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +classroomApp.get('/adm_dependency', (req, res, next) => { + req.sql.from('dependencia_adm') + .field('id') + .field('nome', 'name') + .where('id <= 4'); + next() +}, query, response('adm_dependency')); + +classroomApp.get('/adm_dependency_detailed', (req, res, next) => { + req.sql.from('dependencia_adm') + .field('id', 'id') + .field('nome', 'name'); + next() +}, query, response('adm_dependency_detailed')); + +classroomApp.get('/location', (req, res, next) => { + req.result = [ + {id: 1, name: 'Urbana'}, + {id: 2, name: 'Rural'} + ]; + next(); +}, response('location')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'school', + table: 'escola', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: 'nome', + resultField: 'region_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'regiao_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'min_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'adm_dependency', + table: 'escola', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}).addValue({ + name: 'adm_dependency_detailed', + table: 'escola', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_detailed_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_priv' + } +}).addValue({ + name: 'location', + table: 'escola', + tableField: 'cod_localizacao', + resultField: 'location_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_localizacao' + } +}); + +classroomApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + console.log(req.filter); + req.sql.from('escola') + .field('SUM(escola.num_salas)', 'total') + .field("'Brasil'", 'name') + .field('escola.ano_censo', 'year') + .group('escola.ano_censo') + .order('escola.ano_censo') + .where('escola.situacao_de_funcionamento = 1 AND escola.local_func_predio_escolar = 1'); + next(); +}, query, id2str.transform(true), response('classroom')); + +module.exports = classroomApp; diff --git a/src/libs/routes/enrollment.js b/src/libs/routes/enrollment.js index 7b35d74429a191f7934fda18278da5aa6c9cf2c7..ad14b9b741ea3eb1234fc0e979a46f7b117827fa 100644 --- a/src/libs/routes/enrollment.js +++ b/src/libs/routes/enrollment.js @@ -268,18 +268,13 @@ rqf.addField({ } }).addValue({ name: 'period', - table: 'turma', - tableField: 'turno', + table: 'matricula', + tableField: 'turma_turno_id', resultField: 'period_id', where: { relation: '=', type: 'integer', - field: 'turno' - }, - join: { - primary: 'id', - foreign: 'turma_id', - foreignTable: 'matricula' + field: 'turma_turno_id' } }); diff --git a/src/libs/routes/school.js b/src/libs/routes/school.js index d6e5f7d013f5b0bf11f14a3456273bf64ff0cfca..659730083c3c49928eb8a6d4adb241a1940f7614 100644 --- a/src/libs/routes/school.js +++ b/src/libs/routes/school.js @@ -10,9 +10,305 @@ const query = require(`${libs}/middlewares/query`); const response = require(`${libs}/middlewares/response`); +const id2str = require(`${libs}/middlewares/id2str`); + const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); let rqf = new ReqQueryFields(); +let rqfCount = new ReqQueryFields(); + +// Return location +schoolApp.get('/year_range', (req, res, next) => { + req.sql.from('escola') + .field('MIN(escola.ano_censo)', 'start_year') + .field('MAX(escola.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +schoolApp.get('/location', (req, res, next) => { + req.result = [ + {id: 1, name: 'Urbana'}, + {id: 2, name: 'Rural'} + ]; + next(); +}, response('location')); + +schoolApp.get('/adm_dependency', (req, res, next) => { + req.sql.from('dependencia_adm') + .field('id') + .field('nome', 'name') + .where('id <= 4'); + next(); +}, query, response('adm_dependency')); + +schoolApp.get('/adm_dependency_detailed', (req, res, next) => { + req.sql.from('dependencia_adm') + .field('id', 'id') + .field('nome', 'name'); + next(); +}, query, response('adm_dependency_detailed')); + +schoolApp.get('/government_agreement', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('government_agreement')); + +schoolApp.get('/agreement', (req, res, next) => { + req.result = [ + {id: 1, name: 'Estadual'}, + {id: 2, name: 'Municipal'}, + {id: 3, name: 'Estadual e Municipal'} + ]; + next(); +}, response('agreement')); + +schoolApp.get('/building_school', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('building_school')); + +schoolApp.get('/informatics_lab', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('informatics_lab')); + + +schoolApp.get('/science_lab', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('/science_lab')); + +schoolApp.get('/directors_room', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('directors_room')); + +schoolApp.get('/teacher_room', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('teacher_room')); + +schoolApp.get('/cook_room', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('cook_room')); + +schoolApp.get('/playground', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('playground')); + +schoolApp.get('/indor_sports_court', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('indor_sports_court')); + +schoolApp.get('/nusery', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('nusery')); + +schoolApp.get('/special_attendence_room', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('special_attendence_room')); + +schoolApp.get('/toilet_inside_building', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('toilet_inside_building')); + +schoolApp.get('/denpendency_pne', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('denpendency_pne')); + +schoolApp.get('/restroom_pne', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('restroom_pne')); + +schoolApp.get('/broadband', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('broadband')); + +schoolApp.get('/energy', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('energy')); + +schoolApp.get('/water', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('water')); + +schoolApp.get('/wastepipe', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('wastepipe')); + +schoolApp.get('/education_day_care_child', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_day_care_child')); + +schoolApp.get('/education_preschool_child', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_preschool_child')); + +schoolApp.get('/education_begin_elementary_school', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_begin_elementary_school')); + +schoolApp.get('/education_end_elementary_school', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_end_elementary_school')); + +schoolApp.get('/education_middle_school', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_middle_school')); + +schoolApp.get('/education_professional', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_professional')); + +schoolApp.get('/education_eja', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('education_eja')); + +schoolApp.get('/library', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('library')); + +schoolApp.get('/reading_room', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('reading_room')); + +schoolApp.get('/library_reading_room', (req, res, next) => { + req.result = [ + {id: null, name: 'Não Declarado'}, + {id: 0, name: 'Não'}, + {id: 1, name: 'Sim'} + ]; + next(); +}, response('library_reading_room')); rqf.addField({ name: 'filter', @@ -72,6 +368,447 @@ rqf.addField({ } }); +rqfCount.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'id', + table: 'escola', + tableField: 'id', + where: { + relation: '=', + type: 'integer', + field: 'id' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: 'escola' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: 'nome', + resultField: 'region_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'regiao_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo', + table: 'escola' + } +}).addValue({ + name: 'adm_dependency', + table: 'dependencia_adm', + tableField: 'nome', + resultField: 'adm_dependency_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'dependencia_adm_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'adm_dependency_detailed', + table: 'dependencia_adm', + tableField: 'nome', + resultField: 'adm_dependency_detailed_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'dependencia_adm_priv', + foreignTable: 'escola' + } +}).addValue({ + name: 'location', + table: 'escola', + tableField: 'cod_localizacao', + resultField: 'location_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_localizacao' + } +}).addValue({ + name: 'cook_room', + table: 'escola', + tableField: 'cozinha', + resultField: 'cook_room_id', + where: { + relation: '=', + type: 'boolean', + field: 'cozinha' + } +}).addValue({ + name: 'government_agreement', + table: 'escola', + tableField: 'conveniada_pp', + resultField: 'government_agreement_id', + where: { + relation: '=', + type: 'boolean', + field: 'conveniada_pp' + } +}).addValue({ + name: 'informatics_lab', + table: 'escola', + tableField: 'lab_informatica', + resultField: 'informatics_lab_id', + where: { + relation: '=', + type: 'boolean', + field: 'lab_informatica' + } +}).addValue({ + name: 'science_lab', + table: 'escola', + tableField: 'lab_ciencias', + resultField: 'science_lab_id', + where: { + relation: '=', + type: 'boolean', + field: 'lab_ciencias' + } +}).addValue({ + name: 'special_attendence_room', + table: 'escola', + tableField: 'sala_atendimento_especial', + resultField: 'special_attendence_room_id', + where: { + relation: '=', + type: 'boolean', + field: 'sala_atendimento_especial' + } +}).addValue({ + name: 'indor_sports_court', + table: 'escola', + tableField: 'quadra_esportes_coberta', + resultField: 'indor_sports_court_id', + where: { + relation: '=', + type: 'boolean', + field: 'quadra_esportes_coberta' + } +}).addValue({ + name: 'education_eja', + table: 'escola', + tableField: 'ensino_eja', + resultField: 'education_eja_id', + where: { + relation: '=', + type: 'boolean', + field: 'ensino_eja' + } +}).addValue({ + name: 'education_professional', + table: 'escola', + tableField: 'educacao_profissional', + resultField: 'education_professional_id', + where: { + relation: '=', + type: 'boolean', + field: 'educacao_profissional' + } +}).addValue({ + name: 'education_middle_school', + table: 'escola', + tableField: 'reg_medio_medio', + resultField: 'education_middle_school_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_medio_medio' + } +}).addValue({ + name: 'education_end_elementary_school', + table: 'escola', + tableField: 'reg_fund_af', + resultField: 'education_end_elementary_school_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_fund_af' + } +}).addValue({ + name: 'education_begin_elementary_school', + table: 'escola', + tableField: 'reg_fund_ai', + resultField: 'education_begin_elementary_school_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_fund_ai' + } +}).addValue({ + name: 'education_preschool_child', + table: 'escola', + tableField: 'reg_infantil_preescola', + resultField: 'education_preschool_child_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_infantil_preescola' + } +}).addValue({ + name: 'education_day_care_child', + table: 'escola', + tableField: 'reg_infantil_creche', + resultField: 'education_day_care_child_id', + where: { + relation: '=', + type: 'boolean', + field: 'reg_infantil_creche' + } +}).addValue({ + name: 'directors_room', + table: 'escola', + tableField: 'sala_diretoria', + resultField: 'directors_room_id', + where: { + relation: '=', + type: 'boolean', + field: 'sala_diretoria' + } +}).addValue({ + name: 'teacher_room', + table: 'escola', + tableField: 'sala_professor', + resultField: 'teacher_room_id', + where: { + relation: '=', + type: 'boolean', + field: 'sala_professor' + } +}).addValue({ + name: 'playground', + table: 'escola', + tableField: 'parque_infantil', + resultField: 'playground_id', + where: { + relation: '=', + type: 'boolean', + field: 'parque_infantil' + } +}).addValue({ + name: 'nusery', + table: 'escola', + tableField: 'bercario', + resultField: 'nusery_id', + where: { + relation: '=', + type: 'boolean', + field: 'bercario' + } +}).addValue({ + name: 'toilet_inside_building', + table: 'escola', + tableField: 'sanitario_dentro_predio', + resultField: 'toilet_inside_building_id', + where: { + relation: '=', + type: 'boolean', + field: 'sanitario_dentro_predio' + } +}).addValue({ + name: 'wastepipe', + table: 'escola', + tableField: 'esgoto_sanitario', + resultField: 'wastepipe_id', + where: { + relation: '=', + type: 'boolean', + field: 'esgoto_sanitario' + } +}).addValue({ + name: 'water', + table: 'escola', + tableField: 'fornecimento_agua', + resultField: 'water_id', + where: { + relation: '=', + type: 'boolean', + field: 'fornecimento_agua ' + } +}).addValue({ + name: 'energy', + table: 'escola', + tableField: 'fornecimento_energia', + resultField: 'energy_id', + where: { + relation: '=', + type: 'boolean', + field: 'fornecimento_energia ' + } +}).addValue({ + name: 'broadband', + table: 'escola', + tableField: 'internet_banda_larga', + resultField: 'broadband_id', + where: { + relation: '=', + type: 'boolean', + field: 'internet_banda_larga ' + } +}).addValue({ + name: 'restroom_pne', + table: 'escola', + tableField: 'sanitario_pne', + resultField: 'restroom_pne_id', + where: { + relation: '=', + type: 'boolean', + field: 'sanitario_pne ' + } +}).addValue({ + name: 'denpendency_pne', + table: 'escola', + tableField: 'dependencias_pne', + resultField: 'denpendency_pne_id', + where: { + relation: '=', + type: 'boolean', + field: 'dependencias_pne ' + } +}).addValue({ + name: 'agreement', + table: 'escola', + tableField: 'tipo_convenio_pp', + resultField: 'agreement_id', + where: { + relation: '=', + type: 'integer', + field: 'tipo_convenio_pp' + } +}).addValue({ + name: 'building_school', + table: 'escola', + tableField: 'local_func_predio_escolar', + resultField: 'building_school_id', + where: { + relation: '=', + type: 'boolean', + field: 'local_func_predio_escolar' + } +}).addValue({ + name: 'library', + table: 'escola', + tableField: 'biblioteca', + resultField: 'library_id', + where: { + relation: '=', + type: 'boolean', + field: 'biblioteca' + } +}).addValue({ + name: 'reading_room', + table: 'escola', + tableField: 'sala_leitura', + resultField: 'reading_room_id', + where: { + relation: '=', + type: 'boolean', + field: 'sala_leitura' + } +}).addValue({ + name: 'library_reading_room', + table: 'escola', + tableField: 'biblioteca_sala_leitura', + resultField: 'library_reading_room_id', + where: { + relation: '=', + type: 'boolean', + condition: 'or', + field: 'biblioteca_sala_leitura' + } +}).addValue({ + name: 'min_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'escola', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}); + +// .addValue({ //Using multiple_where +// name: 'library_reading_room', +// table: 'escola', +// tableField: ['biblioteca', 'sala_leitura', 'biblioteca_sala_leitura'], +// resultField: 'library_or_reading_room', +// where: { +// relation: '=', +// type: 'boolean', +// condition: 'or', +// field: ['biblioteca', 'sala_leitura', 'biblioteca_sala_leitura'] +// } + +// SELECT COUNT(escola.id) AS "total", 'Brasil' AS "name", escola.ano_censo AS "year" FROM escola WHERE (escola.biblioteca = ? OR escola.sala_leitura = ? OR escola.biblioteca_sala_leitura) AND (escola.situacao_de_funcionamento = 1 AND escola.ensino_regular = 1) GROUP BY escola.ano_censo ORDER BY escola.ano_censo ASC schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { console.log(req.filter); if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0) { @@ -90,4 +827,16 @@ schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { next(); }, query, response('school')); +schoolApp.get('/count', rqfCount.parse(), rqfCount.build(), (req, res, next) => { + + req.sql.from('escola') + .field('COUNT(escola.id)', 'total') + .field("'Brasil'", 'name') + .field('escola.ano_censo', 'year') + .group('escola.ano_censo') + .order('escola.ano_censo') + .where('escola.situacao_de_funcionamento = 1 AND escola.ensino_regular = 1'); + next(); +}, query, id2str.transform(true), response('school')); + module.exports = schoolApp; diff --git a/src/libs/routes/teacher.js b/src/libs/routes/teacher.js new file mode 100644 index 0000000000000000000000000000000000000000..5a70c8350b1ee1bc42336eb6f70c409757ad93d4 --- /dev/null +++ b/src/libs/routes/teacher.js @@ -0,0 +1,257 @@ +const express = require('express'); + +const teacherApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const log = require(`${libs}/log`)(module); + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +let rqf = new ReqQueryFields(); + +// Returns a tuple of start and ending years of the complete enrollments dataset. +teacherApp.get('/year_range', (req, res, next) => { + req.sql.from('docente') + .field('MIN(docente.ano_censo)', 'start_year') + .field('MAX(docente.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +teacherApp.get('/adm_dependency_detailed', (req, res, next) => { + req.sql.from('dependencia_adm') + .field('id', 'id') + .field('nome', 'name'); + next(); +}, query, response('adm_dependency_detailed')); + +teacherApp.get('/adm_dependency', (req, res, next) => { + req.sql.from('dependencia_adm') + .field('id') + .field('nome', 'name') + .where('id <= 4'); + next(); +}, query, response('adm_dependency')); + +teacherApp.get('/education_level_mod', (req, res, next) => { + req.sql.from('etapas_mod_ensino_segmento') + .field('id') + .field('nome', 'name'); + next(); +}, query, response('education_level_mod')); + +teacherApp.get('/location', (req, res, next) => { + req.sql.from('localizacao') + .field('id') + .field('descricao', 'name') + .where('id <= 2'); + next(); +}, query, response('location')); + +teacherApp.get('/education_type', (req, res, next) => { + req.sql.from('docente') + .field('DISTINCT nivel_tipo_formacao', 'id') + .order('id'); + next(); +}, query, (req, res, next) => { + req.result.forEach((result) => { + result.name = id2str.educationType(result.id); + }); + next(); +}, response('education_type')); + +teacherApp.get('/gender', (req, res, next) => { + req.result = [ + {id: 1, name: 'Masculino'}, + {id: 2, name: 'Feminino'} + ]; + next(); +}, response('gender')); + +teacherApp.get('/ethnic_group', (req, res, next) => { + req.sql.from('cor_raca') + .field('id') + .field('nome', 'name'); + next(); +}, query, response('ethnic_group')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'adm_dependency', + table: 'docente', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_id' + } +}).addValue({ + name: 'adm_dependency_detailed', + table: 'docente', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_detailed_id', + where: { + relation: '=', + type: 'integer', + field: 'dependencia_adm_priv' + } +}).addValue({ + name: 'education_level_mod', + table: 'docente', + tableField: 'etapas_mod_ensino_segmento_id', + resultField: 'education_level_mod_id', + where: { + relation: '=', + type: 'integer', + field: 'etapas_mod_ensino_segmento_id' + } +}).addValue({ + name: 'education_type', + table: 'docente', + tableField: 'nivel_tipo_formacao', + resultField: 'education_type_id', + where: { + relation: '=', + type: 'integer', + field: 'nivel_tipo_formacao' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: 'nome', + resultField: 'region_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_regiao_id', + foreignTable: 'docente' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_estado_id', + foreignTable: 'docente' + } +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: 'id', + foreign: 'escola_municipio_id', + foreignTable: 'docente' + } +}).addValue({ + name: 'school', + table: 'escola', + tableField: 'nome_escola', + resultField: 'school_name', + where: { + relation: '=', + type: 'integer', + field: 'id' + }, + join: { + primary: ['id', 'ano_censo'], + foreign: ['escola_id', 'ano_censo'], + foreignTable: 'docente' + } +}).addValue({ + name: 'location', + table: 'docente', + tableField: 'cod_localizacao', + resultField: 'location_id', + where: { + relation: '=', + type: 'integer', + field: 'cod_localizacao' + } +}).addValue({ + name: 'min_year', + table: 'docente', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'docente', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'gender', + table: 'docente', + tableField: 'sexo', + resultField: 'gender_id', + where: { + relation: '=', + type: 'integer', + field: 'sexo' + } +}).addValue({ + name: 'ethnic_group', + table: 'docente', + tableField: 'cor_raca', + resultField: 'ethnic_group_id', + where: { + relation: '=', + type: 'integer' + } +}); + +teacherApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.field('COUNT(DISTINCT docente.id)', 'total') + .field("'Brasil'", 'name') + .field('docente.ano_censo', 'year') + .from('docente') + .join('turma', null, 'docente.turma_id=turma.id') + .group('docente.ano_censo') + .order('docente.ano_censo') + .where('(docente.tipo_docente = 1 OR docente.tipo_docente = 5) AND (turma.tipo_turma_id <= 3)'); + next(); +}, query, id2str.transform(true), response('teacher')); + +module.exports = teacherApp; diff --git a/src/server.js b/src/server.js index ccc5e884702641fca04e0fc0480860a4b72300ef..f91eb88bf71dd6cf36618e2d8debfdd3e3508f01 100644 --- a/src/server.js +++ b/src/server.js @@ -1,29 +1,44 @@ -const debug = require('debug')('node-express-base'); - +const debug = require('debug')('simcaq-api'); const libs = `${process.cwd()}/libs`; - const config = require(`${libs}/config`); - const log = require(`${libs}/log`)(module); - const app = require(`${libs}/app`); - const compatVersion = require(`${libs}/middlewares/checkVersion`); +const cluster = require('cluster'); // Check if Node version is compatible if (!compatVersion()) { process.exit(1); } -// Set default port: first environment variable PORT, then configuration and last 3000 -app.set('port', process.env.PORT || config.port || 3000); -process.env.NODE_ENV = process.env.NODE_ENV || 'development'; -// Set default ip: first environment variable IOP, then configuration and last '127.0.0.1' -app.set('ip', process.env.IP || config.ip || '127.0.0.1'); - -const server = app.listen(app.get('port'), () => { - log.info(`Express server listening on port ${server.address().port}`); -}); - -// For testing -module.exports = server; +if(cluster.isMaster) { + log.info(`Master ${process.pid} is running`); + + const numCPUs = require('os').cpus().length; + log.info(`Master will create ${numCPUs} workers`); + for(let i=0; i < numCPUs; ++i) { + cluster.fork(); + } + + // Caso uma instâcia morra + cluster.on('exit', (worker, code, signal) => { + log.info(`Worker ${worker.process.pid} died`); + // Revive a instância + cluster.fork(); + }); +} else { + // Set default port: first environment variable PORT, then configuration and last 3000 + app.set('port', process.env.PORT || config.port || 3000); + process.env.NODE_ENV = process.env.NODE_ENV || 'development'; + // Set default ip: first environment variable IOP, then configuration and last '127.0.0.1' + app.set('ip', process.env.IP || config.ip || '127.0.0.1'); + + const server = app.listen(app.get('port'), () => { + log.info(`Express server listening on port ${server.address().port}`); + }); + + log.info(`Worker ${cluster.worker.id} is running (${process.pid})`); + + // For testing + module.exports = server; +} diff --git a/src/test/class.js b/src/test/class.js index 3cf5f354e384a1e94e8362590d2ac0a133ee6fbe..32f89e3bacec3313f59067b8ff1102da230b037b 100644 --- a/src/test/class.js +++ b/src/test/class.js @@ -23,7 +23,7 @@ const libs = `${process.cwd()}/libs`; const server = require(`${libs}/app`); chai.use(chaiHttp); -describe('request enrollments', () => { +describe('request class', () => { it('should list the locations', (done) => { chai.request(server) .get('/api/v1/class/location') @@ -40,7 +40,7 @@ describe('request enrollments', () => { it('should list the education level', (done) => { chai.request(server) - .get('/api/v1/class/education_level') + .get('/api/v1/class/education_level_mod') .end((err, res) => { res.should.have.status(200); res.should.be.json; @@ -155,7 +155,7 @@ describe('request enrollments', () => { it('should list class with valid dimensions and filters', (done) => { chai.request(server) - .get('/api/v1/class?dims=region,state,education_level,school,period&filter=min_year:2015,max_year:2015,city:4106902') + .get('/api/v1/class?dims=region,state,education_level_mod,school,period&filter=min_year:2015,max_year:2015,city:4106902') .end((err, res) => { res.should.have.status(200); res.should.be.json; @@ -164,7 +164,7 @@ describe('request enrollments', () => { res.body.result[0].should.have.property('region_name'); res.body.result[0].should.have.property('state_name'); res.body.result[0].should.have.property('school_name'); - res.body.result[0].should.have.property('education_level_name'); + res.body.result[0].should.have.property('education_level_mod_name'); res.body.result[0].should.have.property('total'); res.body.result[0].should.have.property('year'); done(); diff --git a/src/test/classroom.js b/src/test/classroom.js new file mode 100644 index 0000000000000000000000000000000000000000..bd520cf8b67ad396f8251092bf0a4036bb65e36a --- /dev/null +++ b/src/test/classroom.js @@ -0,0 +1,265 @@ +process.env.NODE_ENV = 'test'; + +const chai = require('chai'); + +const dirtyChai = require('dirty-chai'); + +chai.use(dirtyChai); + +const chaiXml = require('chai-xml'); + +chai.use(chaiXml); + +const chaiHttp = require('chai-http'); + +const assert = chai.assert; + +const expect = chai.expect; + +const should = chai.should(); // actually call the function + +const libs = `${process.cwd()}/libs`; + +const server = require(`${libs}/app`); + +chai.use(chaiHttp); +describe('request classrooms', () => { + + it('should list the locations', (done) => { + chai.request(server) + .get('/api/v1/classroom/location') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the administrative dependencies', (done) => { + chai.request(server) + .get('/api/v1/classroom/adm_dependency') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the detailed administrative dependencies', (done) => { + chai.request(server) + .get('/api/v1/classroom/adm_dependency_detailed') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list classrooms', (done) => { + chai.request(server) + .get('/api/v1/classroom') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid filters', (done) => { + chai.request(server) + .get('/api/v1/classroom?filter=city:4106902') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid filters', (done) => { + chai.request(server) + .get('/api/v1/classroom?filter=state:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid filters', (done) => { + chai.request(server) + .get('/api/v1/classroom?filter=region:4') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid filters', (done) => { + chai.request(server) + .get('/api/v1/classroom?filter=adm_dependency:3') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid filters', (done) => { + chai.request(server) + .get('/api/v1/classroom?filter=adm_dependency_detailed:5') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid filters', (done) => { + chai.request(server) + .get('/api/v1/classroom?filter=location:1') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid dimensions', (done) => { + chai.request(server) + .get('/api/v1/classroom?dims=city') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('city_name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid dimensions', (done) => { + chai.request(server) + .get('/api/v1/classroom?dims=state') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid dimensions', (done) => { + chai.request(server) + .get('/api/v1/classroom?dims=region') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('region_name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid dimensions', (done) => { + chai.request(server) + .get('/api/v1/classroom?dims=adm_dependency') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('adm_dependency_name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid dimensions', (done) => { + chai.request(server) + .get('/api/v1/classroom?dims=adm_dependency_detailed') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('adm_dependency_detailed_name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with valid dimensions', (done) => { + chai.request(server) + .get('/api/v1/classroom?dims=location') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list classrooms with invalid dimensions', (done) => { + chai.request(server) + .get('/api/v1/class?dims=foo,bar') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); +}); diff --git a/src/test/enrollment.js b/src/test/enrollment.js index ba0ec75828f352a2f91357c6a1d606994f422cb6..7d9572ff708165ed7e519be6347c6e3d46feb034 100644 --- a/src/test/enrollment.js +++ b/src/test/enrollment.js @@ -52,7 +52,7 @@ describe('request enrollments', () => { }); }); - it('should list the education level', (done) => { + it('should list the school year', (done) => { chai.request(server) .get('/api/v1/enrollment/school_year') .end((err, res) => { @@ -66,9 +66,37 @@ describe('request enrollments', () => { }); }); + it('should list the education level', (done) => { + chai.request(server) + .get('/api/v1/enrollment/education_level') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education level mod', (done) => { + chai.request(server) + .get('/api/v1/enrollment/education_level_mod') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + it('should list the administrative dependencies', (done) => { chai.request(server) - .get('/api/v1/enrollment/adm_dependency_detailed') + .get('/api/v1/enrollment/adm_dependency') .end((err, res) => { res.should.have.status(200); res.should.be.json; @@ -82,7 +110,7 @@ describe('request enrollments', () => { it('should list the administrative dependencies detailed', (done) => { chai.request(server) - .get('/api/v1/enrollment/adm_dependency') + .get('/api/v1/enrollment/adm_dependency_detailed') .end((err, res) => { res.should.have.status(200); res.should.be.json; @@ -227,6 +255,132 @@ describe('request enrollments', () => { }); }); + it('should list enrollment with dimension location', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=location') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('location_name'); + res.body.result[0].should.not.have.property('location_id'); + done(); + }); + }); + + it('should list enrollment with dimension school year', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=school_year') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('school_year_name'); + res.body.result[0].should.not.have.property('school_year_id'); + done(); + }); + }); + + it('should list enrollment with dimension education_level', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=education_level') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('education_level_name'); + res.body.result[0].should.not.have.property('education_level_id'); + done(); + }); + }); + + it('should list enrollment with dimension education_level_mod', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=education_level_mod') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('education_level_mod_name'); + res.body.result[0].should.not.have.property('education_level_mod_id'); + done(); + }); + }); + + it('should list enrollment with dimension adm_dependency', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=adm_dependency') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('adm_dependency_name'); + res.body.result[0].should.not.have.property('adm_dependency_id'); + done(); + }); + }); + + it('should list enrollment with dimension adm_dependency_detailed', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=adm_dependency_detailed') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('adm_dependency_detailed_name'); + res.body.result[0].should.not.have.property('adm_dependency_detailed_id'); + done(); + }); + }); + + it('should list enrollment with dimension gender', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=gender') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('gender_name'); + res.body.result[0].should.not.have.property('gender_id'); + done(); + }); + }); + + it('should list enrollment with dimension ethnic_group', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=ethnic_group') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('ethnic_group_name'); + res.body.result[0].should.not.have.property('ethnic_group_id'); + done(); + }); + }); + + it('should list enrollment with dimension period', (done) => { + chai.request(server) + .get('/api/v1/enrollment?dims=period') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('period_name'); + res.body.result[0].should.not.have.property('period_id'); + done(); + }); + }); + it('should list enrollments offer projection', (done) => { chai.request(server) .get('/api/v1/enrollment/offer_projection') diff --git a/src/test/schoolCount.js b/src/test/schoolCount.js new file mode 100644 index 0000000000000000000000000000000000000000..0a94f2d7a9b235cef2d2136f5d52f75ad6cfe12d --- /dev/null +++ b/src/test/schoolCount.js @@ -0,0 +1,640 @@ +process.env.NODE_ENV = 'test'; + +const chai = require('chai'); + +const dirtyChai = require('dirty-chai'); + +chai.use(dirtyChai); + +const chaiXml = require('chai-xml'); + +chai.use(chaiXml); + +const chaiHttp = require('chai-http'); + +const assert = chai.assert; + +const expect = chai.expect; + +const should = chai.should(); // actually call the function + +const libs = `${process.cwd()}/libs`; + +const server = require(`${libs}/app`); + +chai.use(chaiHttp); + +describe('request schools count', () => { + it('should list the locations', (done) => { + chai.request(server) + .get('/api/v1/school/location') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the administrative dependencies', (done) => { + chai.request(server) + .get('/api/v1/school/adm_dependency') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the administrative dependencies detailed', (done) => { + chai.request(server) + .get('/api/v1/school/adm_dependency_detailed') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the government agreement', (done) => { + chai.request(server) + .get('/api/v1/school/government_agreement') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the agreement', (done) => { + chai.request(server) + .get('/api/v1/school/agreement') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the building school', (done) => { + chai.request(server) + .get('/api/v1/school/building_school') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the informatics labs', (done) => { + chai.request(server) + .get('/api/v1/school/informatics_lab') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the science labs', (done) => { + chai.request(server) + .get('/api/v1/school/science_lab') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the directors room', (done) => { + chai.request(server) + .get('/api/v1/school/directors_room') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the teacher room', (done) => { + chai.request(server) + .get('/api/v1/school/teacher_room') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the cook room', (done) => { + chai.request(server) + .get('/api/v1/school/cook_room') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the playgrounds', (done) => { + chai.request(server) + .get('/api/v1/school/playground') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the indor sports court', (done) => { + chai.request(server) + .get('/api/v1/school/indor_sports_court') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the nusery', (done) => { + chai.request(server) + .get('/api/v1/school/nusery') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the special attendence room', (done) => { + chai.request(server) + .get('/api/v1/school/special_attendence_room') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the toilets inside building', (done) => { + chai.request(server) + .get('/api/v1/school/toilet_inside_building') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the denpendency pne', (done) => { + chai.request(server) + .get('/api/v1/school/denpendency_pne') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the restroom pne', (done) => { + chai.request(server) + .get('/api/v1/school/restroom_pne') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the broadband', (done) => { + chai.request(server) + .get('/api/v1/school/broadband') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the energy', (done) => { + chai.request(server) + .get('/api/v1/school/energy') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the water', (done) => { + chai.request(server) + .get('/api/v1/school/water') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the wastepipe', (done) => { + chai.request(server) + .get('/api/v1/school/wastepipe') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education day care child', (done) => { + chai.request(server) + .get('/api/v1/school/education_day_care_child') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education preschool child', (done) => { + chai.request(server) + .get('/api/v1/school/education_preschool_child') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education begin elementary school', (done) => { + chai.request(server) + .get('/api/v1/school/education_begin_elementary_school') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education begin elementary school', (done) => { + chai.request(server) + .get('/api/v1/school/education_begin_elementary_school') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education end elementary school', (done) => { + chai.request(server) + .get('/api/v1/school/education_end_elementary_school') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education middle school', (done) => { + chai.request(server) + .get('/api/v1/school/education_middle_school') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education professional', (done) => { + chai.request(server) + .get('/api/v1/school/education_professional') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education eja', (done) => { + chai.request(server) + .get('/api/v1/school/education_eja') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the reading room', (done) => { + chai.request(server) + .get('/api/v1/school/reading_room') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the library and/or reading_room', (done) => { + chai.request(server) + .get('/api/v1/school/library_reading_room') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list school with valid dimensions and filters', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=location,adm_dependency,government_agreement,library,reading_room,library_reading_room') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('location_name'); + res.body.result[0].should.have.property('adm_dependency_name'); + res.body.result[0].should.have.property('government_agreement_name'); + res.body.result[0].should.have.property('library_name'); + res.body.result[0].should.have.property('reading_room_name'); + res.body.result[0].should.have.property('library_reading_room_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=region,state,cook_room&filter=min_year:2015,max_year:2016,city:4106902,indor_sports_court:1') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('region_name'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('cook_room_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with no argument dimensions and filters', (done) => { + chai.request(server) + .get('/api/v1/school/count') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters of states', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=state&filter=min_year:2015,max_year:2016') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters of states', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=state,education_professional,education_eja&filter=min_year:2015,max_year:2016') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('education_professional_name'); + res.body.result[0].should.have.property('education_eja_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters of states', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=state&filter=min_year:2015,max_year:2016') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters of states that have no toilet inside building', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=state&filter=min_year:2015,max_year:2016,toilet_inside_building:0') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters of states with energy and water', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=state&filter=min_year:2015,max_year:2016,energy:1,water:1') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters related to library and reading_room of Curitiba', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=city,library,reading_room,library_reading_room&filter=min_year:2015,max_year:2016,city:4106902') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('city_name'); + res.body.result[0].should.have.property('library_name'); + res.body.result[0].should.have.property('reading_room_name'); + res.body.result[0].should.have.property('library_reading_room_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list school with valid dimensions and filters related to library and reading_room of cities of Paraná', (done) => { + chai.request(server) + .get('/api/v1/school/count?dims=city,library,reading_room,library_reading_room&filter=min_year:2015,max_year:2016,state:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('city_name'); + res.body.result[0].should.have.property('library_name'); + res.body.result[0].should.have.property('reading_room_name'); + res.body.result[0].should.have.property('library_reading_room_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); +}); diff --git a/src/test/teacher.js b/src/test/teacher.js new file mode 100644 index 0000000000000000000000000000000000000000..0b3cb7bdd528ddde998d5fc35e1aabd35e95b1c9 --- /dev/null +++ b/src/test/teacher.js @@ -0,0 +1,327 @@ +process.env.NODE_ENV = 'test'; + +const chai = require('chai'); + +const dirtyChai = require('dirty-chai'); + +chai.use(dirtyChai); + +const chaiXml = require('chai-xml'); + +chai.use(chaiXml); + +const chaiHttp = require('chai-http'); + +const assert = chai.assert; + +const expect = chai.expect; + +const should = chai.should(); // actually call the function + +const libs = `${process.cwd()}/libs`; + +const server = require(`${libs}/app`); + +chai.use(chaiHttp); +describe('request teachers', () => { + it('should list the year range', (done) => { + chai.request(server) + .get('/api/v1/teacher/year_range') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('start_year'); + res.body.result[0].should.have.property('end_year'); + done(); + }); + }); + + it('should list the locations', (done) => { + chai.request(server) + .get('/api/v1/teacher/location') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education level mod', (done) => { + chai.request(server) + .get('/api/v1/teacher/education_level_mod') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the education type', (done) => { + chai.request(server) + .get('/api/v1/teacher/education_type') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the administrative dependencies', (done) => { + chai.request(server) + .get('/api/v1/teacher/adm_dependency') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the administrative dependencies detailed', (done) => { + chai.request(server) + .get('/api/v1/teacher/adm_dependency_detailed') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list genders', (done) => { + chai.request(server) + .get('/api/v1/teacher/gender') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + it('should list the ethnic groups', (done) => { + chai.request(server) + .get('/api/v1/teacher/ethnic_group') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('id'); + res.body.result[0].should.have.property('name'); + done(); + }); + }); + + + it('should list teachers count', (done) => { + chai.request(server) + .get('/api/v1/teacher') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list teacher count with valid filters', (done) => { + chai.request(server) + .get('/api/v1/teacher?filter=min_year:2014,state:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list teacher count with invalid filters', (done) => { + chai.request(server) + .get('/api/v1/teacher?filter=foo:2010,bar:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list teacher count with valid dimensions', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=region,state,adm_dependency,location,gender,ethnic_group') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('region_name'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('adm_dependency_name'); + res.body.result[0].should.have.property('location_name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list teacher count with invalid dimensions', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=foo,bar') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('name'); + res.body.result[0].should.have.property('total'); + done(); + }); + }); + + it('should list teacher count with valid dimensions and filters', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=region,state,school,gender&filter=min_year:2015,max_year:2015,city:4106902') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('region_name'); + res.body.result[0].should.have.property('state_name'); + res.body.result[0].should.have.property('school_name'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + done(); + }); + }); + + it('should list teacher count with dimension location', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=location') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('location_name'); + res.body.result[0].should.not.have.property('location_id'); + done(); + }); + }); + + it('should list teacher count with dimension education_level_mod', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=education_level_mod') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('education_level_mod_name'); + res.body.result[0].should.not.have.property('education_level_mod_id'); + done(); + }); + }); + + it('should list teacher count with dimension education type', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=education_type') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('education_type_name'); + res.body.result[0].should.not.have.property('education_type_id'); + done(); + }); + }); + + it('should list teacher count with dimension adm_dependency', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=adm_dependency') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('adm_dependency_name'); + res.body.result[0].should.not.have.property('adm_dependency_id'); + done(); + }); + }); + + it('should list teacher count with dimension adm_dependency_detailed', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=adm_dependency_detailed') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('adm_dependency_detailed_name'); + res.body.result[0].should.not.have.property('adm_dependency_detailed_id'); + done(); + }); + }); + + it('should list teacher count with dimension gender', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=gender') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('gender_name'); + res.body.result[0].should.not.have.property('gender_id'); + done(); + }); + }); + + it('should list teacher count with dimension ethnic_group', (done) => { + chai.request(server) + .get('/api/v1/teacher?dims=ethnic_group') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('ethnic_group_name'); + res.body.result[0].should.not.have.property('ethnic_group_id'); + done(); + }); + }); +});