diff --git a/src/libs/routes/schoolInfrastructure.js b/src/libs/routes/schoolInfrastructure.js index f51102fe851985690e530242eaa25dc3b91fbf15..835f0f6efa548a07f924a1ef0768e8aa236f61a8 100644 --- a/src/libs/routes/schoolInfrastructure.js +++ b/src/libs/routes/schoolInfrastructure.js @@ -87,19 +87,26 @@ infrastructureApp.get('/rural_location', (req, res, next) => { }, response('rural_location')); infrastructureApp.get('/adm_dependency', (req, res, next) => { - req.sql.from('dependencia_adm') - .field('id') - .field('nome', 'name') - .where('id <= 4'); + req.result = []; + for(let i = 1; i <= 4; ++i) { + req.result.push({ + id: i, + name: id2str.admDependency(i) + }); + }; next(); -}, query, response('adm_dependency')); +}, response('adm_dependency')); infrastructureApp.get('/adm_dependency_detailed', (req, res, next) => { - req.sql.from('dependencia_adm_priv') - .field('id', 'id') - .field('nome', 'name'); + req.result = []; + for(let i = 1; i <= 6; ++i) { + req.result.push({ + id: i, + name: id2str.admDependencyPriv(i) + }); + }; next(); -}, query, response('adm_dependency_detailed')); +}, response('adm_dependency_detailed')); rqf.addField({ name: 'filter', diff --git a/src/test/schoolInfrastructure.js b/src/test/schoolInfrastructure.js new file mode 100644 index 0000000000000000000000000000000000000000..f167fb1ff2aa7521a5018066e40616ff5b56f10b --- /dev/null +++ b/src/test/schoolInfrastructure.js @@ -0,0 +1,183 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +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 school infrastructure', () => { + it('should list the default school insfrastructure query', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure') + .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('schools_in_school_buildings'); + res.body.result[0].should.have.property('urban_schools_in_school_buildings'); + res.body.result[0].should.have.property('country_schools_in_school_buildings'); + res.body.result[0].should.have.property('schools_not_in_school_buildings'); + res.body.result[0].should.have.property('libraries'); + res.body.result[0].should.have.property('libraries_reading_room'); + res.body.result[0].should.have.property('computer_lab'); + res.body.result[0].should.have.property('science_lab'); + res.body.result[0].should.have.property('kids_park'); + res.body.result[0].should.have.property('nursery'); + res.body.result[0].should.have.property('sports_court'); + res.body.result[0].should.have.property('sports_court_coverage'); + res.body.result[0].should.have.property('courtyard'); + res.body.result[0].should.have.property('courtyard_coverage'); + res.body.result[0].should.have.property('director_room'); + res.body.result[0].should.have.property('secretary'); + res.body.result[0].should.have.property('teacher_room'); + res.body.result[0].should.have.property('kitchen'); + res.body.result[0].should.have.property('storeroom'); + res.body.result[0].should.have.property('warehouse'); + res.body.result[0].should.have.property('internet'); + res.body.result[0].should.have.property('broadband_internet'); + res.body.result[0].should.have.property('inside_bathroom'); + res.body.result[0].should.have.property('inside_kids_bathroom'); + res.body.result[0].should.have.property('eletric_energy'); + res.body.result[0].should.have.property('water_supply'); + res.body.result[0].should.have.property('filtered_water'); + res.body.result[0].should.have.property('sewage_treatment'); + res.body.result[0].should.have.property('adapted_building'); + res.body.result[0].should.have.property('special_bathroom'); + done(); + }); + }); + it('should list the year range', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure/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 years', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure/years') + .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('year'); + done(); + }); + }); + + it('should list the source', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure/source') + .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('source'); + done(); + }); + }); + + it('should list the location', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure/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 rural location', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure/rural_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 adm dependency', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure/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 adm dependency detailed', (done) => { + chai.request(server) + .get('/api/v1/school_infrastructure/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(); + }); + }); +}); \ No newline at end of file