diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 0ad22595aeee07c654a1afa0f9d09647d8d071de..b04d93d43dcda10ef5266c97184fa063990fbdff 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -74,7 +74,7 @@ gulp.task('test', ['pre-test'], () => { gulp.src('test/test.js', {read: false}) .pipe(mocha()) .pipe(istanbul.writeReports()) - .pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } })) + .pipe(istanbul.enforceThresholds({ thresholds: { global: 75 } })) .once('error', () => { process.exit(1); }) diff --git a/src/libs/routes/school.js b/src/libs/routes/school.js index 8662d945f4f39989bc318709e7beab9802a3bfb8..6c92430b425d3b9fde8c682216c8f6a10f07b75f 100644 --- a/src/libs/routes/school.js +++ b/src/libs/routes/school.js @@ -37,8 +37,8 @@ schoolApp.get('/:id', (req, res, next) => { schoolApp.get('/state/:id', (req, res, next) => { req.sql.from('escolas') .field('pk_escola_id') - .field('nome_entidade', 'name') - .field('ano_censo', 'year') + .field('nome_entidade') + .field('ano_censo') .field('fk_cod_estado') .field('fk_cod_municipio') .where('fk_cod_estado = ?', parseInt(req.params.id, 10)); @@ -49,8 +49,8 @@ schoolApp.get('/state/:id', (req, res, next) => { schoolApp.get('/city/:id', (req, res, next) => { req.sql.from('escolas') .field('pk_escola_id') - .field('nome_entidade', 'name') - .field('ano_censo', 'year') + .field('nome_entidade') + .field('ano_censo') .field('fk_cod_estado') .field('fk_cod_municipio') .where('fk_cod_municipio = ?', parseInt(req.params.id, 10)); diff --git a/src/test/test.js b/src/test/test.js index f06f837ef405c00dd4bc5bdb5f5c812f722c6ccb..a7e17edac1b67ebeb0a9b1f3f18951f54e78b6f6 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -18,6 +18,19 @@ const server = require(`${libs}/app`); chai.use(chaiHttp); +describe('API is running', () => { + it('should respond it\'s running', (done) => { + chai.request(server) + .get('/api/v1') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('msg'); + done(); + }) + }); +}); + describe('request enrollments', () => { it('should list enrollments', (done) => { chai.request(server) @@ -161,4 +174,68 @@ describe('request cities', () => { done(); }); }); + + it('should list all cities from a state', (done) => { + chai.request(server) + .get('/api/v1/city/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('pk_municipio_id'); + res.body.result[0].should.have.property('fk_estado_id'); + res.body.result[0].should.have.property('nome'); + res.body.result[0].should.have.property('codigo_ibge'); + done(); + }) + }) +}); + +describe('request schools', () => { + it('should list a school by id', (done) => { + chai.request(server) + .get('/api/v1/school/185588') + .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('pk_escola_id'); + res.body.result[0].should.have.property('ano_censo'); + res.body.result[0].should.have.property('cod_entidade'); + res.body.result[0].should.have.property('nome_entidade'); + done(); + }); + }); + + it('should list all schools from a state', (done) => { + chai.request(server) + .get('/api/v1/school/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('pk_escola_id'); + res.body.result[0].should.have.property('ano_censo'); + res.body.result[0].should.have.property('nome_entidade'); + done(); + }); + }); + + it('should list all schools from a city', (done) => { + chai.request(server) + .get('/api/v1/school/city/3287') + .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('pk_escola_id'); + res.body.result[0].should.have.property('ano_censo'); + res.body.result[0].should.have.property('nome_entidade'); + done(); + }) + }) });