From 0407732c0623972d6fe140ad14a975c2540753a7 Mon Sep 17 00:00:00 2001 From: "Henrique V. Ehrenfried" <hvehrenfried@inf.ufpr.br> Date: Tue, 5 Jun 2018 09:12:58 -0300 Subject: [PATCH] Add tests to geolocation and category --- test/category.js | 4 ++-- test/geolocation.js | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/test/category.js b/test/category.js index d8fe806..ac84fac 100644 --- a/test/category.js +++ b/test/category.js @@ -18,7 +18,7 @@ describe('Categories', function() { }); }); }); - it('should try to create a new category', function(){ + it('should try to create a new category', function() { let testObject = { 'category_name': 'Terreiro', 'category_description': 'Lugar que mantém as tradições dos afrodescendentes', @@ -45,7 +45,7 @@ describe('Categories', function() { }); }); }); - it('should create a new category as admin', function(){ + it('should create a new category as admin', function() { let testObject = { 'email': 'abc@admin.com', 'password': 'admin', diff --git a/test/geolocation.js b/test/geolocation.js index 93b70df..3808bac 100644 --- a/test/geolocation.js +++ b/test/geolocation.js @@ -3,16 +3,37 @@ var env = require('../enviroment'); const URL = env.URL; describe('Geolocation', function() { - it('should create a geolocation as an Android user', function() { + it('should create a geolocation as an android user', function() { + let credential = { + 'email': 'user@user.com', + 'password': 'user', + }; + return chakram.post(`${URL}end_users/login`, credential).then(function(loginResponse) { + let testObject = { + 'category_id': 1, + 'geolocation_name': env.randomWord(10), + 'latitude': 10.2123, + 'longitude': 112.2124214, + 'when_sent': new Date(Date.now()), + 'android_id': env.randomId(20), + 'user_id': loginResponse.body.result.userId, + 'description_location': env.randomWord(6, false, true) + ' ' + env.randomWord(6), + }; + return chakram.post(`${URL}geolocations`, testObject).then(function(myResponse) { + expect(myResponse).to.have.status(200); + expect(myResponse.body.result).to.be.a('object'); + }); + }); + }); + it('should create a geolocation as a logged user', function() { let testObject = { 'category_id': 1, 'geolocation_name': env.randomWord(10), - 'latitude': 10.2123, - 'longitude': 112.2124214, + 'latitude': 116.2123, + 'longitude': 50.2124214, 'when_sent': new Date(Date.now()), - 'android_id': env.randomId(20), 'description_location': env.randomWord(6, false, true) + ' ' + env.randomWord(6), - } + }; return chakram.post(`${URL}geolocations`, testObject).then(function(myResponse) { expect(myResponse).to.have.status(200); expect(myResponse.body.result).to.be.a('object'); @@ -33,4 +54,14 @@ describe('Geolocation', function() { }); }); }); + it('should try to remove one geolocation', function() { + return chakram.get(`${URL}geolocations`).then(function(myResponse) { + let id = myResponse.body.result[0].id; + return chakram.delete(`${URL}geolocations/${id}`).then(function(myResponse2) { + expect(myResponse2).to.have.status(401); + expect(myResponse2.body.error.code).to.contain('AUTHORIZATION_REQUIRED'); + }); + }); + }); }); + -- GitLab