diff --git a/src/libs/routes/idhme.js b/src/libs/routes/idhme.js index 9667d5b2151061f9badce0dc7ce194fdd1f2eba2..9b4672efe4f50be75866c2169422afeb9ed509af 100644 --- a/src/libs/routes/idhme.js +++ b/src/libs/routes/idhme.js @@ -131,7 +131,7 @@ idhmeApp.get('/', rqf.parse(), (req, res, next) => { .group('adh_idh.idhm_e') .group('adh_idh.ano_censo') .group('adh_idh.municipio_id'); - } else { + } else if (("state" in req.filter) || ("state" in req.dims)) { req.sql.from('adh_idh_uf') .field('adh_idh_uf.idhm_e', 'total') .field('adh_idh_uf.ano_censo', 'year') @@ -139,6 +139,12 @@ idhmeApp.get('/', rqf.parse(), (req, res, next) => { .group('adh_idh_uf.idhm_e') .group('adh_idh_uf.ano_censo') .group('adh_idh_uf.estado_id'); + } else { + res.status(400); + next({ + status: 400, + message: 'Wrong/No filter specified' + }); } next(); }, rqf.build(), query, id2str.transform(), response('idhme')); diff --git a/src/libs/routes/idhml.js b/src/libs/routes/idhml.js index be1ee7a3b7a0b00b7d914d0a9fe1d480034beae7..a24c51ccbfe0f0f108cb554f224aa12e5ecf7f42 100644 --- a/src/libs/routes/idhml.js +++ b/src/libs/routes/idhml.js @@ -131,7 +131,7 @@ idhmlApp.get('/', rqf.parse(), (req, res, next) => { .group('adh_idh.idhm_l') .group('adh_idh.ano_censo') .group('adh_idh.municipio_id'); - } else { + } else if (("state" in req.filter) || ("state" in req.dims)) { req.sql.from('adh_idh_uf') .field('adh_idh_uf.idhm_l', 'total') .field('adh_idh_uf.ano_censo', 'year') @@ -139,6 +139,12 @@ idhmlApp.get('/', rqf.parse(), (req, res, next) => { .group('adh_idh_uf.idhm_l') .group('adh_idh_uf.ano_censo') .group('adh_idh_uf.estado_id'); + } else { + res.status(400); + next({ + status: 400, + message: 'Wrong/No filter specified' + }); } next(); }, rqf.build(), query, id2str.transform(), response('idhme')); diff --git a/src/test/idhme.js b/src/test/idhme.js index ce3a83bb99ed06d73caf6f02873adcee40afb3be..4962c8a68b3ca9a42d32ecb2554496f4384667f1 100644 --- a/src/test/idhme.js +++ b/src/test/idhme.js @@ -70,19 +70,17 @@ describe('request idhme', () => { chai.request(server) .get('/api/v1/idhme?filter=foo:2010,bar:41') .end((err, res) => { - res.should.have.status(200); + res.should.have.status(400); res.should.be.json; - res.body.result.should.be.a('array'); - res.body.result[0].should.have.property('total'); - res.body.result[0].should.have.property('year'); - res.body.result[0].should.have.property('state_id'); + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); done(); }); }); it('should list idhme with valid dimensions', (done) => { chai.request(server) - .get('/api/v1/idhme?dims=state') + .get('/api/v1/idhme?dims=state&filter=min_year:2010') .end((err, res) => { res.should.have.status(200); res.should.be.json; @@ -112,17 +110,14 @@ describe('request idhme', () => { }); }); - it('should list idhme from all states with all years available with no argument dimensions and filters', (done) => { + it('should return 400 with no filters', (done) => { chai.request(server) .get('/api/v1/idhme') .end((err, res) => { - res.should.have.status(200); + res.should.have.status(400); res.should.be.json; - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - res.body.result[0].should.have.property('total'); - res.body.result[0].should.have.property('year'); - res.body.result[0].should.have.property('state_id'); + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); done(); }); }); diff --git a/src/test/idhml.js b/src/test/idhml.js index b4ece764162c2caf34ff1aaa6ec4f0b9c11fd66f..9ddf8f345f78b8732ef6228659fb22190f9787c2 100644 --- a/src/test/idhml.js +++ b/src/test/idhml.js @@ -70,19 +70,17 @@ describe('request idhml', () => { chai.request(server) .get('/api/v1/idhml?filter=foo:2010,bar:41') .end((err, res) => { - res.should.have.status(200); + res.should.have.status(400); res.should.be.json; - res.body.result.should.be.a('array'); - res.body.result[0].should.have.property('total'); - res.body.result[0].should.have.property('year'); - res.body.result[0].should.have.property('state_id'); + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); done(); }); }); it('should list idhml with valid dimensions', (done) => { chai.request(server) - .get('/api/v1/idhml?dims=state') + .get('/api/v1/idhml?dims=state&filter=min_year:2010') .end((err, res) => { res.should.have.status(200); res.should.be.json; @@ -112,17 +110,14 @@ describe('request idhml', () => { }); }); - it('should list idhml from all states with all years available with no argument dimensions and filters', (done) => { + it('should return 400 with no filters', (done) => { chai.request(server) .get('/api/v1/idhml') .end((err, res) => { - res.should.have.status(200); + res.should.have.status(400); res.should.be.json; - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - res.body.result[0].should.have.property('total'); - res.body.result[0].should.have.property('year'); - res.body.result[0].should.have.property('state_id'); + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); done(); }); });