diff --git a/src/libs/middlewares/reqQueryFields.js b/src/libs/middlewares/reqQueryFields.js index f65efc81d28787ca753909aeeb8f10c797b4afd6..7f4a1399e1369350d1b8b1b383e70bd7918e5fed 100644 --- a/src/libs/middlewares/reqQueryFields.js +++ b/src/libs/middlewares/reqQueryFields.js @@ -198,9 +198,9 @@ class ReqQueryFields { build() { // "Constrói" o SQL return (req, res, next) => { - // Foreach no campos let hasJoined = {}; let thisTable = req.sql.tableFrom; + // Foreach no campos Object.keys(this.fields).forEach((key) => { // Campo let field = this.fields[key]; diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index 43fec48396eb4731d4d4e112b35aa4c617955ead..18ed066486287be2d022551c103060287642ae07 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -59,7 +59,7 @@ api.use('/state', state); api.use('/region', region); api.use('/city', city); api.use('/school', school); -api.use('/spatial', spatial); +// api.use('/spatial', spatial); api.use('/classroom', classroom); api.use('/teacher', teacher); api.use('/idhmr', idhmr); diff --git a/src/libs/routes/class.js b/src/libs/routes/class.js index 5313c21bde095d05fffeeccad450f9430461ff16..46732ccb8809233953d6ea4d3e8e758b7476c5e7 100644 --- a/src/libs/routes/class.js +++ b/src/libs/routes/class.js @@ -85,11 +85,19 @@ classApp.get('/adm_dependency_detailed', (req, res, next) => { // Returns all periods avaible classApp.get('/period', (req, res, next) => { - req.sql.from('turma_turno') - .field('id') - .field('nome', 'name'); + req.result = []; + for(let i=1; i <= 3; ++i) { + req.result.push({ + id: i, + name: id2str.period(i) + }); + } + req.result.push({ + id: 99, + name: id2str.period(99) + }); next(); -}, query, response('period')); +}, response('period')); // Returns integral-time avaible classApp.get('/integral_time', (req, res, next) => { @@ -103,11 +111,19 @@ classApp.get('/integral_time', (req, res, next) => { // Returns all educational levels avaible classApp.get('/education_level_mod', (req, res, next) => { - req.sql.from('etapas_mod_ensino_segmento') - .field('id') - .field('nome', 'name'); + req.result = []; + for(let i = 1; i <=11; ++i) { + req.result.push({ + id: i, + name: id2str.educationLevelMod(i) + }); + } + req.result.push({ + id: 99, + name: id2str.educationLevelMod(99) + }); next(); -}, query, response('education_level_mod')); +}, response('education_level_mod')); classApp.get('/education_level_short', (req, res, next) => { req.result = [ diff --git a/src/libs/routes/enrollment.js b/src/libs/routes/enrollment.js index ba4d89320543232ca197ab534aebc5a0bdac6ef6..12d97c53c9ff9fa84cb2b94e5a8a857bb983b203 100644 --- a/src/libs/routes/enrollment.js +++ b/src/libs/routes/enrollment.js @@ -69,27 +69,59 @@ enrollmentApp.get('/rural_location', (req, res, next) => { // Returns all school years available enrollmentApp.get('/school_year', (req, res, next) => { - req.sql.from('serie_ano') - .field('id') - .field('nome', 'name'); + req.result = []; + for(let i = 11; i <= 71; ++i) { + let obj = { + id: i, + name: id2str.schoolYear(i) + }; + + if(obj.name !== id2str.schoolYear(99)) { + req.result.push(obj); + } + } + req.result.push({ + id: 99, + name: id2str.schoolYear(99) + }); next(); -}, query, response('school_year')); +}, response('school_year')); // Returns all school years available enrollmentApp.get('/education_level', (req, res, next) => { - req.sql.from('etapa_ensino') - .field('id') - .field('desc_etapa', 'name'); + req.result = []; + for(let i = 1; i <= 74; ++i) { + let obj = { + id: i, + name: id2str.educationLevel(i) + }; + + if(obj.name !== id2str.educationLevel(99)) { + req.result.push(obj); + } + } + req.result.push({ + id: 99, + name: id2str.educationLevel(99) + }); next(); -}, query, response('education_level')); +}, response('education_level')); // Returns all school years available enrollmentApp.get('/education_level_mod', (req, res, next) => { - req.sql.from('etapas_mod_ensino_segmento') - .field('id') - .field('nome', 'name'); + req.result = []; + for(let i = 1; i <= 11; ++i) { + req.result.push({ + id: i, + name: id2str.educationLevelMod(i) + }); + } + req.result.push({ + id: 99, + name: id2str.educationLevelMod(99) + }); next(); -}, query, response('education_level_mod')); +}, response('education_level_mod')); enrollmentApp.get('/education_level_short', (req, res, next) => { req.result = [ @@ -132,18 +164,30 @@ enrollmentApp.get('/gender', (req, res, next) => { // Return ethnic group enrollmentApp.get('/ethnic_group', (req, res, next) => { - req.sql.from('cor_raca') - .field('id') - .field('nome', 'name'); + req.result = []; + for(let i = 0; i <=5; ++i) { + req.result.push({ + id: i, + name: id2str.ethnicGroup(i) + }); + } next(); -}, query, response('ethnic_group')); +}, response('ethnic_group')); enrollmentApp.get('/period', (req, res, next) => { - req.sql.from('turma_turno') - .field('id') - .field('nome', 'name'); + req.result = []; + for(let i = 1; i <= 3; ++i) { + req.result.push({ + id: i, + name: id2str.period(i) + }); + } + req.result.push({ + id: 99, + name: id2str.period(99) + }); next(); -}, query, response('period')); +}, response('period')); // Returns integral-time avaible enrollmentApp.get('/integral_time', (req, res, next) => { diff --git a/src/libs/routes/idhm.js b/src/libs/routes/idhm.js index f9336c5a256235ddb3dd7a4a68a7c920ba43066d..c757a0e7227a0acd1fef7336b14aedb41ec494da 100644 --- a/src/libs/routes/idhm.js +++ b/src/libs/routes/idhm.js @@ -65,6 +65,13 @@ idhmApp.get('/years', (req, res, next) => { next(); }, response('years')); +idhmApp.get('/source', (req, res, next) => { + req.sql.from('fonte') + .field('fonte', 'source') + .where('tabela = \'adh_idh\''); + next(); +}, query, response('source')); + idhmApp.get('/IDHM_level', (req, res, next) => { req.result = [ {id: null, name: 'Não classificada'}, diff --git a/src/libs/routes/idhme.js b/src/libs/routes/idhme.js index 22ef5697dbbcfdba5a7f829a206177731367e232..431380b4a178e07d306af45d219b243a4b47ce2b 100644 --- a/src/libs/routes/idhme.js +++ b/src/libs/routes/idhme.js @@ -63,6 +63,13 @@ idhmeApp.get('/years', (req, res, next) => { next(); }, response('years')); +idhmeApp.get('/source', (req, res, next) => { + req.sql.from('fonte') + .field('fonte', 'source') + .where('tabela = \'adh_idh\''); + next(); +}, query, response('source')); + rqf.addField({ name: 'filter', field: false, diff --git a/src/libs/routes/idhml.js b/src/libs/routes/idhml.js index 8d9e2e77014913ad902980244f2c1e3808cc513e..2542fae5ab340c1d7dc6e0f4812046e2d502465d 100644 --- a/src/libs/routes/idhml.js +++ b/src/libs/routes/idhml.js @@ -63,6 +63,13 @@ idhmlApp.get('/years', (req, res, next) => { next(); }, response('years')); +idhmlApp.get('/source', (req, res, next) => { + req.sql.from('fonte') + .field('fonte', 'source') + .where('tabela = \'adh_idh\''); + next(); +}, query, response('source')); + rqf.addField({ name: 'filter', field: false, diff --git a/src/libs/routes/idhmr.js b/src/libs/routes/idhmr.js index 33f950dc09e46efd41ef086738c0c237a6f018fa..1cf63b44879c9c55ad3707f4cce75a7046d318bb 100644 --- a/src/libs/routes/idhmr.js +++ b/src/libs/routes/idhmr.js @@ -65,6 +65,13 @@ idhmrApp.get('/years', (req, res, next) => { next(); }, response('years')); +idhmrApp.get('/source', (req, res, next) => { + req.sql.from('fonte') + .field('fonte', 'source') + .where('tabela = \'adh_idh\''); + next(); +}, query, response('source')); + rqf.addField({ name: 'filter', field: false, diff --git a/src/libs/routes/pibpercapita.js b/src/libs/routes/pibpercapita.js index 4080588f95cf07917ff3df75ea18b5ca09d191ff..33f50d02a2290d16e75f03c4db190df5992b4c87 100644 --- a/src/libs/routes/pibpercapita.js +++ b/src/libs/routes/pibpercapita.js @@ -37,6 +37,13 @@ pibpercapitaApp.get('/years', (req, res, next) => { next(); }, query, response('years')); +pibpercapitaApp.get('/source', (req, res, next) => { + req.sql.from('fonte') + .field('fonte', 'source') + .where('tabela = \'ibge_pib\''); + next(); +}, query, response('source')); + pibpercapitaApp.get('/income_level', (req, res, next) => { req.result = [ {id: 1, name: "1º quintil – 20% menores"}, diff --git a/src/libs/routes/school.js b/src/libs/routes/school.js index 8e72933af6d95918579e0d9e8c022f79cd1d4a8f..d91eb3266e2f3db6b8fe9f7f5214055b034d04ab 100644 --- a/src/libs/routes/school.js +++ b/src/libs/routes/school.js @@ -467,7 +467,7 @@ schoolApp.get('/count', cache('15 day'), rqfCount.parse(), rqfCount.build(), (re next(); }, query, id2str.transform(), response('school')); -schoolApp.get('/count/download', rqf.parse(), rqf.build(), (req, res, next) => { +schoolApp.get('/count/download', rqfCount.parse(), rqfCount.build(), (req, res, next) => { let username = req.query.user; let email = req.query.email; diff --git a/src/libs/routes/teacher.js b/src/libs/routes/teacher.js index 845cf0df1214e277d32e63320795352cb0487e98..4401a16d8ac79d63e8b16b8c4f5b950af86a6a20 100644 --- a/src/libs/routes/teacher.js +++ b/src/libs/routes/teacher.js @@ -61,11 +61,20 @@ teacherApp.get('/adm_dependency', (req, res, 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'); + req.result = []; + for(let i = 1; i <= 11; ++i) { + req.result.push({ + id: i, + name: id2str.educationLevelMod(i) + }); + } + + req.result.push({ + id: 99, + name: id2str.educationLevelMod(99) + }); next(); -}, query, response('education_level_mod')); +}, response('education_level_mod')); teacherApp.get('/education_level_short', (req, res, next) => { req.result = [ @@ -122,11 +131,15 @@ teacherApp.get('/gender', (req, res, next) => { }, response('gender')); teacherApp.get('/ethnic_group', (req, res, next) => { - req.sql.from('cor_raca') - .field('id') - .field('nome', 'name'); + req.result = []; + for(let i = 0; i <=5; ++i) { + req.result.push({ + id: i, + name: id2str.ethnicGroup(i) + }); + } next(); -}, query, response('ethnic_group')); +}, response('ethnic_group')); rqf.addField({ name: 'filter', @@ -323,16 +336,54 @@ rqf.addField({ } }); -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 AND docente.ano_censo=turma.ano_censo') - .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(), response('teacher')); +teacherApp.get('/', rqf.parse(), (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 AND docente.ano_censo=turma.ano_censo') + .group('docente.ano_censo') + .order('docente.ano_censo') + .where('(docente.tipo_docente = 1 OR docente.tipo_docente = 5) AND (turma.tipo_turma_id <= 3)'); + + if("education_level_mod" in req.dims) { + delete req.dims.education_level_mod; + req.hadEducationLevelMod = true; + req.sql.field('docente.etapas_mod_ensino_segmento_id', 'education_level_mod_id') + .where('docente.etapas_mod_ensino_segmento_id < 11') + .group('docente.etapas_mod_ensino_segmento_id'); + } + + next(); +}, rqf.build(), query, (req, res, next) => { + req.oldResult = req.result; + if(req.hadEducationLevelMod) { + + req.sql = squel.select() + .field('COUNT(DISTINCT docente.id)', 'total') + .field("'Brasil'", 'name') + .field('docente.ano_censo', 'year') + .from('docente') + .join('turma', null, 'docente.turma_id=turma.id AND docente.ano_censo=turma.ano_censo') + .group('docente.ano_censo') + .order('docente.ano_censo') + .where('(docente.tipo_docente = 1 OR docente.tipo_docente = 5) AND (turma.tipo_turma_id <= 3)') + .where('docente.profissionalizante = 1'); + + rqf.build()(req, res, () => {}); + query(req, res, next); + } else { + next(); + } +}, /*rqf.build(), query,*/ (req, res, next) => { + if(req.hadEducationLevelMod) { + req.result.forEach((result) => { + result.education_level_mod_id = 11; + req.oldResult.push(result); + }); + } + req.result = req.oldResult; + next(); +}, id2str.transform(), response('teacher')); module.exports = teacherApp; diff --git a/src/test/query.js b/src/test/query.js index df6269dff8460b9a867b7d54064886214b9b7d12..8b6c4541859c20f3ea733046cddc8af81b01d0b3 100644 --- a/src/test/query.js +++ b/src/test/query.js @@ -75,16 +75,13 @@ describe('Query middleware', () => { }); }); - it('should return 404 with an empty query result', (done) => { + it('should not return 404 with an empty query result', (done) => { let req = { sql: squel.select().field('*').from('regiao').where('id>6') }; let res = {}; query(req, {}, (error)=>{ - error.should.have.property('status'); - error.status.should.be.equal(404); - error.should.have.property('message'); - error.message.should.be.equal('No results found in database'); + req.should.have.property('result'); done(); }); }); diff --git a/src/test/spatial.js b/src/test/spatial.js deleted file mode 100644 index b4422e7911a30b19e2d0f7a73a9b1d62389df1b4..0000000000000000000000000000000000000000 --- a/src/test/spatial.js +++ /dev/null @@ -1,564 +0,0 @@ -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); - -const testTimeout = 60000; - -describe('test spatial', () => { - it('should return the expected response format for sociodemographic data for the whole country', (done) => { - chai.request(server) - .get('/api/v1/spatial/sociodemographic') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('population'); - res.body.result.should.have.property('gdp'); - res.body.result.should.have.property('idh'); - res.body.result.should.have.property('analfab'); - res.body.result.should.have.property('gini'); - // test response attributes for population - res.body.result.population.should.have.property('name'); - res.body.result.population.should.have.property('population'); - res.body.result.population.should.have.property('census_year'); - // test response attributes for gdp - res.body.result.gdp.should.have.property('name'); - res.body.result.gdp.should.have.property('gdp_per_capita'); - res.body.result.gdp.should.have.property('census_year'); - // test response attributes for idh - res.body.result.idh.should.have.property('name'); - res.body.result.idh.should.have.property('idhm'); - res.body.result.idh.should.have.property('census_year'); - // test response attributes for analfab - res.body.result.analfab.should.have.property('name'); - res.body.result.analfab.should.have.property('analfabetism'); - res.body.result.analfab.should.have.property('census_year'); - // test response attributes for gini - res.body.result.gini.should.have.property('name'); - res.body.result.gini.should.have.property('gini'); - res.body.result.gini.should.have.property('census_year'); - done(); - }); - }).timeout(testTimeout); - - it('should return the expected response format for sociodemographic data for a region', (done) => { - chai.request(server) - .get('/api/v1/spatial/sociodemographic?filter=region:1') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('population'); - res.body.result.should.have.property('gdp'); - res.body.result.should.have.property('idh'); - res.body.result.should.have.property('analfab'); - res.body.result.should.have.property('gini'); - // test response attributes for population - res.body.result.population.should.have.property('name'); - res.body.result.population.should.have.property('population'); - res.body.result.population.should.have.property('census_year'); - // test response attributes for gdp - res.body.result.gdp.should.have.property('name'); - res.body.result.gdp.should.have.property('gdp_per_capita'); - res.body.result.gdp.should.have.property('census_year'); - // test response attributes for idh - res.body.result.idh.should.have.property('name'); - res.body.result.idh.should.have.property('idhm'); - res.body.result.idh.should.have.property('census_year'); - // test response attributes for analfab - res.body.result.analfab.should.have.property('name'); - res.body.result.analfab.should.have.property('analfabetism'); - res.body.result.analfab.should.have.property('census_year'); - // test response attributes for gini - res.body.result.gini.should.have.property('name'); - res.body.result.gini.should.have.property('gini'); - res.body.result.gini.should.have.property('census_year'); - done(); - }); - }).timeout(testTimeout); - - it('should return the expected response format for sociodemographic data for a state', (done) => { - chai.request(server) - .get('/api/v1/spatial/sociodemographic?filter=state:42') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('population'); - res.body.result.should.have.property('gdp'); - res.body.result.should.have.property('idh'); - res.body.result.should.have.property('analfab'); - res.body.result.should.have.property('gini'); - // test response attributes for population - res.body.result.population.should.have.property('name'); - res.body.result.population.should.have.property('population'); - res.body.result.population.should.have.property('census_year'); - // test response attributes for gdp - res.body.result.gdp.should.have.property('name'); - res.body.result.gdp.should.have.property('gdp_per_capita'); - res.body.result.gdp.should.have.property('census_year'); - // test response attributes for idh - res.body.result.idh.should.have.property('name'); - res.body.result.idh.should.have.property('idhm'); - res.body.result.idh.should.have.property('census_year'); - // test response attributes for analfab - res.body.result.analfab.should.have.property('name'); - res.body.result.analfab.should.have.property('analfabetism'); - res.body.result.analfab.should.have.property('census_year'); - // test response attributes for gini - res.body.result.gini.should.have.property('name'); - res.body.result.gini.should.have.property('gini'); - res.body.result.gini.should.have.property('census_year'); - done(); - }); - }).timeout(testTimeout); - - it('should return the expected response format for sociodemographic data for a city', (done) => { - chai.request(server) - .get('/api/v1/spatial/sociodemographic?filter=city:4106902') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('population'); - res.body.result.should.have.property('gdp'); - res.body.result.should.have.property('idh'); - res.body.result.should.have.property('analfab'); - res.body.result.should.have.property('gini'); - // test response attributes for population - res.body.result.population.should.have.property('name'); - res.body.result.population.should.have.property('population'); - res.body.result.population.should.have.property('census_year'); - // test response attributes for gdp - res.body.result.gdp.should.have.property('name'); - res.body.result.gdp.should.have.property('gdp_per_capita'); - res.body.result.gdp.should.have.property('census_year'); - // test response attributes for idh - res.body.result.idh.should.have.property('name'); - res.body.result.idh.should.have.property('idhm'); - res.body.result.idh.should.have.property('census_year'); - // test response attributes for analfab - res.body.result.analfab.should.have.property('name'); - res.body.result.analfab.should.have.property('analfabetism'); - res.body.result.analfab.should.have.property('census_year'); - // test response attributes for gini - res.body.result.gini.should.have.property('name'); - res.body.result.gini.should.have.property('gini'); - res.body.result.gini.should.have.property('census_year'); - done(); - }); - }).timeout(testTimeout); - - it('should return the expected response format for educational data for the whole country', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('school'); - res.body.result.school.should.be.a('array'); - res.body.result.should.have.property('school_per_location'); - res.body.result.school_per_location.should.be.a('array'); - res.body.result.should.have.property('enrollment'); - res.body.result.enrollment.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_adm_dep'); - res.body.result.enrollment_per_adm_dep.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_school_level'); - res.body.result.enrollment_per_school_level.should.be.a('array'); - // test response attributes for school - res.body.result.school.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for school_per_location - res.body.result.school_per_location.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment - res.body.result.enrollment.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('adm_dependency_name'); - }); - // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('school_level_name'); - }); - done(); - }); - }).timeout(testTimeout); - - it('should return the expected response format for educational data for a country region', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational?filter=region:1') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('school'); - res.body.result.school.should.be.a('array'); - res.body.result.should.have.property('school_per_location'); - res.body.result.school_per_location.should.be.a('array'); - res.body.result.should.have.property('enrollment'); - res.body.result.enrollment.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_adm_dep'); - res.body.result.enrollment_per_adm_dep.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_school_level'); - res.body.result.enrollment_per_school_level.should.be.a('array'); - // test response attributes for school - res.body.result.school.should.a('array'); - res.body.result.school.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for school_per_location - res.body.result.school_per_location.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment - res.body.result.enrollment.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('adm_dependency_name'); - }); - // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('school_level_name'); - }); - done(); - }); - }).timeout(testTimeout); - - it('should return the expected response format for educational data for a country state', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational?filter=state:42') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('school'); - res.body.result.school.should.be.a('array'); - res.body.result.should.have.property('school_per_location'); - res.body.result.school_per_location.should.be.a('array'); - res.body.result.should.have.property('enrollment'); - res.body.result.enrollment.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_adm_dep'); - res.body.result.enrollment_per_adm_dep.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_school_level'); - res.body.result.enrollment_per_school_level.should.be.a('array'); - // test response attributes for school - res.body.result.school.should.a('array'); - res.body.result.school.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for school_per_location - res.body.result.school_per_location.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment - res.body.result.enrollment.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('adm_dependency_name'); - }); - // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('school_level_name'); - }); - done(); - }); - }).timeout(testTimeout); - - it('should return the expected response format for educational data for a country city', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational?filter=city:4106902') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - // test result type - res.body.result.should.be.a('object'); - res.body.result.should.have.property('school'); - res.body.result.school.should.be.a('array'); - res.body.result.should.have.property('school_per_location'); - res.body.result.school_per_location.should.be.a('array'); - res.body.result.should.have.property('enrollment'); - res.body.result.enrollment.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_adm_dep'); - res.body.result.enrollment_per_adm_dep.should.be.a('array'); - res.body.result.should.have.property('enrollment_per_school_level'); - res.body.result.enrollment_per_school_level.should.be.a('array'); - // test response attributes for school - res.body.result.school.should.a('array'); - res.body.result.school.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for school_per_location - res.body.result.school_per_location.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('location_name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment - res.body.result.enrollment.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - }); - // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('adm_dependency_name'); - }); - // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('name'); - row.should.have.property('total'); - row.should.have.property('census_year'); - row.should.have.property('school_level_name'); - }); - done(); - }); - }).timeout(testTimeout); - - it('should return the correct format of enrollments per school level', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational/school_level') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - // test response attributes for school - res.body.result.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('degree'); - row.should.have.property('census_year'); - row.should.have.property('table'); - row.table.should.be.a('array'); - row.table.forEach((tableRow) => { - tableRow.should.be.a('object'); - tableRow.should.have.property('title'); - tableRow.should.have.property('value'); - tableRow.title.should.be.a('String'); - tableRow.value.should.be.a('Number'); - }); - }); - done(); - }); - }).timeout(testTimeout); - - it('should return the correct format of enrollments per school level for a region', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational/school_level?filter=region:1') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - // test response attributes for school - res.body.result.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('degree'); - row.should.have.property('census_year'); - row.should.have.property('table'); - row.table.should.be.a('array'); - row.table.forEach((tableRow) => { - tableRow.should.be.a('object'); - tableRow.should.have.property('title'); - tableRow.should.have.property('value'); - tableRow.title.should.be.a('String'); - tableRow.value.should.be.a('Number'); - }); - }); - done(); - }); - }).timeout(testTimeout); - - it('should return the correct format of enrollments per school level for a state', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational/school_level?filter=state:42') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - // test response attributes for school - res.body.result.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('degree'); - row.should.have.property('census_year'); - row.should.have.property('table'); - row.table.should.be.a('array'); - row.table.forEach((tableRow) => { - tableRow.should.be.a('object'); - tableRow.should.have.property('title'); - tableRow.should.have.property('value'); - tableRow.title.should.be.a('String'); - tableRow.value.should.be.a('Number'); - }); - }); - done(); - }); - }).timeout(testTimeout); - - it('should return the correct format of enrollments per school level for a city', (done) => { - chai.request(server) - .get('/api/v1/spatial/educational/school_level?filter=city:4106902') - .end((err, res) => { - res.should.have.status(200); - // test response format - res.should.be.json; - // test for result attribute in the response - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - // test response attributes for school - res.body.result.forEach((row) => { - row.should.be.a('object'); - row.should.have.property('degree'); - row.should.have.property('census_year'); - row.should.have.property('table'); - row.table.should.be.a('array'); - row.table.forEach((tableRow) => { - tableRow.should.be.a('object'); - tableRow.should.have.property('title'); - tableRow.should.have.property('value'); - tableRow.title.should.be.a('String'); - tableRow.value.should.be.a('Number'); - }); - }); - done(); - }); - }).timeout(testTimeout); -}); diff --git a/src/test/teacher.js b/src/test/teacher.js index d32c93e9ad505484de1e3f943fd13d86d8514ba6..ab722be4290ded974d783a31f3da76105adf28b2 100644 --- a/src/test/teacher.js +++ b/src/test/teacher.js @@ -294,7 +294,7 @@ describe('request teachers', () => { }); }); - it('should list enrollment with dimension education_level_short', (done) => { + it('should list teacher with dimension education_level_short', (done) => { chai.request(server) .get('/api/v1/teacher?dims=education_level_short') .end((err, res) => {