From 67a1d4ca2479438356ca1674bf3e3322aa370eec Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Mon, 10 Jul 2017 11:05:25 -0300
Subject: [PATCH] IDHM route test

---
 src/test/idhm.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 src/test/idhm.js

diff --git a/src/test/idhm.js b/src/test/idhm.js
new file mode 100644
index 00000000..210d5818
--- /dev/null
+++ b/src/test/idhm.js
@@ -0,0 +1,80 @@
+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);
+describe('request idhm', () => {
+    it('should list the year range', (done) => {
+        chai.request(server)
+            .get('/api/v1/idhm/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 idhm with valid filters', (done) => {
+        chai.request(server)
+            .get('/api/v1/idhm?filter=min_year:2000,state:41')
+            .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('total');
+                res.body.result[0].should.have.property('year');
+                res.body.result[0].should.have.property('state_id');
+                done();
+            });
+    });
+
+    it('should list idhm with invalid filters', (done) => {
+        chai.request(server)
+            .get('/api/v1/idhm?filter=foo:2010,bar:41')
+            .end((err, res) => {
+                res.should.have.status(400);
+                res.should.be.json;
+                res.body.should.have.property('error');
+                res.body.error.should.be.equal('Wrong/No filter specified');
+                done();
+            });
+    });
+
+    it('should return 400 with no filters', (done) => {
+        chai.request(server)
+            .get('/api/v1/idhm')
+            .end((err, res) => {
+                res.should.have.status(400);
+                res.should.be.json;
+                res.body.should.have.property('error');
+                res.body.error.should.be.equal('Wrong/No filter specified');
+                done();
+            })
+    });
+
+});
-- 
GitLab