diff --git a/src/libs/routes/location.js b/src/libs/routes/location.js index 0a1245741d914ec48b522f6dc785c35d1e81d146..3db23d544b11176ea2d45369563f7ab24c152173 100644 --- a/src/libs/routes/location.js +++ b/src/libs/routes/location.js @@ -34,15 +34,21 @@ function locationIdToStr(locationId) { return locationStr; } -function processResultSet(querySet, querySetLabels = ["result"]) { +function processResultSet(querySet, querySetLabels = ["result"], singleResult = false) { const resultMap = new Map(); let resultIdx = 0; // loop relies on the fact that Promise.all maintains the order of the original iterable for(let result of querySet) { const resultLbl = querySetLabels[resultIdx]; - // each query only returns one object in an array, so we get rid of the array - const resultObj = result[0]; - resultMap[resultLbl] = resultObj; + resultMap[resultLbl] = []; + if (singleResult) { + resultMap[resultLbl] = result[0]; + } else { + for(let row of result) { + log.debug(row); + resultMap[resultLbl].push(row); + } + } resultIdx++; } log.debug(resultMap); @@ -121,7 +127,7 @@ locationApp.get('/sociodemographic', (req, res, next) => { const querySet = [ populationQry, pibQry, idhQry, analfabQry, giniQry ]; // wait until all queries finish or one of them fail Promise.all(dbExecAll(querySet)).then((queryResults) => { - req.result = processResultSet(queryResults, queryLabels); + req.result = processResultSet(queryResults, queryLabels, true); next(); }).catch((error) => { log.error(`[SQL query error] ${error}`); @@ -241,7 +247,7 @@ locationApp.get('/sociodemographic/region/:id', (req, res, next) => { const querySet = [ populationQry, pibQry, idhQry, analfabQry, giniQry ]; // wait until all queries finish or one of them fail Promise.all(dbExecAll(querySet)).then((queryResults) => { - req.result = processResultSet(queryResults, queryLabels); + req.result = processResultSet(queryResults, queryLabels, true); next(); }).catch((error) => { log.error(`[SQL query error] ${error}`); @@ -351,7 +357,7 @@ locationApp.get('/sociodemographic/state/:id', (req, res, next) => { const querySet = [ populationQry, pibQry, idhQry, analfabQry, giniQry ]; // wait until all queries finish or one of them fail Promise.all(dbExecAll(querySet)).then((queryResults) => { - req.result = processResultSet(queryResults, queryLabels); + req.result = processResultSet(queryResults, queryLabels, true); next(); }).catch((error) => { log.error(`[SQL query error] ${error}`); @@ -451,7 +457,7 @@ locationApp.get('/sociodemographic/city/:id', (req, res, next) => { const querySet = [ populationQry, pibQry, idhQry, analfabQry, giniQry ]; // wait until all queries finish or one of them fail Promise.all(dbExecAll(querySet)).then((queryResults) => { - req.result = processResultSet(queryResults, queryLabels); + req.result = processResultSet(queryResults, queryLabels, true); next(); }).catch((error) => { log.error(`[SQL query error] ${error}`); @@ -495,7 +501,6 @@ locationApp.get('/educational', (req, res, next) => { .field('\'Brasil\'', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('\'Total\'', 'adm_dependency') .from('turma') .where(`turma.ano_censo IN (${schoolClassYearQry})`) .where('turma.fk_tipo_turma_id <= 3') @@ -518,19 +523,14 @@ locationApp.get('/educational', (req, res, next) => { .field('\'Brasil\'', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('dependencia_adm.nome', 'adm_dependency') .field('etapa_ensino.desc_etapa', 'school_level') .from('turma') - .from('dependencia_adm') .from('etapa_ensino') - .where('turma.fk_dependencia_adm_id = dependencia_adm.pk_dependencia_adm_id') .where('turma.fk_etapa_ensino_id = etapa_ensino.pk_etapa_ensino_id') .where('turma.fk_tipo_turma_id <= 3') .where(`turma.ano_censo IN (${schoolClassYearQry})`) .group('turma.ano_censo') - .group('dependencia_adm.nome') .group('etapa_ensino.desc_etapa') - .order('dependencia_adm.nome') .order('etapa_ensino.desc_etapa'); const queryLabels = [ "school", "school_per_location", "enrollment", "enrollment_per_adm_dep", @@ -541,7 +541,11 @@ locationApp.get('/educational', (req, res, next) => { Promise.all(dbExecAll(querySet)).then((queryResults) => { req.result = processResultSet(queryResults, queryLabels); for(let label in req.result) { - req.result[label].location = locationIdToStr(req.result[label].location); + for(let row of req.result[label]) { + if (row.hasOwnProperty('location')) { + row.location = locationIdToStr(row.location); + } + } } next(); }).catch((error) => { @@ -600,7 +604,6 @@ locationApp.get('/educational/region/:id', (req, res, next) => { .field('regiao.nome', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('\'Total\'', 'adm_dependency') .from('turma') .from('regiao') .where('turma.fk_regiao_id = regiao.pk_regiao_id') @@ -631,24 +634,19 @@ locationApp.get('/educational/region/:id', (req, res, next) => { .field('regiao.nome', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('dependencia_adm.nome', 'adm_dependency') .field('etapa_ensino.desc_etapa', 'school_level') .from('turma') - .from('dependencia_adm') .from('etapa_ensino') .from('regiao') .where('turma.fk_regiao_id = regiao.pk_regiao_id') .where(`turma.fk_regiao_id = ${regionId}`) - .where('turma.fk_dependencia_adm_id = dependencia_adm.pk_dependencia_adm_id') .where('turma.fk_etapa_ensino_id = etapa_ensino.pk_etapa_ensino_id') .where('turma.fk_tipo_turma_id <= 3') .where(`turma.ano_censo IN (${schoolClassYearQry})`) .group('turma.ano_censo') - .group('dependencia_adm.nome') .group('etapa_ensino.desc_etapa') .group('regiao.nome') .order('regiao.nome') - .order('dependencia_adm.nome') .order('etapa_ensino.desc_etapa'); const queryLabels = [ "school", "school_per_location", "enrollment", "enrollment_per_adm_dep", @@ -659,7 +657,11 @@ locationApp.get('/educational/region/:id', (req, res, next) => { Promise.all(dbExecAll(querySet)).then((queryResults) => { req.result = processResultSet(queryResults, queryLabels); for(let label in req.result) { - req.result[label].location = locationIdToStr(req.result[label].location); + for(let row of req.result[label]) { + if (row.hasOwnProperty('location')) { + row.location = locationIdToStr(row.location); + } + } } next(); }).catch((error) => { @@ -714,7 +716,6 @@ locationApp.get('/educational/state/:id', (req, res, next) => { .field('estado.nome', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('\'Total\'', 'adm_dependency') .from('turma') .from('estado') .where('turma.fk_estado_id = estado.pk_estado_id') @@ -745,24 +746,19 @@ locationApp.get('/educational/state/:id', (req, res, next) => { .field('estado.nome', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('dependencia_adm.nome', 'adm_dependency') .field('etapa_ensino.desc_etapa', 'school_level') .from('turma') - .from('dependencia_adm') .from('etapa_ensino') .from('estado') .where('turma.fk_estado_id = estado.pk_estado_id') .where(`turma.fk_estado_id = ${stateId}`) - .where('turma.fk_dependencia_adm_id = dependencia_adm.pk_dependencia_adm_id') .where('turma.fk_etapa_ensino_id = etapa_ensino.pk_etapa_ensino_id') .where('turma.fk_tipo_turma_id <= 3') .where(`turma.ano_censo IN (${schoolClassYearQry})`) .group('turma.ano_censo') - .group('dependencia_adm.nome') .group('etapa_ensino.desc_etapa') .group('estado.nome') .order('estado.nome') - .order('dependencia_adm.nome') .order('etapa_ensino.desc_etapa'); const queryLabels = [ "school", "school_per_location", "enrollment", "enrollment_per_adm_dep", @@ -773,7 +769,11 @@ locationApp.get('/educational/state/:id', (req, res, next) => { Promise.all(dbExecAll(querySet)).then((queryResults) => { req.result = processResultSet(queryResults, queryLabels); for(let label in req.result) { - req.result[label].location = locationIdToStr(req.result[label].location); + for(let row of req.result[label]) { + if (row.hasOwnProperty('location')) { + row.location = locationIdToStr(row.location); + } + } } next(); }).catch((error) => { @@ -828,7 +828,6 @@ locationApp.get('/educational/city/:id', (req, res, next) => { .field('municipio.nome', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('\'Total\'', 'adm_dependency') .from('turma') .from('municipio') .where('turma.fk_municipio_id = municipio.pk_cod_ibge') @@ -859,24 +858,19 @@ locationApp.get('/educational/city/:id', (req, res, next) => { .field('municipio.nome', 'name') .field('COALESCE(SUM(turma.num_matriculas), 0)', 'total') .field('turma.ano_censo', 'census_year') - .field('dependencia_adm.nome', 'adm_dependency') .field('etapa_ensino.desc_etapa', 'school_level') .from('turma') - .from('dependencia_adm') .from('etapa_ensino') .from('municipio') .where('turma.fk_municipio_id = municipio.pk_cod_ibge') .where(`turma.fk_municipio_id = ${cityId}`) - .where('turma.fk_dependencia_adm_id = dependencia_adm.pk_dependencia_adm_id') .where('turma.fk_etapa_ensino_id = etapa_ensino.pk_etapa_ensino_id') .where('turma.fk_tipo_turma_id <= 3') .where(`turma.ano_censo IN (${schoolClassYearQry})`) .group('turma.ano_censo') - .group('dependencia_adm.nome') .group('etapa_ensino.desc_etapa') .group('municipio.nome') .order('municipio.nome') - .order('dependencia_adm.nome') .order('etapa_ensino.desc_etapa'); const queryLabels = [ "school", "school_per_location", "enrollment", "enrollment_per_adm_dep", @@ -887,7 +881,11 @@ locationApp.get('/educational/city/:id', (req, res, next) => { Promise.all(dbExecAll(querySet)).then((queryResults) => { req.result = processResultSet(queryResults, queryLabels); for(let label in req.result) { - req.result[label].location = locationIdToStr(req.result[label].location); + for(let row of req.result[label]) { + if (row.hasOwnProperty('location')) { + row.location = locationIdToStr(row.location); + } + } } next(); }).catch((error) => { diff --git a/src/test/location.js b/src/test/location.js index 334e3faf364f71a0fdcfb9fab87393ae6464dd5a..7d8f202e7efff24c8474fed39f6de94725c6b53c 100644 --- a/src/test/location.js +++ b/src/test/location.js @@ -67,7 +67,7 @@ describe('test location', () => { }); }).timeout(testTimeout); - it('should return the expected response format for sociodemographic data for a country region', (done) => { + it('should return the expected response format for sociodemographic data for a region', (done) => { chai.request(server) .get('/api/v1/location/sociodemographic/region/1') .end((err, res) => { @@ -107,7 +107,7 @@ describe('test location', () => { }); }).timeout(testTimeout); - it('should return the expected response format for sociodemographic data for a country state', (done) => { + it('should return the expected response format for sociodemographic data for a state', (done) => { chai.request(server) .get('/api/v1/location/sociodemographic/state/42') .end((err, res) => { @@ -147,7 +147,7 @@ describe('test location', () => { }); }).timeout(testTimeout); - it('should return the expected response format for sociodemographic data for a country city', (done) => { + it('should return the expected response format for sociodemographic data for a city', (done) => { chai.request(server) .get('/api/v1/location/sociodemographic/city/4106902') .end((err, res) => { @@ -199,39 +199,55 @@ describe('test location', () => { // test result type res.body.result.should.be.a('object'); res.body.result.should.have.property('school'); + res.body.result.school.should.be.a('array'); res.body.result.should.have.property('school_per_location'); + res.body.result.school_per_location.should.be.a('array'); res.body.result.should.have.property('enrollment'); + res.body.result.enrollment.should.be.a('array'); res.body.result.should.have.property('enrollment_per_adm_dep'); + res.body.result.enrollment_per_adm_dep.should.be.a('array'); res.body.result.should.have.property('enrollment_per_school_level'); + res.body.result.enrollment_per_school_level.should.be.a('array'); // test response attributes for school - res.body.result.school.should.have.property('name'); - res.body.result.school.should.have.property('location'); - res.body.result.school.should.have.property('total'); - res.body.result.school.should.have.property('census_year'); + res.body.result.school.should.a('array'); + res.body.result.school.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for school_per_location - res.body.result.school_per_location.should.have.property('name'); - res.body.result.school_per_location.should.have.property('location'); - res.body.result.school_per_location.should.have.property('total'); - res.body.result.school_per_location.should.have.property('census_year'); + res.body.result.school_per_location.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment - res.body.result.enrollment.should.have.property('name'); - res.body.result.enrollment.should.have.property('total'); - res.body.result.enrollment.should.have.property('census_year'); - res.body.result.enrollment.should.have.property('adm_dependency'); - res.body.result.enrollment.should.have.property('location'); + res.body.result.enrollment.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.should.have.property('name'); - res.body.result.enrollment_per_adm_dep.should.have.property('total'); - res.body.result.enrollment_per_adm_dep.should.have.property('census_year'); - res.body.result.enrollment_per_adm_dep.should.have.property('adm_dependency'); - res.body.result.enrollment_per_adm_dep.should.have.property('location'); + res.body.result.enrollment_per_adm_dep.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('adm_dependency'); + }); // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.should.have.property('name'); - res.body.result.enrollment_per_school_level.should.have.property('total'); - res.body.result.enrollment_per_school_level.should.have.property('census_year'); - res.body.result.enrollment_per_school_level.should.have.property('adm_dependency'); - res.body.result.enrollment_per_school_level.should.have.property('school_level'); - res.body.result.enrollment_per_school_level.should.have.property('location'); + res.body.result.enrollment_per_school_level.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('school_level'); + }); done(); }); }).timeout(testTimeout); @@ -248,39 +264,55 @@ describe('test location', () => { // test result type res.body.result.should.be.a('object'); res.body.result.should.have.property('school'); + res.body.result.school.should.be.a('array'); res.body.result.should.have.property('school_per_location'); + res.body.result.school_per_location.should.be.a('array'); res.body.result.should.have.property('enrollment'); + res.body.result.enrollment.should.be.a('array'); res.body.result.should.have.property('enrollment_per_adm_dep'); + res.body.result.enrollment_per_adm_dep.should.be.a('array'); res.body.result.should.have.property('enrollment_per_school_level'); + res.body.result.enrollment_per_school_level.should.be.a('array'); // test response attributes for school - res.body.result.school.should.have.property('name'); - res.body.result.school.should.have.property('location'); - res.body.result.school.should.have.property('total'); - res.body.result.school.should.have.property('census_year'); + res.body.result.school.should.a('array'); + res.body.result.school.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for school_per_location - res.body.result.school_per_location.should.have.property('name'); - res.body.result.school_per_location.should.have.property('location'); - res.body.result.school_per_location.should.have.property('total'); - res.body.result.school_per_location.should.have.property('census_year'); + res.body.result.school_per_location.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment - res.body.result.enrollment.should.have.property('name'); - res.body.result.enrollment.should.have.property('total'); - res.body.result.enrollment.should.have.property('census_year'); - res.body.result.enrollment.should.have.property('adm_dependency'); - res.body.result.enrollment.should.have.property('location'); + res.body.result.enrollment.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.should.have.property('name'); - res.body.result.enrollment_per_adm_dep.should.have.property('total'); - res.body.result.enrollment_per_adm_dep.should.have.property('census_year'); - res.body.result.enrollment_per_adm_dep.should.have.property('adm_dependency'); - res.body.result.enrollment_per_adm_dep.should.have.property('location'); + res.body.result.enrollment_per_adm_dep.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('adm_dependency'); + }); // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.should.have.property('name'); - res.body.result.enrollment_per_school_level.should.have.property('total'); - res.body.result.enrollment_per_school_level.should.have.property('census_year'); - res.body.result.enrollment_per_school_level.should.have.property('adm_dependency'); - res.body.result.enrollment_per_school_level.should.have.property('school_level'); - res.body.result.enrollment_per_school_level.should.have.property('location'); + res.body.result.enrollment_per_school_level.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('school_level'); + }); done(); }); }).timeout(testTimeout); @@ -297,39 +329,55 @@ describe('test location', () => { // test result type res.body.result.should.be.a('object'); res.body.result.should.have.property('school'); + res.body.result.school.should.be.a('array'); res.body.result.should.have.property('school_per_location'); + res.body.result.school_per_location.should.be.a('array'); res.body.result.should.have.property('enrollment'); + res.body.result.enrollment.should.be.a('array'); res.body.result.should.have.property('enrollment_per_adm_dep'); + res.body.result.enrollment_per_adm_dep.should.be.a('array'); res.body.result.should.have.property('enrollment_per_school_level'); + res.body.result.enrollment_per_school_level.should.be.a('array'); // test response attributes for school - res.body.result.school.should.have.property('name'); - res.body.result.school.should.have.property('location'); - res.body.result.school.should.have.property('total'); - res.body.result.school.should.have.property('census_year'); + res.body.result.school.should.a('array'); + res.body.result.school.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for school_per_location - res.body.result.school_per_location.should.have.property('name'); - res.body.result.school_per_location.should.have.property('location'); - res.body.result.school_per_location.should.have.property('total'); - res.body.result.school_per_location.should.have.property('census_year'); + res.body.result.school_per_location.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment - res.body.result.enrollment.should.have.property('name'); - res.body.result.enrollment.should.have.property('total'); - res.body.result.enrollment.should.have.property('census_year'); - res.body.result.enrollment.should.have.property('adm_dependency'); - res.body.result.enrollment.should.have.property('location'); + res.body.result.enrollment.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.should.have.property('name'); - res.body.result.enrollment_per_adm_dep.should.have.property('total'); - res.body.result.enrollment_per_adm_dep.should.have.property('census_year'); - res.body.result.enrollment_per_adm_dep.should.have.property('adm_dependency'); - res.body.result.enrollment_per_adm_dep.should.have.property('location'); + res.body.result.enrollment_per_adm_dep.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('adm_dependency'); + }); // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.should.have.property('name'); - res.body.result.enrollment_per_school_level.should.have.property('total'); - res.body.result.enrollment_per_school_level.should.have.property('census_year'); - res.body.result.enrollment_per_school_level.should.have.property('adm_dependency'); - res.body.result.enrollment_per_school_level.should.have.property('school_level'); - res.body.result.enrollment_per_school_level.should.have.property('location'); + res.body.result.enrollment_per_school_level.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('school_level'); + }); done(); }); }).timeout(testTimeout); @@ -346,39 +394,55 @@ describe('test location', () => { // test result type res.body.result.should.be.a('object'); res.body.result.should.have.property('school'); + res.body.result.school.should.be.a('array'); res.body.result.should.have.property('school_per_location'); + res.body.result.school_per_location.should.be.a('array'); res.body.result.should.have.property('enrollment'); + res.body.result.enrollment.should.be.a('array'); res.body.result.should.have.property('enrollment_per_adm_dep'); + res.body.result.enrollment_per_adm_dep.should.be.a('array'); res.body.result.should.have.property('enrollment_per_school_level'); + res.body.result.enrollment_per_school_level.should.be.a('array'); // test response attributes for school - res.body.result.school.should.have.property('name'); - res.body.result.school.should.have.property('location'); - res.body.result.school.should.have.property('total'); - res.body.result.school.should.have.property('census_year'); + res.body.result.school.should.a('array'); + res.body.result.school.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for school_per_location - res.body.result.school_per_location.should.have.property('name'); - res.body.result.school_per_location.should.have.property('location'); - res.body.result.school_per_location.should.have.property('total'); - res.body.result.school_per_location.should.have.property('census_year'); + res.body.result.school_per_location.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('location'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment - res.body.result.enrollment.should.have.property('name'); - res.body.result.enrollment.should.have.property('total'); - res.body.result.enrollment.should.have.property('census_year'); - res.body.result.enrollment.should.have.property('adm_dependency'); - res.body.result.enrollment.should.have.property('location'); + res.body.result.enrollment.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + }); // test response attributes for enrollment_per_adm_dep - res.body.result.enrollment_per_adm_dep.should.have.property('name'); - res.body.result.enrollment_per_adm_dep.should.have.property('total'); - res.body.result.enrollment_per_adm_dep.should.have.property('census_year'); - res.body.result.enrollment_per_adm_dep.should.have.property('adm_dependency'); - res.body.result.enrollment_per_adm_dep.should.have.property('location'); + res.body.result.enrollment_per_adm_dep.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('adm_dependency'); + }); // test response attributes for enrollment_per_school_level - res.body.result.enrollment_per_school_level.should.have.property('name'); - res.body.result.enrollment_per_school_level.should.have.property('total'); - res.body.result.enrollment_per_school_level.should.have.property('census_year'); - res.body.result.enrollment_per_school_level.should.have.property('adm_dependency'); - res.body.result.enrollment_per_school_level.should.have.property('school_level'); - res.body.result.enrollment_per_school_level.should.have.property('location'); + res.body.result.enrollment_per_school_level.forEach((row) => { + row.should.be.a('object'); + row.should.have.property('name'); + row.should.have.property('total'); + row.should.have.property('census_year'); + row.should.have.property('school_level'); + }); done(); }); }).timeout(testTimeout);