From e6c24d6573af1492aa31228804fc231dbab105eb Mon Sep 17 00:00:00 2001 From: Vytor Calixto <vytorcalixto@gmail.com> Date: Tue, 4 Oct 2016 10:34:20 -0300 Subject: [PATCH] Add more test cases --- gulpfile.babel.js | 2 +- src/libs/routes/school.js | 8 ++-- src/test/test.js | 77 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 0ad22595..b04d93d4 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 8662d945..6c92430b 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 f06f837e..a7e17eda 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(); + }) + }) }); -- GitLab