From bd02f312dc2a42a27e410378e1d821a8332d0718 Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Wed, 28 Mar 2018 11:15:13 -0300
Subject: [PATCH] Add test to some routes

---
 src/libs/convert/incomeLevel.js |  2 +-
 src/test/class.js               | 14 +++++++
 src/test/id2str.js              | 73 +++++++++++++++++++++++++++++++--
 src/test/infrastructure.js      | 14 +++++++
 src/test/school.js              | 42 +++++++++++++++++++
 5 files changed, 140 insertions(+), 5 deletions(-)

diff --git a/src/libs/convert/incomeLevel.js b/src/libs/convert/incomeLevel.js
index c3910684..f80faf86 100644
--- a/src/libs/convert/incomeLevel.js
+++ b/src/libs/convert/incomeLevel.js
@@ -1,4 +1,4 @@
-module.exports = function citySize(id) {
+module.exports = function incomeLevel(id) {
     switch (id) {
         case 1:
         return '1º quintil – 20% menores';
diff --git a/src/test/class.js b/src/test/class.js
index ef5254f4..3000476c 100644
--- a/src/test/class.js
+++ b/src/test/class.js
@@ -38,6 +38,20 @@ describe('request class', () => {
             });
     });
 
+    it('should list the years', (done) => {
+        chai.request(server)
+            .get('/api/v1/class/year_range')
+            .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('start_year');
+                res.body.result[0].should.have.property('end_year');
+                done();
+            });
+    });
+
     it('should list the source', (done) => {
         chai.request(server)
             .get('/api/v1/class/source')
diff --git a/src/test/id2str.js b/src/test/id2str.js
index 1f4960c3..8d6f5457 100644
--- a/src/test/id2str.js
+++ b/src/test/id2str.js
@@ -44,9 +44,12 @@ describe('id2str middleware', () => {
     });
 
     it('should transform a location id', (done) => {
-        expect(id2str.location(6)).to.deep.equal('Unidade de uso sustentável');
+        expect(id2str.location(1)).to.deep.equal('Urbana');
+        expect(id2str.location(2)).to.deep.equal('Rural');
+        expect(id2str.location(3)).to.deep.equal('Área de assentamento');
         expect(id2str.location(4)).to.deep.equal('Terra indígena');
         expect(id2str.location(5)).to.deep.equal('Área remanescente de quilombos');
+        expect(id2str.location(6)).to.deep.equal('Unidade de uso sustentável');
         done();
     });
 
@@ -58,25 +61,87 @@ describe('id2str middleware', () => {
 
     it('should transform a income level id', (done) => {
         expect(id2str.incomeLevel(1)).to.deep.equal('1º quintil – 20% menores');
+        expect(id2str.incomeLevel(12)).to.deep.equal('Não classificada');
         done();
     });
 
-    it('should transform a income level id', (done) => {
+    it('should transform a education level basic id', (done) => {
         expect(id2str.educationLevelBasic(7)).to.deep.equal('Não classificada');
         done();
     });
 
-    it('should transform a class adm dependency id', (done) => {
+    it('should transform a age range id', (done) => {
+        expect(id2str.ageRange(12)).to.deep.equal('Não declarada');
+        done();
+    });
+
+    it('should transform a booleans variables', (done) => {
+        expect(id2str.booleanVariable(1)).to.deep.equal('Sim');
+        expect(id2str.booleanVariable(0)).to.deep.equal('Não');
+        expect(id2str.booleanVariable(null)).to.deep.equal('Não Declarado');
+        done();
+    });
+
+    it('should transform a city size id', (done) => {
+        expect(id2str.citySize(10)).to.deep.equal('Não classificada');
+        done();
+    });
+
+    it('should transform a educatoin type id', (done) => {
+        expect(id2str.educationType(10)).to.deep.equal('Não definido');
+        done();
+    });
+
+
+    it('should transform a gender Pnad id', (done) => {
+        expect(id2str.genderPnad(2)).to.deep.equal('Masculino');
+        expect(id2str.genderPnad(4)).to.deep.equal('Feminino');
+        done();
+    });
+
+    it('should transform a adm dependency id', (done) => {
         expect(id2str.admDependency(6)).to.deep.equal('Não classificada');
         done();
     });
 
-    it('should transform a class adm dependency priv id', (done) => {
+    it('should transform a adm dependency priv id', (done) => {
         expect(id2str.admDependencyPriv(7)).to.deep.equal('Não classificada');
+        done();
+    });
+
+    it('should transform a ethnic group id', (done) => {
+        expect(id2str.ethnicGroup(7)).to.deep.equal('Não declarada');
+        done();
+    });
 
+    it('should transform a ethnic group Pnad id', (done) => {
+        expect(id2str.ethnicGroupPnad(7)).to.deep.equal('Sem declaração');
         done();
     });
 
+    it('should transform a full age range id', (done) => {
+        expect(id2str.fullAgeRange(1)).to.deep.equal('0-3');
+        expect(id2str.fullAgeRange(2)).to.deep.equal('4-5');
+        expect(id2str.fullAgeRange(3)).to.deep.equal('6-10');
+        expect(id2str.fullAgeRange(4)).to.deep.equal('11-14');
+        expect(id2str.fullAgeRange(5)).to.deep.equal('15-17');
+        expect(id2str.fullAgeRange(6)).to.deep.equal('18-24');
+        expect(id2str.fullAgeRange(7)).to.deep.equal('25-29');
+        expect(id2str.fullAgeRange(8)).to.deep.equal('30-40');
+        expect(id2str.fullAgeRange(9)).to.deep.equal('41-50');
+        expect(id2str.fullAgeRange(10)).to.deep.equal('51-64');
+        expect(id2str.fullAgeRange(11)).to.deep.equal('64+');
+        expect(id2str.fullAgeRange(12)).to.deep.equal('Não declarada');
+
+        done();
+    });
+
+    it('should transform a idhm level id', (done) => {
+        expect(id2str.idhmLevel(12)).to.deep.equal('Não classificada');
+        done();
+    });
+
+
     it('should transform a result', (done) => {
         let req = {
             result: [{gender_id: 2, period_id: 3, school_year_id: 11}]
diff --git a/src/test/infrastructure.js b/src/test/infrastructure.js
index c92fda1e..8714a73c 100644
--- a/src/test/infrastructure.js
+++ b/src/test/infrastructure.js
@@ -50,6 +50,20 @@ describe('request infrastructure', () => {
             });
     });
 
+    it('should list the years', (done) => {
+        chai.request(server)
+            .get('/api/v1/infrastructure/year_range')
+            .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('start_year');
+                res.body.result[0].should.have.property('end_year');
+                done();
+            });
+    });
+
     it('should list the source', (done) => {
         chai.request(server)
             .get('/api/v1/infrastructure/source')
diff --git a/src/test/school.js b/src/test/school.js
index 266c5428..0ca4c78b 100644
--- a/src/test/school.js
+++ b/src/test/school.js
@@ -54,6 +54,21 @@ describe('request schools', () => {
             });
     });
 
+    it('should list a school by id', (done) => {
+        chai.request(server)
+            .get('/api/v1/school/education_end_elementary_school')
+            .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('id');
+                res.body.result[0].should.have.property('name');
+                //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?filter=state:41')
@@ -84,6 +99,33 @@ describe('request schools', () => {
             })
     });
 
+    it('should list the year range', (done) => {
+        chai.request(server)
+            .get('/api/v1/school/year_range')
+            .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('start_year');
+                res.body.result[0].should.have.property('end_year');
+                done();
+            });
+    });
+
+    it('should list the year range', (done) => {
+        chai.request(server)
+            .get('/api/v1/school/years')
+            .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('year');
+                done();
+            });
+    });
+
     it('should return 400 with no filters', (done) => {
         chai.request(server)
             .get('/api/v1/school')
-- 
GitLab