From d5e05b00782a09cbc1e6387374230a7bae411868 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Tozatti=20Risso?= <jvtr12@inf.ufpr.br>
Date: Tue, 1 Nov 2016 10:45:33 -0200
Subject: [PATCH] Add test cases for location routes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: João Victor Tozatti Risso <jvtr12@inf.ufpr.br>
---
 src/test/location.js | 385 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 385 insertions(+)
 create mode 100644 src/test/location.js

diff --git a/src/test/location.js b/src/test/location.js
new file mode 100644
index 00000000..334e3faf
--- /dev/null
+++ b/src/test/location.js
@@ -0,0 +1,385 @@
+process.env.NODE_ENV = 'test';
+
+const chai = require('chai');
+
+const dirtyChai = require('dirty-chai');
+
+chai.use(dirtyChai);
+
+const chaiXml = require('chai-xml');
+
+chai.use(chaiXml);
+
+const chaiHttp = require('chai-http');
+
+const assert = chai.assert;
+
+const expect = chai.expect;
+
+const should = chai.should(); // actually call the function
+
+const libs = `${process.cwd()}/libs`;
+
+const server = require(`${libs}/app`);
+
+chai.use(chaiHttp);
+
+const testTimeout = 5000;
+
+describe('test location', () => {
+    it('should return the expected response format for sociodemographic data for the whole country', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/sociodemographic')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('population');
+                res.body.result.should.have.property('gdp');
+                res.body.result.should.have.property('idh');
+                res.body.result.should.have.property('analfab');
+                res.body.result.should.have.property('gini');
+                // test response attributes for population
+                res.body.result.population.should.have.property('name');
+                res.body.result.population.should.have.property('population');
+                res.body.result.population.should.have.property('census_year');
+                // test response attributes for gdp
+                res.body.result.gdp.should.have.property('name');
+                res.body.result.gdp.should.have.property('gdp_per_capita');
+                res.body.result.gdp.should.have.property('census_year');
+                // test response attributes for idh
+                res.body.result.idh.should.have.property('name');
+                res.body.result.idh.should.have.property('idhm');
+                res.body.result.idh.should.have.property('census_year');
+                // test response attributes for analfab
+                res.body.result.analfab.should.have.property('name');
+                res.body.result.analfab.should.have.property('analfabetism');
+                res.body.result.analfab.should.have.property('census_year');
+                // test response attributes for gini
+                res.body.result.gini.should.have.property('name');
+                res.body.result.gini.should.have.property('gini');
+                res.body.result.gini.should.have.property('census_year');
+                done();
+            });
+    }).timeout(testTimeout);
+
+    it('should return the expected response format for sociodemographic data for a country region', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/sociodemographic/region/1')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('population');
+                res.body.result.should.have.property('gdp');
+                res.body.result.should.have.property('idh');
+                res.body.result.should.have.property('analfab');
+                res.body.result.should.have.property('gini');
+                // test response attributes for population
+                res.body.result.population.should.have.property('name');
+                res.body.result.population.should.have.property('population');
+                res.body.result.population.should.have.property('census_year');
+                // test response attributes for gdp
+                res.body.result.gdp.should.have.property('name');
+                res.body.result.gdp.should.have.property('gdp_per_capita');
+                res.body.result.gdp.should.have.property('census_year');
+                // test response attributes for idh
+                res.body.result.idh.should.have.property('name');
+                res.body.result.idh.should.have.property('idhm');
+                res.body.result.idh.should.have.property('census_year');
+                // test response attributes for analfab
+                res.body.result.analfab.should.have.property('name');
+                res.body.result.analfab.should.have.property('analfabetism');
+                res.body.result.analfab.should.have.property('census_year');
+                // test response attributes for gini
+                res.body.result.gini.should.have.property('name');
+                res.body.result.gini.should.have.property('gini');
+                res.body.result.gini.should.have.property('census_year');
+                done();
+            });
+    }).timeout(testTimeout);
+
+    it('should return the expected response format for sociodemographic data for a country state', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/sociodemographic/state/42')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('population');
+                res.body.result.should.have.property('gdp');
+                res.body.result.should.have.property('idh');
+                res.body.result.should.have.property('analfab');
+                res.body.result.should.have.property('gini');
+                // test response attributes for population
+                res.body.result.population.should.have.property('name');
+                res.body.result.population.should.have.property('population');
+                res.body.result.population.should.have.property('census_year');
+                // test response attributes for gdp
+                res.body.result.gdp.should.have.property('name');
+                res.body.result.gdp.should.have.property('gdp_per_capita');
+                res.body.result.gdp.should.have.property('census_year');
+                // test response attributes for idh
+                res.body.result.idh.should.have.property('name');
+                res.body.result.idh.should.have.property('idhm');
+                res.body.result.idh.should.have.property('census_year');
+                // test response attributes for analfab
+                res.body.result.analfab.should.have.property('name');
+                res.body.result.analfab.should.have.property('analfabetism');
+                res.body.result.analfab.should.have.property('census_year');
+                // test response attributes for gini
+                res.body.result.gini.should.have.property('name');
+                res.body.result.gini.should.have.property('gini');
+                res.body.result.gini.should.have.property('census_year');
+                done();
+            });
+    }).timeout(testTimeout);
+
+    it('should return the expected response format for sociodemographic data for a country city', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/sociodemographic/city/4106902')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('population');
+                res.body.result.should.have.property('gdp');
+                res.body.result.should.have.property('idh');
+                res.body.result.should.have.property('analfab');
+                res.body.result.should.have.property('gini');
+                // test response attributes for population
+                res.body.result.population.should.have.property('name');
+                res.body.result.population.should.have.property('population');
+                res.body.result.population.should.have.property('census_year');
+                // test response attributes for gdp
+                res.body.result.gdp.should.have.property('name');
+                res.body.result.gdp.should.have.property('gdp_per_capita');
+                res.body.result.gdp.should.have.property('census_year');
+                // test response attributes for idh
+                res.body.result.idh.should.have.property('name');
+                res.body.result.idh.should.have.property('idhm');
+                res.body.result.idh.should.have.property('census_year');
+                // test response attributes for analfab
+                res.body.result.analfab.should.have.property('name');
+                res.body.result.analfab.should.have.property('analfabetism');
+                res.body.result.analfab.should.have.property('census_year');
+                // test response attributes for gini
+                res.body.result.gini.should.have.property('name');
+                res.body.result.gini.should.have.property('gini');
+                res.body.result.gini.should.have.property('census_year');
+                done();
+            });
+    }).timeout(testTimeout);
+
+    it('should return the expected response format for educational data for the whole country', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/educational')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('school');
+                res.body.result.should.have.property('school_per_location');
+                res.body.result.should.have.property('enrollment');
+                res.body.result.should.have.property('enrollment_per_adm_dep');
+                res.body.result.should.have.property('enrollment_per_school_level');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                done();
+            });
+    }).timeout(testTimeout);
+
+    it('should return the expected response format for educational data for a country region', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/educational/region/1')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('school');
+                res.body.result.should.have.property('school_per_location');
+                res.body.result.should.have.property('enrollment');
+                res.body.result.should.have.property('enrollment_per_adm_dep');
+                res.body.result.should.have.property('enrollment_per_school_level');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                done();
+            });
+    }).timeout(testTimeout);
+
+    it('should return the expected response format for educational data for a country state', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/educational/state/42')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('school');
+                res.body.result.should.have.property('school_per_location');
+                res.body.result.should.have.property('enrollment');
+                res.body.result.should.have.property('enrollment_per_adm_dep');
+                res.body.result.should.have.property('enrollment_per_school_level');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                done();
+            });
+    }).timeout(testTimeout);
+
+    it('should return the expected response format for educational data for a country city', (done) => {
+        chai.request(server)
+            .get('/api/v1/location/educational/city/4106902')
+            .end((err, res) => {
+                res.should.have.status(200);
+                // test response format
+                res.should.be.json;
+                // test for result attribute in the response
+                res.body.should.have.property('result');
+                // test result type
+                res.body.result.should.be.a('object');
+                res.body.result.should.have.property('school');
+                res.body.result.should.have.property('school_per_location');
+                res.body.result.should.have.property('enrollment');
+                res.body.result.should.have.property('enrollment_per_adm_dep');
+                res.body.result.should.have.property('enrollment_per_school_level');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                // 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');
+                done();
+            });
+    }).timeout(testTimeout);
+});
-- 
GitLab