Skip to content
Snippets Groups Projects
Commit b02ca7e7 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add tests to RQF

parent e946a55c
No related branches found
No related tags found
1 merge request!116Release v1.0.0
Pipeline #
...@@ -9,13 +9,18 @@ function parseWhereValue(type, value) { ...@@ -9,13 +9,18 @@ function parseWhereValue(type, value) {
if(type === 'double') return parseFloat(value); if(type === 'double') return parseFloat(value);
if(type === 'string') return '%'+value+'%'; if(type === 'string') return '%'+value+'%';
if(type === 'boolean') { if(type === 'boolean') {
if (value.toLowerCase() === 'null') { if(value === null || typeof value === 'boolean') {
console.log('Fazendo uma consulta Null'); return value;
return null;
} else {
console.log('Fazendo uma consulta True');
return (value.toLowerCase() === 'true' || parseInt(value, 10) === 1);
} }
if(typeof value === 'string') {
if(value.toLowerCase() === 'true' || value.toLowerCase() === '1') {
return true;
}
if(value.toLowerCase() === 'null') {
return null;
}
}
return false;
} }
} }
...@@ -152,7 +157,15 @@ class ReqQueryFields { ...@@ -152,7 +157,15 @@ class ReqQueryFields {
// Fazemos o split e temos um array `['state', 41]` // Fazemos o split e temos um array `['state', 41]`
const kv = param.split(':'); const kv = param.split(':');
// Checa se há um valor. Se não tem, definimos como true. // Checa se há um valor. Se não tem, definimos como true.
obj[kv[0]] = (typeof kv[1] === 'undefined') ? true : JSON.parse(kv[1]); if ( (typeof kv[1] === 'undefined')) {
obj[kv[0]] = true;
} else {
try {
obj[kv[0]] = JSON.parse(kv[1]);
} catch(err) {
obj[kv[0]] = kv[1];
}
}
// `obj` é agora `{kv[0]: kv[1]}` ou `{kv[0]: true}`. // `obj` é agora `{kv[0]: kv[1]}` ou `{kv[0]: true}`.
// No exemplo `{'state': 41}` // No exemplo `{'state': 41}`
} }
...@@ -243,10 +256,6 @@ class ReqQueryFields { ...@@ -243,10 +256,6 @@ class ReqQueryFields {
log.debug('whereValue'); log.debug('whereValue');
log.debug(whereValue); log.debug(whereValue);
log.debug(`Where value é array? ${Array.isArray(whereValue)}`); log.debug(`Where value é array? ${Array.isArray(whereValue)}`);
// TODO: |
// TODO: |
// TODO: V
//TODO: parse do valor do where onde apropriado!!!!!!!
let tbl = value.where.table || value.table; let tbl = value.where.table || value.table;
// multiple where, only tested for boolean filds // multiple where, only tested for boolean filds
......
...@@ -237,6 +237,20 @@ describe('request enrollments', () => { ...@@ -237,6 +237,20 @@ describe('request enrollments', () => {
}); });
}); });
it('should list enrollments with multivalue filter and single value filter', (done) => {
chai.request(server)
.get('/api/v1/enrollment?filter=region:[1,2],min_year:2015')
.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('name');
res.body.result[0].should.have.property('total');
done();
});
});
it('should list enrollments with valid dimensions and filters', (done) => { it('should list enrollments with valid dimensions and filters', (done) => {
chai.request(server) chai.request(server)
.get('/api/v1/enrollment?dims=region,state,school_year,school,gender,period&filter=min_year:2015,max_year:2015,city:4106902') .get('/api/v1/enrollment?dims=region,state,school_year,school,gender,period&filter=min_year:2015,max_year:2015,city:4106902')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment